mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
fix(git): correctly identify conflicted files
This commit is contained in:
parent
3d53650b22
commit
8f8dd04ac7
|
@ -44,7 +44,7 @@ func (s *GitStatus) add(code string) {
|
||||||
s.Added++
|
s.Added++
|
||||||
case "?":
|
case "?":
|
||||||
s.Untracked++
|
s.Untracked++
|
||||||
case "U":
|
case "U", "AA":
|
||||||
s.Unmerged++
|
s.Unmerged++
|
||||||
case "M", "R", "C", "m":
|
case "M", "R", "C", "m":
|
||||||
s.Modified++
|
s.Modified++
|
||||||
|
@ -493,6 +493,17 @@ func (g *Git) setGitStatus() {
|
||||||
if len(status) <= 4 {
|
if len(status) <= 4 {
|
||||||
return
|
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]
|
workingCode := status[3:4]
|
||||||
stagingCode := status[2:3]
|
stagingCode := status[2:3]
|
||||||
g.Working.add(workingCode)
|
g.Working.add(workingCode)
|
||||||
|
|
|
@ -436,6 +436,8 @@ func TestSetGitStatus(t *testing.T) {
|
||||||
ExpectedUpstreamGone bool
|
ExpectedUpstreamGone bool
|
||||||
ExpectedAhead int
|
ExpectedAhead int
|
||||||
ExpectedBehind int
|
ExpectedBehind int
|
||||||
|
Rebase bool
|
||||||
|
Merge bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Case: "all different options on working and staging, no remote",
|
Case: "all different options on working and staging, no remote",
|
||||||
|
@ -535,6 +537,40 @@ func TestSetGitStatus(t *testing.T) {
|
||||||
ExpectedRef: "branch-is-gone",
|
ExpectedRef: "branch-is-gone",
|
||||||
ExpectedUpstreamGone: true,
|
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 {
|
for _, tc := range cases {
|
||||||
env := new(mock.MockedEnvironment)
|
env := new(mock.MockedEnvironment)
|
||||||
|
@ -554,6 +590,8 @@ func TestSetGitStatus(t *testing.T) {
|
||||||
if tc.ExpectedStaging == nil {
|
if tc.ExpectedStaging == nil {
|
||||||
tc.ExpectedStaging = &GitStatus{}
|
tc.ExpectedStaging = &GitStatus{}
|
||||||
}
|
}
|
||||||
|
g.Rebase = tc.Rebase
|
||||||
|
g.Merge = tc.Merge
|
||||||
tc.ExpectedStaging.Formats = map[string]string{}
|
tc.ExpectedStaging.Formats = map[string]string{}
|
||||||
tc.ExpectedWorking.Formats = map[string]string{}
|
tc.ExpectedWorking.Formats = map[string]string{}
|
||||||
g.setGitStatus()
|
g.setGitStatus()
|
||||||
|
|
Loading…
Reference in a new issue