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

Commit 30e3738

Browse files
Functionality to parse unmerged states
1 parent e7e7bc6 commit 30e3738

File tree

2 files changed

+97
-8
lines changed

2 files changed

+97
-8
lines changed

src/GitHub.Api/OutputProcessors/StatusOutputProcessor.cs

Lines changed: 65 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,15 +135,34 @@ 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+
status = GitFileStatus.Deleted;
155+
staged = !secondPosition;
156+
}
157+
else
158+
{
159+
HandleUnexpected(line);
160+
return;
161+
}
162+
145163
proc.SkipWhitespace();
146164

147165
path = proc.ReadToEnd().Trim('"');
148-
status = GitFileStatus.Deleted;
149166
}
150167
else if (proc.Matches('R'))
151168
{
@@ -163,19 +180,59 @@ public override void LineReceived(string line)
163180
originalPath = files[0];
164181
path = files[1];
165182
status = GitFileStatus.Renamed;
183+
staged = !secondPosition;
166184
}
167185
else if (proc.Matches('A'))
168186
{
169-
//A something added.txt
170187
proc.MoveNext();
188+
if (proc.Matches('A') || proc.Matches('U'))
189+
{
190+
//AA deploy.cmd - unmerged, both added
191+
//AU deploy.cmd - unmerged, added by us
192+
193+
status = GitFileStatus.Unmerged;
194+
}
195+
else if (proc.IsAtWhitespace)
196+
{
197+
//A something added.txt
198+
status = GitFileStatus.Added;
199+
staged = !secondPosition;
200+
}
201+
else
202+
{
203+
HandleUnexpected(line);
204+
return;
205+
}
206+
207+
proc.SkipWhitespace();
208+
209+
path = proc.ReadToEnd().Trim('"');
210+
}
211+
else if (proc.Matches('U'))
212+
{
213+
proc.MoveNext();
214+
if (proc.Matches('D') || proc.Matches('A') || proc.Matches('U'))
215+
{
216+
//UD deploy.cmd - unmerged, deleted by them
217+
//UA deploy.cmd - unmerged, added by them
218+
//UU deploy.cmd - unmerged, both modified
219+
220+
status = GitFileStatus.Unmerged;
221+
}
222+
else
223+
{
224+
HandleUnexpected(line);
225+
return;
226+
}
227+
171228
proc.SkipWhitespace();
172229

173230
path = proc.ReadToEnd().Trim('"');
174-
status = GitFileStatus.Added;
175231
}
176232
else
177233
{
178234
HandleUnexpected(line);
235+
return;
179236
}
180237
}
181238

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)