8000 Improved IsConflicResolved check, to work for submodule conflicts · sourcegit-scm/sourcegit@d928e69 · GitHub
[go: up one dir, main page]

Skip to content

Commit d928e69

Browse files
committed
Improved IsConflicResolved check, to work for submodule conflicts
1 parent e28b75b commit d928e69

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/Commands/IsConflictResolved.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,38 @@
22
{
33
public class IsConflictResolved : Command
44
{
5+
private string StatusArgs;
6+
private string DiffArgs;
7+
58
public IsConflictResolved(string repo, Models.Change change)
69
{
710
var opt = new Models.DiffOption(change, true);
811

912
WorkingDirectory = repo;
1013
Context = repo;
11-
Args = $"diff -a --ignore-cr-at-eol --check {opt}";
14+
15+
StatusArgs = $"--no-optional-locks status --porcelain=v2 -- \"{change.Path}\"";
16+
DiffArgs = $"diff -a --ignore-cr-at-eol --check {opt}";
1217
}
1318

1419
public bool Result()
1520
{
16-
return ReadToEnd().IsSuccess;
21+
// First, check if the file is still "unmerged"...
22+
Args = StatusArgs;
23+
var rs = ReadToEnd();
24+
if (rs.IsSuccess && rs.StdOut.StartsWith("u"))
25+
{
26+
// Then, check if the file is a submodule (then we can't use a text-diff).
27+
// Porcelain Format Version 2, Unmerged entry: "u <XY> <N|S><c><m><u> <...>"
28+
if (rs.StdOut.Substring(5, 1) == "S")
29+
return false;
30+
31+
// Finally, run a text-diff, checking for conflict-markers.
32+
// (NOTE: Could possibly give false positives for whitespace errors?)
33+
Args = DiffArgs;
34+
return ReadToEnd().IsSuccess;
35+
}
36+
return true;
1737
}
1838
}
1939
}

0 commit comments

Comments
 (0)
0