fix(git): correctly identify conflicted files

This commit is contained in:
Jan De Dobbeleer 2023-09-04 16:34:26 +02:00 committed by Jan De Dobbeleer
parent 3d53650b22
commit 8f8dd04ac7
2 changed files with 50 additions and 1 deletions

View file

@ -44,7 +44,7 @@ func (s *GitStatus) add(code string) {
s.Added++
case "?":
s.Untracked++
case "U":
case "U", "AA":
s.Unmerged++
case "M", "R", "C", "m":
s.Modified++
@ -493,6 +493,17 @@ func (g *Git) setGitStatus() {
if len(status) <= 4 {
return
}
// map conflicts separately when in a merge or rebase
if g.Rebase || g.Merge {
conflict := "AA"
full := status[2:4]
if full == conflict {
g.Staging.add(conflict)
return
}
}
workingCode := status[3:4]
stagingCode := status[2:3]
g.Working.add(workingCode)

View file

@ -436,6 +436,8 @@ func TestSetGitStatus(t *testing.T) {
ExpectedUpstreamGone bool
ExpectedAhead int
ExpectedBehind int
Rebase bool
Merge bool
}{
{
Case: "all different options on working and staging, no remote",
@ -535,6 +537,40 @@ func TestSetGitStatus(t *testing.T) {
ExpectedRef: "branch-is-gone",
ExpectedUpstreamGone: true,
},
{
Case: "rebase with 2 merge conflicts",
Output: `
# branch.oid 1234567891011121314
# branch.head rework-git-status
# branch.upstream origin/rework-git-status
# branch.ab +0 -0
1 AA N...
1 AA N...
`,
ExpectedUpstream: "origin/rework-git-status",
ExpectedHash: "1234567",
ExpectedRef: "rework-git-status",
Rebase: true,
ExpectedStaging: &GitStatus{ScmStatus: ScmStatus{Unmerged: 2}},
},
{
Case: "merge with 4 merge conflicts",
Output: `
# branch.oid 1234567891011121314
# branch.head rework-git-status
# branch.upstream origin/rework-git-status
# branch.ab +0 -0
1 AA N...
1 AA N...
1 AA N...
1 AA N...
`,
ExpectedUpstream: "origin/rework-git-status",
ExpectedHash: "1234567",
ExpectedRef: "rework-git-status",
Merge: true,
ExpectedStaging: &GitStatus{ScmStatus: ScmStatus{Unmerged: 4}},
},
}
for _, tc := range cases {
env := new(mock.MockedEnvironment)
@ -554,6 +590,8 @@ func TestSetGitStatus(t *testing.T) {
if tc.ExpectedStaging == nil {
tc.ExpectedStaging = &GitStatus{}
}
g.Rebase = tc.Rebase
g.Merge = tc.Merge
tc.ExpectedStaging.Formats = map[string]string{}
tc.ExpectedWorking.Formats = map[string]string{}
g.setGitStatus()