fork of go-git with some jj specific features
at main 1.1 kB view raw
1package main 2 3import ( 4 "log" 5 "os" 6 7 "github.com/go-git/go-git/v5" 8 "github.com/go-git/go-git/v5/config" 9 "github.com/go-git/go-git/v5/storage/memory" 10 11 . "github.com/go-git/go-git/v5/_examples" 12) 13 14// Retrieve remote tags without cloning repository 15func main() { 16 CheckArgs("<url>") 17 url := os.Args[1] 18 19 Info("git ls-remote --tags %s", url) 20 21 // Create the remote with repository URL 22 rem := git.NewRemote(memory.NewStorage(), &config.RemoteConfig{ 23 Name: "origin", 24 URLs: []string{url}, 25 }) 26 27 log.Print("Fetching tags...") 28 29 // We can then use every Remote functions to retrieve wanted information 30 refs, err := rem.List(&git.ListOptions{ 31 // Returns all references, including peeled references. 32 PeelingOption: git.AppendPeeled, 33 }) 34 if err != nil { 35 log.Fatal(err) 36 } 37 38 // Filters the references list and only keeps tags 39 var tags []string 40 for _, ref := range refs { 41 if ref.Name().IsTag() { 42 tags = append(tags, ref.Name().Short()) 43 } 44 } 45 46 if len(tags) == 0 { 47 log.Println("No tags!") 48 return 49 } 50 51 log.Printf("Tags found: %v", tags) 52}