diff options
| author | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2018-11-28 15:45:40 +0300 |
|---|---|---|
| committer | İbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com> | 2018-11-28 15:45:40 +0300 |
| commit | 010a5fbff65b9b79ca87bfa9a07bbaccacf015da (patch) | |
| tree | 1d3dca63cd1ad63b409d254f5493e7f1244266c2 | |
| parent | added smart remote/branch selection (diff) | |
| download | gitbatch-010a5fbff65b9b79ca87bfa9a07bbaccacf015da.tar.gz | |
convetional clean check for repositories
| -rw-r--r-- | pkg/git/branch.go | 28 | ||||
| -rw-r--r-- | pkg/git/git-commands.go | 10 |
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 |
