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

Unmerged states #982

Merged
merged 3 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 71 additions & 8 deletions src/GitHub.Api/OutputProcessors/StatusOutputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,11 @@ public override void LineReceived(string line)
}
else
{
var secondPosition = false;
if (proc.IsAtWhitespace)
{
proc.SkipWhitespace();
}
else
{
staged = true;
secondPosition = true;
}

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

path = proc.ReadToEnd().Trim('"');
status = GitFileStatus.Modified;
staged = !secondPosition;
}
else if (proc.Matches('D'))
{
//D deploy.cmd
proc.MoveNext();

if (proc.Matches('D') || proc.Matches('U'))
{
//DD deploy.cmd - unmerged, both deleted
//DU deploy.cmd - unmerged, deleted by us

status = GitFileStatus.Unmerged;
}
else if(proc.IsAtWhitespace)
{
//D deploy.cmd
// D deploy.cmd

status = GitFileStatus.Deleted;
staged = !secondPosition;
}
else
{
HandleUnexpected(line);
return;
}

proc.SkipWhitespace();

path = proc.ReadToEnd().Trim('"');
status = GitFileStatus.Deleted;
}
else if (proc.Matches('R'))
{
//R README.md -> README2.md
// R README.md -> README2.md

proc.MoveNext();
proc.SkipWhitespace();

Expand All @@ -163,19 +184,61 @@ public override void LineReceived(string line)
originalPath = files[0];
path = files[1];
status = GitFileStatus.Renamed;
staged = !secondPosition;
}
else if (proc.Matches('A'))
{
//A something added.txt
proc.MoveNext();
if (proc.Matches('A') || proc.Matches('U'))
{
//AA deploy.cmd - unmerged, both added
//AU deploy.cmd - unmerged, added by us

status = GitFileStatus.Unmerged;
}
else if (proc.IsAtWhitespace)
{
//A something added.txt
// A something added.txt

status = GitFileStatus.Added;
staged = !secondPosition;
}
else
{
HandleUnexpected(line);
return;
}

proc.SkipWhitespace();

path = proc.ReadToEnd().Trim('"');
}
else if (proc.Matches('U'))
{
proc.MoveNext();
if (proc.Matches('D') || proc.Matches('A') || proc.Matches('U'))
{
//UD deploy.cmd - unmerged, deleted by them
//UA deploy.cmd - unmerged, added by them
//UU deploy.cmd - unmerged, both modified

status = GitFileStatus.Unmerged;
}
else
{
HandleUnexpected(line);
return;
}

proc.SkipWhitespace();

path = proc.ReadToEnd().Trim('"');
status = GitFileStatus.Added;
}
else
{
HandleUnexpected(line);
return;
}
}

Expand Down
32 changes: 32 additions & 0 deletions src/tests/UnitTests/IO/StatusOutputProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,38 @@ public void ShouldParseDirtyWorkingTreeUntracked()
});
}

[Test]
public void ShouldParseUnmergedStates()
{
var output = new[]
{
"## master",
"DD something1.txt",
"AU something2.txt",
"UD something3.txt",
"UA something4.txt",
"DU something5.txt",
"AA something6.txt",
"UU something7.txt",
null
};

AssertProcessOutput(output, new GitStatus
{
LocalBranch = "master",
Entries = new List<GitStatusEntry>
{
new GitStatusEntry("something1.txt", TestRootPath + @"\something1.txt", null, GitFileStatus.Unmerged),
new GitStatusEntry("something2.txt", TestRootPath + @"\something2.txt", null, GitFileStatus.Unmerged),
new GitStatusEntry("something3.txt", TestRootPath + @"\something3.txt", null, GitFileStatus.Unmerged),
new GitStatusEntry("something4.txt", TestRootPath + @"\something4.txt", null, GitFileStatus.Unmerged),
new GitStatusEntry("something5.txt", TestRootPath + @"\something5.txt", null, GitFileStatus.Unmerged),
new GitStatusEntry("something6.txt", TestRootPath + @"\something6.txt", null, GitFileStatus.Unmerged),
new GitStatusEntry("something7.txt", TestRootPath + @"\something7.txt", null, GitFileStatus.Unmerged),
}
});
}

[Test]
public void ShouldParseDirtyWorkingTreeTrackedAhead1Behind1()
{
Expand Down