-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathMergeTool.cs
More file actions
65 lines (55 loc) · 2.04 KB
/
Copy pathMergeTool.cs
File metadata and controls
65 lines (55 loc) · 2.04 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
56
57
58
59
60
61
62
63
64
65
using System;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public class MergeTool : Command
{
public MergeTool(string repo, string file)
{
WorkingDirectory = repo;
Context = repo;
_file = string.IsNullOrEmpty(file) ? string.Empty : file.Quoted();
}
public async Task<bool> OpenAsync()
{
var tool = Native.OS.GetDiffMergeTool(false);
if (tool == null)
{
RaiseException("Invalid diff/merge tool in preference setting!");
return false;
}
if (string.IsNullOrEmpty(tool.Cmd))
{
var ok = await CheckGitConfigurationAsync();
if (!ok)
return false;
Args = $"mergetool -g --no-prompt {_file}";
}
else
{
var cmd = $"{tool.Exec.Quoted()} {tool.Cmd}";
Args = $"-c mergetool.sourcegit.cmd={cmd.Quoted()} -c mergetool.writeToTemp=true -c mergetool.keepBackup=false -c mergetool.trustExitCode=true mergetool --tool=sourcegit {_file}";
}
return await ExecAsync().ConfigureAwait(false);
}
private async Task<bool> CheckGitConfigurationAsync()
{
var tool = await new Config(WorkingDirectory).GetAsync("merge.guitool");
if (string.IsNullOrEmpty(tool))
tool = await new Config(WorkingDirectory).GetAsync("merge.tool");
if (string.IsNullOrEmpty(tool))
{
RaiseException("Missing git configuration: merge.guitool");
return false;
}
if (tool.StartsWith("vimdiff", StringComparison.Ordinal) ||
tool.StartsWith("nvimdiff", StringComparison.Ordinal))
{
RaiseException($"CLI based merge tool \"{tool}\" is not supported by this app!");
return false;
}
return true;
}
private string _file;
}
}