6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 19:44:41 +00:00
Files
git-get/new/status.go
2020-05-27 12:54:49 +02:00

50 lines
961 B
Go

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 are any untracked files in the worktree
func hasUntracked(status git.Status) bool {
for _, fs := range status {
if fs.Worktree == git.Untracked {
return true
}
}
return false
}