feature<MergeTool>: supports to use WinMerge as git.mergetool

This commit is contained in:
leo 2021-05-28 20:49:43 +08:00
parent e5ac504134
commit 11420ee5b4
3 changed files with 20 additions and 1 deletions

View file

@ -42,6 +42,11 @@ namespace SourceGit.Commands {
/// </summary>
public string Args { get; set; } = "";
/// <summary>
/// 是否忽略错误
/// </summary>
public bool DontRaiseError { get; set; } = false;
/// <summary>
/// 使用标准错误输出
/// </summary>
@ -115,7 +120,7 @@ namespace SourceGit.Commands {
proc.Close();
if (!isCancelled && exitCode != 0 && errs.Count > 0) {
Models.Exception.Raise(string.Join("\n", errs));
if (!DontRaiseError) Models.Exception.Raise(string.Join("\n", errs));
return false;
} else {
return true;

View file

@ -22,6 +22,7 @@ namespace SourceGit.Models {
new MergeTool(3, "Tortoise Merge", "TortoiseMerge.exe", "-base:\"$BASE\" -theirs:\"$REMOTE\" -mine:\"$LOCAL\" -merged:\"$MERGED\"", FindTortoiseMerge),
new MergeTool(4, "KDiff3", "kdiff3.exe", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", FindKDiff3),
new MergeTool(5, "Beyond Compare 4", "BComp.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", FindBCompare),
new MergeTool(6, "WinMerge", "WinMergeU.exe", "-u -e \"$REMOTE\" \"$LOCAL\" \"$MERGED\"", FindWinMerge),
};
public MergeTool(int type, string name, string exec, string cmd, Func<string> finder) {
@ -115,5 +116,17 @@ namespace SourceGit.Models {
var dir = Path.GetDirectoryName(exec);
return $"{dir}\\BComp.exe";
}
private static string FindWinMerge() {
var root = RegistryKey.OpenBaseKey(
RegistryHive.CurrentUser,
Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32);
var merge = root.OpenSubKey(@"SOFTWARE\Thingamahoochie\WinMerge");
if (merge == null) return "";
var exec = merge.GetValue("Executable") as string;
return exec;
}
}
}

View file

@ -200,6 +200,7 @@ namespace SourceGit.Views.Widgets {
var cmd = new Commands.Command();
cmd.Cwd = repo.Path;
cmd.DontRaiseError = true;
cmd.Args = $"-c mergetool.sourcegit.cmd=\"\\\"{mergeExe}\\\" {merger.Cmd}\" ";
cmd.Args += "-c mergetool.writeToTemp=true -c mergetool.keepBackup=false -c mergetool.trustExitCode=true ";
cmd.Args += $"mergetool --tool=sourcegit {change.Path}";