Skip to content

Commit

Permalink
fix: recognize tag and commit merges
Browse files Browse the repository at this point in the history
  • Loading branch information
asherber authored and JanDeDobbeleer committed Sep 14, 2021
1 parent 98c3f50 commit 3ecdffd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/segment_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/segment_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3ecdffd

Please sign in to comment.