6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-11 16:23:59 +00:00

[WIP] Replace git2go with go-git

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-26 21:35:57 +02:00
parent 632fb4a9c8
commit 616b476ce1
7 changed files with 284 additions and 2 deletions

48
new/status.go Normal file
View File

@@ -0,0 +1,48 @@
package new
import (
"github.com/go-git/go-git/v5"
"github.com/pkg/errors"
)
type RepoStatus struct {
HasUntrackedFiles bool
HasUncommittedChanges bool
Branches map[string]BranchStatus
}
type BranchStatus struct {
Name string
IsRemote bool
HasUpstream bool
NeedsPull bool
NeedsPush bool
Ahead int
Behind int
}
func (r *Repo) LoadStatus() error {
wt, err := r.repo.Worktree()
if err != nil {
return errors.Wrap(err, "Failed getting worktree")
}
status, err := wt.Status()
if err != nil {
return errors.Wrap(err, "Failed getting worktree status")
}
r.Status.HasUncommittedChanges = !status.IsClean()
r.Status.HasUntrackedFiles = hasUntracked(status)
return nil
}
// hasUntracked returns true if there's any untracked file in the worktree
func hasUntracked(status git.Status) bool {
for _, fs := range status {
if fs.Worktree == git.Untracked {
return true
}
}
return false
}