Skip to content

Commit 09fc85c

Browse files
committed
refactor: swap go-git for push with exec
will use exec for the git push commands since go-git requires manual authentication while pushing
1 parent 5bafe9d commit 09fc85c

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

Diff for: commands/release.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package commands
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"path"
78

9+
"github.com/barelyhuman/commitlog/lib"
810
"github.com/barelyhuman/commitlog/pkg"
911
"github.com/go-git/go-git/v5"
10-
"github.com/go-git/go-git/v5/config"
1112
"github.com/go-git/go-git/v5/plumbing"
1213
"github.com/urfave/cli/v2"
1314
)
@@ -114,16 +115,25 @@ func Release(c *cli.Context) (err error) {
114115
}
115116

116117
if c.Bool("push") {
117-
_, err := repoWt.Status()
118+
_, err = repoWt.Status()
118119
if err != nil {
119120
return err
120121
}
121122

122-
gitRepo.Push(&git.PushOptions{
123-
RemoteName: "origin",
124-
Progress: os.Stdout,
125-
RefSpecs: []config.RefSpec{config.RefSpec("refs/tags/*:refs/tags/*")},
126-
})
123+
cmd := exec.Command("git", "push")
124+
cmd.Dir = fileDir
125+
err = lib.Command(cmd)
126+
127+
if err != nil {
128+
return err
129+
}
130+
131+
cmd = exec.Command("git", "push", "--tags")
132+
cmd.Dir = fileDir
133+
134+
if err = lib.Command(cmd); err != nil {
135+
return err
136+
}
127137
}
128138

129139
return err

Diff for: lib/commands.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package lib
2+
3+
import (
4+
"log"
5+
"os/exec"
6+
"strings"
7+
)
8+
9+
func Command(cmd *exec.Cmd) error {
10+
var w strings.Builder
11+
cmd.Stderr = &w
12+
err := cmd.Run()
13+
if err != nil {
14+
log.Println(strings.TrimSpace(w.String()))
15+
return err
16+
}
17+
return nil
18+
}

0 commit comments

Comments
 (0)