forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryConflictFileState.cs
More file actions
55 lines (46 loc) · 1.78 KB
/
Copy pathQueryConflictFileState.cs
File metadata and controls
55 lines (46 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public class QueryConflictFileState : Command
{
public QueryConflictFileState(string repo, Models.Change change)
{
var opt = new Models.DiffOption(change, true);
WorkingDirectory = repo;
Context = repo;
Args = $"diff --no-color --no-ext-diff --full-index --patch {opt}";
}
public async Task<Models.ConflictFileState> GetResultAsync()
{
try
{
using var proc = new Process();
proc.StartInfo = CreateGitStartInfo(true);
proc.Start();
var isBinary = false;
var tokenCount = 0;
while (await proc.StandardOutput.ReadLineAsync().ConfigureAwait(false) is { } line)
{
if (isBinary)
continue;
if (line.StartsWith("Binary files ", StringComparison.Ordinal))
isBinary = true;
else if (line.StartsWith("++<<<<<<<", StringComparison.Ordinal) ||
line.StartsWith("++=======", StringComparison.Ordinal) ||
line.StartsWith("++>>>>>>>", StringComparison.Ordinal))
tokenCount++;
}
await proc.WaitForExitAsync().ConfigureAwait(false);
if (isBinary)
return Models.ConflictFileState.UnmergedBinary;
return tokenCount == 0 ? Models.ConflictFileState.Resolved : Models.ConflictFileState.UnmergedText;
}
catch
{
return Models.ConflictFileState.Unknown;
}
}
}
}