This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree 3 files changed +46
-1
lines changed
3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ Here you can find a list of annotated _go-git_ examples:
10
10
- [ remotes] ( remotes/main.go ) - Working with remotes: adding, removing, etc
11
11
- [ progress] ( progress/main.go ) - Printing the progress information from the sideband
12
12
- [ push] ( push/main.go ) - Push repository to default remote (origin)
13
- - [ checkout] ( checkout/main.go ) - check out a specific commit from a repository.
13
+ - [ checkout] ( checkout/main.go ) - check out a specific commit from a repository
14
+ - [ tag] ( tag/main.go ) - list/print repository tags
14
15
### Advanced
15
16
- [ custom_http] ( custom_http/main.go ) - Replacing the HTTP client using a custom one
16
17
- [ storage] ( storage/README.md ) - Implementing a custom storage system
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ var args = map[string][]string{
23
23
"progress" : []string {defaultURL , tempFolder ()},
24
24
"push" : []string {setEmptyRemote (cloneRepository (defaultURL , tempFolder ()))},
25
25
"showcase" : []string {defaultURL , tempFolder ()},
26
+ "tag" : []string {cloneRepository (defaultURL , tempFolder ())},
26
27
}
27
28
28
29
var ignored = map [string ]bool {}
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+
7
+ "gopkg.in/src-d/go-git.v4"
8
+ . "gopkg.in/src-d/go-git.v4/_examples"
9
+ "gopkg.in/src-d/go-git.v4/plumbing"
10
+ "gopkg.in/src-d/go-git.v4/plumbing/object"
11
+ )
12
+
13
+ // Basic example of how to list tags.
14
+ func main () {
15
+ CheckArgs ("<path>" )
16
+ path := os .Args [1 ]
17
+
18
+ // We instance a new repository targeting the given path (the .git folder)
19
+ r , err := git .PlainOpen (path )
20
+ CheckIfError (err )
21
+
22
+ // List all tag references, both lightweight tags and annotated tags
23
+ Info ("git show-ref --tag" )
24
+
25
+ tagrefs , err := r .Tags ()
26
+ CheckIfError (err )
27
+ err = tagrefs .ForEach (func (t * plumbing.Reference ) error {
28
+ fmt .Println (t )
29
+ return nil
30
+ })
31
+ CheckIfError (err )
32
+
33
+ // Print each annotated tag object (lightweight tags are not included)
34
+ Info ("for t in $(git show-ref --tag); do if [ \" $(git cat-file -t $t)\" = \" tag\" ]; then git cat-file -p $t ; fi; done" )
35
+
36
+ tags , err := r .TagObjects ()
37
+ CheckIfError (err )
38
+ err = tags .ForEach (func (t * object.Tag ) error {
39
+ fmt .Println (t )
40
+ return nil
41
+ })
42
+ CheckIfError (err )
43
+ }
You can’t perform that action at this time.
0 commit comments