forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffTool.cs
More file actions
77 lines (67 loc) · 2.32 KB
/
Copy pathDiffTool.cs
File metadata and controls
77 lines (67 loc) · 2.32 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
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Diagnostics;
namespace SourceGit.Commands
{
public class DiffTool : Command
{
public DiffTool(string repo, Models.DiffOption option)
{
WorkingDirectory = repo;
Context = repo;
_option = option;
}
public void Open()
{
var tool = Native.OS.GetDiffMergeTool(true);
if (tool == null)
{
RaiseException("Invalid diff/merge tool in preference setting!");
return;
}
if (string.IsNullOrEmpty(tool.Cmd))
{
if (!CheckGitConfiguration())
return;
Args = $"difftool -g --no-prompt {_option}";
}
else
{
var cmd = $"{tool.Exec.Quoted()} {tool.Cmd}";
Args = $"-c difftool.sourcegit.cmd={cmd.Quoted()} difftool --tool=sourcegit --no-prompt {_option}";
}
try
{
Process.Start(CreateGitStartInfo(false));
}
catch (Exception ex)
{
RaiseException(ex.Message);
}
}
private bool CheckGitConfiguration()
{
var config = new Config(WorkingDirectory).ReadAll();
if (config.TryGetValue("diff.guitool", out var guiTool))
return CheckCLIBasedTool(guiTool);
if (config.TryGetValue("merge.guitool", out var mergeGuiTool))
return CheckCLIBasedTool(mergeGuiTool);
if (config.TryGetValue("diff.tool", out var diffTool))
return CheckCLIBasedTool(diffTool);
if (config.TryGetValue("merge.tool", out var mergeTool))
return CheckCLIBasedTool(mergeTool);
RaiseException("Missing git configuration: diff.guitool");
return false;
}
private bool CheckCLIBasedTool(string tool)
{
if (tool.StartsWith("vimdiff", StringComparison.Ordinal) ||
tool.StartsWith("nvimdiff", StringComparison.Ordinal))
{
RaiseException($"CLI based diff tool \"{tool}\" is not supported by this app!");
return false;
}
return true;
}
private Models.DiffOption _option;
}
}