6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-09 20:24:17 +00:00

Add function mapping libgit's statusList entries to RepoStatus slice

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-18 14:54:21 +02:00
parent acdb877527
commit 0ed1c2147d
2 changed files with 70 additions and 9 deletions

View File

@@ -14,14 +14,41 @@ const (
StatusUnknown
)
func GetStatus(path string) (RepoStatus, error) {
func GetStatus(path string) ([]RepoStatus, error) {
repo, err := git.OpenRepository(path)
if err != nil {
return StatusUnknown, errors.Wrap(err, "failed opening repository")
return nil, errors.Wrap(err, "failed opening repository")
}
_, err = statusEntries(repo)
return StatusOk, nil
entries, err := statusEntries(repo)
if err != nil {
return nil, errors.Wrap(err, "failed opening repository")
}
statusSet := make(map[RepoStatus]bool)
statusSet[StatusOk] = true
for _, entry := range entries {
switch entry.Status {
case git.StatusWtNew:
statusSet[StatusUntrackedFiles] = true
statusSet[StatusOk] = false
case git.StatusIndexNew:
statusSet[StatusUncommittedChanges] = true
statusSet[StatusOk] = false
default:
statusSet[StatusUnknown] = true
statusSet[StatusOk] = false
}
}
var statusSlice []RepoStatus
for k, v := range statusSet {
if v {
statusSlice = append(statusSlice, k)
}
}
return statusSlice, nil
}
func statusEntries(repo *git.Repository) ([]git.StatusEntry, error) {