1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-10 11:10:18 +02:00

ensure that when a branch name is ambiguous we still show the correct colours

This commit is contained in:
Jesse Duffield 2020-09-02 20:39:24 +10:00 committed by github-actions[bot]
parent 250fe740b2
commit 9eba98302e

View File

@ -172,7 +172,7 @@ func (c *CommitListBuilder) GetCommits(opts GetCommitsOptions) ([]*Commit, error
currentCommit.Name = fmt.Sprintf("%s %s", youAreHere, currentCommit.Name) currentCommit.Name = fmt.Sprintf("%s %s", youAreHere, currentCommit.Name)
} }
commits, err = c.setCommitMergedStatuses(commits) commits, err = c.setCommitMergedStatuses(opts.RefName, commits)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -290,8 +290,8 @@ func (c *CommitListBuilder) commitFromPatch(content string) (*Commit, error) {
}, nil }, nil
} }
func (c *CommitListBuilder) setCommitMergedStatuses(commits []*Commit) ([]*Commit, error) { func (c *CommitListBuilder) setCommitMergedStatuses(refName string, commits []*Commit) ([]*Commit, error) {
ancestor, err := c.getMergeBase() ancestor, err := c.getMergeBase(refName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -313,7 +313,7 @@ func (c *CommitListBuilder) setCommitMergedStatuses(commits []*Commit) ([]*Commi
return commits, nil return commits, nil
} }
func (c *CommitListBuilder) getMergeBase() (string, error) { func (c *CommitListBuilder) getMergeBase(refName string) (string, error) {
currentBranch, _, err := c.GitCommand.CurrentBranchName() currentBranch, _, err := c.GitCommand.CurrentBranchName()
if err != nil { if err != nil {
return "", err return "", err
@ -325,8 +325,18 @@ func (c *CommitListBuilder) getMergeBase() (string, error) {
} }
// swallowing error because it's not a big deal; probably because there are no commits yet // swallowing error because it's not a big deal; probably because there are no commits yet
output, _ := c.OSCommand.RunCommandWithOutput("git merge-base HEAD %s", baseBranch) output, _ := c.OSCommand.RunCommandWithOutput("git merge-base %s %s", refName, baseBranch)
return output, nil return ignoringWarnings(output), nil
}
func ignoringWarnings(commandOutput string) string {
trimmedOutput := strings.TrimSpace(commandOutput)
split := strings.Split(trimmedOutput, "\n")
// need to get last line in case the first line is a warning about how the error is ambiguous.
// At some point we should find a way to make it unambiguous
lastLine := split[len(split)-1]
return lastLine
} }
// getFirstPushedCommit returns the first commit SHA which has been pushed to the ref's upstream. // getFirstPushedCommit returns the first commit SHA which has been pushed to the ref's upstream.
@ -336,7 +346,8 @@ func (c *CommitListBuilder) getFirstPushedCommit(refName string) (string, error)
if err != nil { if err != nil {
return "", err return "", err
} }
return strings.TrimSpace(output), nil
return ignoringWarnings(output), nil
} }
// getLog gets the git log. // getLog gets the git log.