mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
color merged and unmerged commits differently
This commit is contained in:
@ -462,23 +462,48 @@ func includesString(list []string, a string) bool {
|
|||||||
return false
|
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
|
// GetCommits obtains the commits of the current branch
|
||||||
func (c *GitCommand) GetCommits() []Commit {
|
func (c *GitCommand) GetCommits() []Commit {
|
||||||
pushables := c.GetCommitsToPush()
|
pushables := c.GetCommitsToPush()
|
||||||
log := c.GetLog()
|
log := c.GetLog()
|
||||||
commits := []Commit{}
|
|
||||||
// now we can split it up and turn it into commits
|
// now we can split it up and turn it into commits
|
||||||
lines := utils.SplitLines(log)
|
lines := utils.SplitLines(log)
|
||||||
for _, line := range lines {
|
commits := make([]Commit, len(lines))
|
||||||
|
for i, line := range lines {
|
||||||
splitLine := strings.Split(line, " ")
|
splitLine := strings.Split(line, " ")
|
||||||
sha := splitLine[0]
|
sha := splitLine[0]
|
||||||
pushed := includesString(pushables, sha)
|
pushed := !includesString(pushables, sha)
|
||||||
commits = append(commits, Commit{
|
commits[i] = Commit{
|
||||||
Sha: sha,
|
Sha: sha,
|
||||||
Name: strings.Join(splitLine[1:], " "),
|
Name: strings.Join(splitLine[1:], " "),
|
||||||
Pushed: pushed,
|
Pushed: pushed,
|
||||||
DisplayString: strings.Join(splitLine, " "),
|
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
|
return commits
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ type Commit struct {
|
|||||||
Sha string
|
Sha string
|
||||||
Name string
|
Name string
|
||||||
Pushed bool
|
Pushed bool
|
||||||
|
Merged bool
|
||||||
DisplayString string
|
DisplayString string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,15 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
v.Clear()
|
v.Clear()
|
||||||
red := color.New(color.FgRed)
|
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)
|
white := color.New(color.FgWhite)
|
||||||
shaColor := white
|
shaColor := white
|
||||||
for _, commit := range gui.State.Commits {
|
for _, commit := range gui.State.Commits {
|
||||||
if commit.Pushed {
|
if !commit.Pushed {
|
||||||
shaColor = red
|
shaColor = red
|
||||||
|
} else if !commit.Merged {
|
||||||
|
shaColor = green
|
||||||
} else {
|
} else {
|
||||||
shaColor = yellow
|
shaColor = yellow
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user