fix: recognize tag and commit merges

This commit is contained in:
Aaron Sherber 2021-09-13 18:00:59 -04:00 committed by Jan De Dobbeleer
parent 98c3f50fc0
commit 3ecdffd86c
2 changed files with 37 additions and 3 deletions

View file

@ -350,10 +350,20 @@ func (g *git) getGitHEADContext(ref string) string {
if g.hasGitFile("MERGE_MSG") && g.hasGitFile("MERGE_HEAD") {
icon := g.props.getString(MergeIcon, "\uE727 ")
mergeContext := g.getGitFileContents(g.repo.gitWorkingFolder, "MERGE_MSG")
matches := findNamedRegexMatch(`Merge (remote-tracking )?branch '(?P<head>.*)' into`, mergeContext)
matches := findNamedRegexMatch(`Merge (?P<type>(remote-tracking )?branch|commit|tag) '(?P<head>.*)' into`, mergeContext)
if matches != nil && matches["head"] != "" {
branch := g.truncateBranch(matches["head"])
return fmt.Sprintf("%s%s%s into %s", icon, branchIcon, branch, ref)
var headIcon string
switch matches["type"] {
case "tag":
headIcon = g.props.getString(TagIcon, "\uF412")
case "commit":
headIcon = g.props.getString(CommitIcon, "\uF417")
default:
headIcon = branchIcon
}
head := g.truncateBranch(matches["head"])
return fmt.Sprintf("%s%s%s into %s", icon, headIcon, head, ref)
}
}
// sequencer status

View file

@ -325,6 +325,30 @@ func TestGetGitHEADContextMergeRemote(t *testing.T) {
}
func TestGetGitHEADContextMergeTag(t *testing.T) {
want := "\ue727 \uf412v7.8.9 into \ue0a0main"
context := &detachedContext{
merge: true,
mergeHEAD: "v7.8.9",
mergeMsgStart: "Merge tag",
}
g := setupHEADContextEnv(context)
got := g.getGitHEADContext("main")
assert.Equal(t, want, got)
}
func TestGetGitHEADContextMergeCommit(t *testing.T) {
want := "\ue727 \uf4178d7e869 into \ue0a0main"
context := &detachedContext{
merge: true,
mergeHEAD: "8d7e869",
mergeMsgStart: "Merge commit",
}
g := setupHEADContextEnv(context)
got := g.getGitHEADContext("main")
assert.Equal(t, want, got)
}
func TestGetGitHEADContextMergeIntoTag(t *testing.T) {
want := "\ue727 \ue0a0feat into \uf412v3.4.6"
context := &detachedContext{
tagName: "v3.4.6",