Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 58e13aa

Browse files
author
Andreia Gaita
authored
Merge pull request #982 from github-for-unity/unmerged-states
Unmerged states
2 parents e7e7bc6 + 90d88f7 commit 58e13aa

File tree

2 files changed

+103
-8
lines changed

2 files changed

+103
-8
lines changed

src/GitHub.Api/OutputProcessors/StatusOutputProcessor.cs

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,11 @@ public override void LineReceived(string line)
120120
}
121121
else
122122
{
123+
var secondPosition = false;
123124
if (proc.IsAtWhitespace)
124125
{
125126
proc.SkipWhitespace();
126-
}
127-
else
128-
{
129-
staged = true;
127+
secondPosition = true;
130128
}
131129

132130
if (proc.Matches('M'))
@@ -137,19 +135,42 @@ public override void LineReceived(string line)
137135

138136
path = proc.ReadToEnd().Trim('"');
139137
status = GitFileStatus.Modified;
138+
staged = !secondPosition;
140139
}
141140
else if (proc.Matches('D'))
142141
{
143-
//D deploy.cmd
144142
proc.MoveNext();
143+
144+
if (proc.Matches('D') || proc.Matches('U'))
145+
{
146+
//DD deploy.cmd - unmerged, both deleted
147+
//DU deploy.cmd - unmerged, deleted by us
148+
149+
status = GitFileStatus.Unmerged;
150+
}
151+
else if(proc.IsAtWhitespace)
152+
{
153+
//D deploy.cmd
154+
// D deploy.cmd
155+
156+
status = GitFileStatus.Deleted;
157+
staged = !secondPosition;
158+
}
159+
else
160+
{
161+
HandleUnexpected(line);
162+
return;
163+
}
164+
145165
proc.SkipWhitespace();
146166

147167
path = proc.ReadToEnd().Trim('"');
148-
status = GitFileStatus.Deleted;
149168
}
150169
else if (proc.Matches('R'))
151170
{
152171
//R README.md -> README2.md
172+
// R README.md -> README2.md
173+
153174
proc.MoveNext();
154175
proc.SkipWhitespace();
155176

@@ -163,19 +184,61 @@ public override void LineReceived(string line)
163184
originalPath = files[0];
164185
path = files[1];
165186
status = GitFileStatus.Renamed;
187+
staged = !secondPosition;
166188
}
167189
else if (proc.Matches('A'))
168190
{
169-
//A something added.txt
170191
proc.MoveNext();
192+
if (proc.Matches('A') || proc.Matches('U'))
193+
{
194+
//AA deploy.cmd - unmerged, both added
195+
//AU deploy.cmd - unmerged, added by us
196+
197+
status = GitFileStatus.Unmerged;
198+
}
199+
else if (proc.IsAtWhitespace)
200+
{
201+
//A something added.txt
202+
// A something added.txt
203+
204+
status = GitFileStatus.Added;
205+
staged = !secondPosition;
206+
}
207+
else
208+
{
209+
HandleUnexpected(line);
210+
return;
211+
}
212+
213+
proc.SkipWhitespace();
214+
215+
path = proc.ReadToEnd().Trim('"');
216+
}
217+
else if (proc.Matches('U'))
218+
{
219+
proc.MoveNext();
220+
if (proc.Matches('D') || proc.Matches('A') || proc.Matches('U'))
221+
{
222+
//UD deploy.cmd - unmerged, deleted by them
223+
//UA deploy.cmd - unmerged, added by them
224+
//UU deploy.cmd - unmerged, both modified
225+
226+
status = GitFileStatus.Unmerged;
227+
}
228+
else
229+
{
230+
HandleUnexpected(line);
231+
return;
232+
}
233+
171234
proc.SkipWhitespace();
172235

173236
path = proc.ReadToEnd().Trim('"');
174-
status = GitFileStatus.Added;
175237
}
176238
else
177239
{
178240
HandleUnexpected(line);
241+
return;
179242
}
180243
}
181244

src/tests/UnitTests/IO/StatusOutputProcessorTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,38 @@ public void ShouldParseDirtyWorkingTreeUntracked()
3737
});
3838
}
3939

40+
[Test]
41+
public void ShouldParseUnmergedStates()
42+
{
43+
var output = new[]
44+
{
45+
"## master",
46+
"DD something1.txt",
47+
"AU something2.txt",
48+
"UD something3.txt",
49+
"UA something4.txt",
50+
"DU something5.txt",
51+
"AA something6.txt",
52+
"UU something7.txt",
53+
null
54+
};
55+
56+
AssertProcessOutput(output, new GitStatus
57+
{
58+
LocalBranch = "master",
59+
Entries = new List<GitStatusEntry>
60+
{
61+
new GitStatusEntry("something1.txt", TestRootPath + @"\something1.txt", null, GitFileStatus.Unmerged),
62+
new GitStatusEntry("something2.txt", TestRootPath + @"\something2.txt", null, GitFileStatus.Unmerged),
63+
new GitStatusEntry("something3.txt", TestRootPath + @"\something3.txt", null, GitFileStatus.Unmerged),
64+
new GitStatusEntry("something4.txt", TestRootPath + @"\something4.txt", null, GitFileStatus.Unmerged),
65+
new GitStatusEntry("something5.txt", TestRootPath + @"\something5.txt", null, GitFileStatus.Unmerged),
66+
new GitStatusEntry("something6.txt", TestRootPath + @"\something6.txt", null, GitFileStatus.Unmerged),
67+
new GitStatusEntry("something7.txt", TestRootPath + @"\something7.txt", null, GitFileStatus.Unmerged),
68+
}
69+
});
70+
}
71+
4072
[Test]
4173
public void ShouldParseDirtyWorkingTreeTrackedAhead1Behind1()
4274
{

0 commit comments

Comments
 (0)