Skip to content

Commit

Permalink
feat: Add cleanness indicator "*" before the commit hash ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Maverobot committed Jul 14, 2021
1 parent ac42d37 commit 7687374
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func initFlagParser(path *string, level *int, color *bool, update *bool, showVer
flag.BoolVar(showVersion, "version", false, "Show version")
}

const version = "0.1"
const version = "0.2"
const slug = "maverobot/ggit"

func selfUpdate(slug string) error {
Expand Down Expand Up @@ -121,11 +121,20 @@ func main() {
head, err3 := getCurrentCommit(r)
latestTag, err4 := getLatestTag(r)
relPath, err5 := filepath.Rel(dirPath, path)
if err1 == nil && err2 == nil && err3 == nil && err4 == nil && err5 == nil {
isClean, err6 := isClean(r)

var cleannessPrefix string
if isClean {
cleannessPrefix = ""
} else {
cleannessPrefix = "*"
}

if err1 == nil && err2 == nil && err3 == nil && err4 == nil && err5 == nil && err6 == nil {
if len(remoteNames) == 0 {
rows = append(rows, table.Row{relPath, head[:7], branch, tag, latestTag, ""})
rows = append(rows, table.Row{relPath, cleannessPrefix + head[:7], branch, tag, latestTag, ""})
} else {
rows = append(rows, table.Row{relPath, head[:7], branch, tag, latestTag, strings.Join(remoteNames, "\n")})
rows = append(rows, table.Row{relPath, cleannessPrefix + head[:7], branch, tag, latestTag, strings.Join(remoteNames, "\n")})
}
}
}
Expand Down Expand Up @@ -265,6 +274,18 @@ func getCurrentCommit(repository *git.Repository) (string, error) {
return headSha, nil
}

func isClean(repository *git.Repository) (bool, error) {
w, err := repository.Worktree()
if err != nil {
return false, err
}
status, err := w.Status()
if err != nil {
return false, err
}
return status.IsClean(), err
}

func getLatestTag(repository *git.Repository) (string, error) {
tagRefs, err := repository.Tags()
if err != nil {
Expand Down

0 comments on commit 7687374

Please sign in to comment.