mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-24 02:40:24 +08:00
enhance: warn users if they are using vimdiff or nvimdiff as external merge/diff tool (#1742)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -17,12 +17,15 @@ namespace SourceGit.Commands
|
||||
var tool = Native.OS.GetDiffMergeTool(true);
|
||||
if (tool == null)
|
||||
{
|
||||
App.RaiseException(Context, "Invalid merge tool in preference setting!");
|
||||
App.RaiseException(Context, "Invalid diff/merge tool in preference setting!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(tool.Cmd))
|
||||
{
|
||||
if (!CheckGitConfiguration())
|
||||
return;
|
||||
|
||||
Args = $"difftool -g --no-prompt {_option}";
|
||||
}
|
||||
else
|
||||
@@ -41,6 +44,34 @@ namespace SourceGit.Commands
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
App.RaiseException(Context, "Missing git configuration: diff.guitool");
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool CheckCLIBasedTool(string tool)
|
||||
{
|
||||
if (tool.StartsWith("vimdiff", StringComparison.Ordinal) ||
|
||||
tool.StartsWith("nvimdiff", StringComparison.Ordinal))
|
||||
{
|
||||
App.RaiseException(Context, $"CLI based diff tool \"{tool}\" is not supported by this app!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Models.DiffOption _option;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.Commands
|
||||
{
|
||||
@@ -16,13 +17,17 @@ namespace SourceGit.Commands
|
||||
var tool = Native.OS.GetDiffMergeTool(false);
|
||||
if (tool == null)
|
||||
{
|
||||
App.RaiseException(Context, "Invalid merge tool in preference setting!");
|
||||
App.RaiseException(Context, "Invalid diff/merge tool in preference setting!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(tool.Cmd))
|
||||
{
|
||||
Args = $"mergetool {_file}";
|
||||
var ok = await CheckGitConfigurationAsync();
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
Args = $"mergetool -g --no-prompt {_file}";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -33,6 +38,28 @@ namespace SourceGit.Commands
|
||||
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))
|
||||
{
|
||||
App.RaiseException(Context, "Missing git configuration: merge.guitool");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tool.StartsWith("vimdiff", StringComparison.Ordinal) ||
|
||||
tool.StartsWith("nvimdiff", StringComparison.Ordinal))
|
||||
{
|
||||
App.RaiseException(Context, $"CLI based merge tool \"{tool}\" is not supported by this app!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private string _file;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user