@@ -2,7 +2,9 @@ package jet
2
2
3
3
import (
4
4
"fmt"
5
+ "os/exec"
5
6
"sort"
7
+ "strings"
6
8
"time"
7
9
8
10
"github.com/go-git/go-git/v5"
@@ -62,18 +64,13 @@ func (g Git) IsClean() bool {
62
64
// Checkout executes a git checkout command with the branch name
63
65
// and returns the output and the command that was executed
64
66
func (g Git ) Checkout (branchName string ) error {
65
- w , err := g .repo .Worktree ()
66
-
67
+ result , _ , err := g .exec ("checkout" , branchName )
67
68
if err != nil {
68
- return err
69
+ return fmt . Errorf ( "error checking out branch: %s" , result )
69
70
}
70
71
71
- branchRefName := plumbing .NewBranchReferenceName (branchName )
72
- err = w .Checkout (& git.CheckoutOptions {
73
- Branch : plumbing .ReferenceName (branchRefName ),
74
- })
72
+ return nil
75
73
76
- return err
77
74
}
78
75
79
76
// 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 {
130
127
131
128
return results
132
129
}
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