diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 0c7509b91..cbf7aa2b8 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -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 } diff --git a/pkg/commands/git_structs.go b/pkg/commands/git_structs.go index 2b3b3f2db..cb2d125fa 100644 --- a/pkg/commands/git_structs.go +++ b/pkg/commands/git_structs.go @@ -17,6 +17,7 @@ type Commit struct { Sha string Name string Pushed bool + Merged bool DisplayString string } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 1c1662475..3d9b10058 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -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 }