Skip to content

Commit 1d4220f

Browse files
committed
examples, tag: Show git command
1 parent ba94982 commit 1d4220f

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

_examples/tag-create-push/main.go

+6-13
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ func main() {
3030
return
3131
}
3232

33-
if tagExists(tag, r) {
34-
log.Printf("Tag %s already exists, nothing to do here", tag)
35-
return
36-
}
37-
3833
created, err := setTag(r, tag, defaultSignature(name, email))
3934
if err != nil {
4035
log.Printf("create tag error: %s", err)
@@ -59,19 +54,16 @@ func cloneRepo(url, dir, publicKeyPath string) (*git.Repository, error) {
5954
return nil, keyErr
6055
}
6156

57+
Info("git clone %s", url)
6258
r, err := git.PlainClone(dir, false, &git.CloneOptions{
6359
Progress: os.Stdout,
6460
URL: url,
6561
Auth: auth,
6662
})
6763

6864
if err != nil {
69-
if err == git.ErrRepositoryAlreadyExists {
70-
log.Print("repo was already cloned")
71-
} else {
72-
log.Printf("clone git repo error: %s", err)
73-
return nil, err
74-
}
65+
log.Printf("clone git repo error: %s", err)
66+
return nil, err
7567
}
7668

7769
return r, nil
@@ -89,6 +81,7 @@ func publicKey(filePath string) (*ssh.PublicKeys, error) {
8981

9082
func tagExists(tag string, r *git.Repository) bool {
9183
tagFoundErr := "tag was found"
84+
Info("git show-ref --tag")
9285
tags, err := r.TagObjects()
9386
if err != nil {
9487
log.Printf("get tags error: %s", err)
@@ -120,7 +113,7 @@ func setTag(r *git.Repository, tag string, tagger *object.Signature) (bool, erro
120113
log.Printf("get HEAD error: %s", err)
121114
return false, err
122115
}
123-
116+
Info("git tag -a %s %s -m \"%s\"", tag, h.Hash(), tag)
124117
_, err = r.CreateTag(tag, h.Hash(), &git.CreateTagOptions{
125118
Tagger: tagger,
126119
Message: tag,
@@ -144,7 +137,7 @@ func pushTags(r *git.Repository, publicKeyPath string) error {
144137
RefSpecs: []config.RefSpec{config.RefSpec("refs/tags/*:refs/tags/*")},
145138
Auth: auth,
146139
}
147-
140+
Info("git push --tags")
148141
err := r.Push(po)
149142

150143
if err != nil {

0 commit comments

Comments
 (0)