1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

color merged and unmerged commits differently

This commit is contained in:
Jesse Duffield
2018-09-18 21:32:24 +10:00
parent ca2eec60fe
commit c789bba673
3 changed files with 36 additions and 7 deletions

View File

@ -462,23 +462,48 @@ func includesString(list []string, a string) bool {
return false
}
func (c *GitCommand) getMergeBase() string {
output, err := c.OSCommand.RunCommandWithOutput("git merge-base HEAD master") // TODO: support develop as well
if err != nil {
c.Log.Error("Could not get merge base")
return ""
}
return output
}
// GetCommits obtains the commits of the current branch
func (c *GitCommand) GetCommits() []Commit {
pushables := c.GetCommitsToPush()
log := c.GetLog()
commits := []Commit{}
// now we can split it up and turn it into commits
lines := utils.SplitLines(log)
for _, line := range lines {
commits := make([]Commit, len(lines))
for i, line := range lines {
splitLine := strings.Split(line, " ")
sha := splitLine[0]
pushed := includesString(pushables, sha)
commits = append(commits, Commit{
pushed := !includesString(pushables, sha)
commits[i] = Commit{
Sha: sha,
Name: strings.Join(splitLine[1:], " "),
Pushed: pushed,
DisplayString: strings.Join(splitLine, " "),
})
}
}
commits = c.setCommitMergedStatuses(commits)
return commits
}
func (c *GitCommand) setCommitMergedStatuses(commits []Commit) []Commit {
ancestor := c.getMergeBase()
if ancestor == "" {
return commits
}
passedAncestor := false
for i, commit := range commits {
if strings.HasPrefix(ancestor, commit.Sha) {
passedAncestor = true
}
commits[i].Merged = passedAncestor
}
return commits
}

View File

@ -17,6 +17,7 @@ type Commit struct {
Sha string
Name string
Pushed bool
Merged bool
DisplayString string
}

View File

@ -17,12 +17,15 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error {
}
v.Clear()
red := color.New(color.FgRed)
yellow := color.New(color.FgYellow)
yellow := color.New(color.FgGreen)
green := color.New(color.FgYellow)
white := color.New(color.FgWhite)
shaColor := white
for _, commit := range gui.State.Commits {
if commit.Pushed {
if !commit.Pushed {
shaColor = red
} else if !commit.Merged {
shaColor = green
} else {
shaColor = yellow
}