Skip to content

Commit 9f1813e

Browse files
committed
use exec to checkout branch
1 parent b2d75c0 commit 9f1813e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ require (
5151

5252
require (
5353
github.com/fatih/color v1.18.0
54-
github.com/go-git/go-git/v5 v5.5.2
54+
github.com/go-git/go-git/v5 v5.12.0
5555
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5656
github.com/jroimartin/gocui v0.5.0
5757
github.com/spf13/pflag v1.0.5 // indirect

jet/git.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package jet
22

33
import (
44
"fmt"
5+
"os/exec"
56
"sort"
7+
"strings"
68
"time"
79

810
"github.com/go-git/go-git/v5"
@@ -62,18 +64,13 @@ func (g Git) IsClean() bool {
6264
// Checkout executes a git checkout command with the branch name
6365
// and returns the output and the command that was executed
6466
func (g Git) Checkout(branchName string) error {
65-
w, err := g.repo.Worktree()
66-
67+
result, _, err := g.exec("checkout", branchName)
6768
if err != nil {
68-
return err
69+
return fmt.Errorf("error checking out branch: %s", result)
6970
}
7071

71-
branchRefName := plumbing.NewBranchReferenceName(branchName)
72-
err = w.Checkout(&git.CheckoutOptions{
73-
Branch: plumbing.ReferenceName(branchRefName),
74-
})
72+
return nil
7573

76-
return err
7774
}
7875

7976
// ListBranches executes a git branch command with --list and any other provided args
@@ -130,3 +127,10 @@ func (g Git) Logs(branchName string, n int) []Commit {
130127

131128
return results
132129
}
130+
131+
// exec executes a git command with the provided args
132+
// it returns the output of the command and the command that was executed
133+
func (g Git) exec(args ...string) (string, string, error) {
134+
out, err := exec.Command("git", args...).CombinedOutput()
135+
return string(out), fmt.Sprintf("git %s", strings.Join(args, " ")), err
136+
}

0 commit comments

Comments
 (0)