summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/git/branch.go28
-rw-r--r--pkg/git/git-commands.go10
2 files changed, 30 insertions, 8 deletions
diff --git a/pkg/git/branch.go b/pkg/git/branch.go
index a700c30..138ff62 100644
--- a/pkg/git/branch.go
+++ b/pkg/git/branch.go
@@ -1,6 +1,7 @@
package git
import (
+ "github.com/isacikgoz/gitbatch/pkg/utils"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"strings"
@@ -85,15 +86,26 @@ func (entity *RepoEntity) Checkout(branch *Branch) error {
}
func (entity *RepoEntity) isClean() bool {
- worktree, err := entity.Repository.Worktree()
- if err != nil {
- return true
- }
- status, err := worktree.Status()
- if err != nil {
- return false
+ // this method is painfully slow
+ // worktree, err := entity.Repository.Worktree()
+ // if err != nil {
+ // return true
+ // }
+ // status, err := worktree.Status()
+ // if err != nil {
+ // return false
+ // }
+ // return status.IsClean()
+ status := entity.StatusWithGit()
+ status = utils.TrimTrailingNewline(status)
+ if status != "?" {
+ verbose := strings.Split(status, "\n")
+ lastLine := verbose[len(verbose)-1]
+ if strings.Contains(lastLine, "working tree clean") {
+ return true
+ }
}
- return status.IsClean()
+ return false
}
func (entity *RepoEntity) RefreshPushPull() {
diff --git a/pkg/git/git-commands.go b/pkg/git/git-commands.go
index 41d30c3..1dbb73c 100644
--- a/pkg/git/git-commands.go
+++ b/pkg/git/git-commands.go
@@ -85,3 +85,13 @@ func (entity *RepoEntity) CheckoutWithGit(branch string) error {
}
return nil
}
+
+// GitStatus returns the plaintext short status of the repo
+func (entity *RepoEntity) StatusWithGit() string {
+ args := []string{"status"}
+ status, err := command.RunCommandWithOutput(entity.AbsPath, "git", args)
+ if err != nil {
+ return "?"
+ }
+ return status
+} \ No newline at end of file