diff --git a/src/Models/MergeTool.cs b/src/Models/MergeTool.cs index 5108cb93..dc0817ce 100644 --- a/src/Models/MergeTool.cs +++ b/src/Models/MergeTool.cs @@ -13,23 +13,25 @@ namespace SourceGit.Models { public string Name { get; set; } public string Exec { get; set; } public string Cmd { get; set; } + public string DiffCmd { get; set; } public Func Finder { get; set; } public static List Supported = new List() { - new MergeTool(0, "--", "", "", () => ""), - new MergeTool(1, "Visual Studio Code", "Code.exe", "-n --wait \"$MERGED\"", FindVSCode), - new MergeTool(2, "Visual Studio 2017/2019", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" //m", FindVSMerge), - 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), + new MergeTool(0, "--", "", "", "", () => ""), + new MergeTool(1, "Visual Studio Code", "Code.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\"", FindVSCode), + new MergeTool(2, "Visual Studio 2017/2019", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" /m", "\"$LOCAL\" \"$REMOTE\"", FindVSMerge), + new MergeTool(3, "Tortoise Merge", "TortoiseMerge.exe", "-base:\"$BASE\" -theirs:\"$REMOTE\" -mine:\"$LOCAL\" -merged:\"$MERGED\"", "-base:\"$LOCAL\" -theirs:\"$REMOTE\"", FindTortoiseMerge), + new MergeTool(4, "KDiff3", "kdiff3.exe", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\"", FindKDiff3), + new MergeTool(5, "Beyond Compare 4", "BComp.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\"", FindBCompare), + new MergeTool(6, "WinMerge", "WinMergeU.exe", "-u -e \"$REMOTE\" \"$LOCAL\" \"$MERGED\"", "-u -e \"$LOCAL\" \"$REMOTE\"", FindWinMerge), }; - public MergeTool(int type, string name, string exec, string cmd, Func finder) { + public MergeTool(int type, string name, string exec, string cmd, string diffCmd, Func finder) { Type = type; Name = name; Exec = exec; Cmd = cmd; + DiffCmd = diffCmd; Finder = finder; } diff --git a/src/Resources/Icons.xaml b/src/Resources/Icons.xaml index c74b5ecc..1149947b 100644 --- a/src/Resources/Icons.xaml +++ b/src/Resources/Icons.xaml @@ -42,6 +42,7 @@ M832 960l192-512H192L0 960zM128 384L0 960V128h288l128 128h416v128z M959 320H960v640A64 64 0 01896 1024H192A64 64 0 01128 960V64A64 64 0 01192 0H640v321h320L959 320zM320 544c0 17 14 32 32 32h384A32 32 0 00768 544c0-17-14-32-32-32H352A32 32 0 00320 544zm0 128c0 17 14 32 32 32h384a32 32 0 0032-32c0-17-14-32-32-32H352a32 32 0 00-32 32zm0 128c0 17 14 32 32 32h384a32 32 0 0032-32c0-17-14-32-32-32H352a32 32 0 00-32 32z M854 307 611 73c-6-6-14-9-22-9H296c-4 0-8 4-8 8v56c0 4 4 8 8 8h277l219 211V824c0 4 4 8 8 8h56c4 0 8-4 8-8V330c0-9-4-17-10-23zM553 201c-6-6-14-9-23-9H192c-18 0-32 14-32 32v704c0 18 14 32 32 32h512c18 0 32-14 32-32V397c0-9-3-17-9-23L553 201zM568 753c0 4-3 7-8 7h-225c-4 0-8-3-8-7v-42c0-4 3-7 8-7h225c4 0 8 3 8 7v42zm0-220c0 4-3 7-8 7H476v85c0 4-3 7-7 7h-42c-4 0-7-3-7-7V540h-85c-4 0-8-3-8-7v-42c0-4 3-7 8-7H420v-85c0-4 3-7 7-7h42c4 0 7 3 7 7V484h85c4 0 8 3 8 7v42z + M683 409v204L1024 308 683 0v191c-413 0-427 526-427 526c117-229 203-307 427-307zm85 492H102V327h153s38-63 114-122H51c-28 0-51 27-51 61v697c0 34 23 61 51 61h768c28 0 51-27 51-61V614l-102 100v187z M599 425 599 657 425 832 425 425 192 192 832 192Z M71 1024V0h661L953 219V1024H71zm808-731-220-219H145V951h735V293zM439 512h-220V219h220V512zm-74-219H292v146h74v-146zm0 512h74v73h-220v-73H292v-146H218V585h147v219zm294-366h74V512H512v-73h74v-146H512V219h147v219zm74 439H512V585h220v293zm-74-219h-74v146h74v-146z diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml index 05eae298..d1365c13 100644 --- a/src/Resources/Locales/en_US.xaml +++ b/src/Resources/Locales/en_US.xaml @@ -228,6 +228,7 @@ Next Difference Previous Difference Toggle One-Side/Two-Sides + Open With Merge Tool SELECT FILE TO VIEW CHANGES NO CHANGES OR ONLY EOL CHANGES BINARY DIFF diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml index fe7e8b2a..5f08e071 100644 --- a/src/Resources/Locales/zh_CN.xaml +++ b/src/Resources/Locales/zh_CN.xaml @@ -228,6 +228,7 @@ 下一个差异 上一个差异 切换显示模式 + 使用外部合并工具查看 请选择需要对比的文件 没有变更或仅有换行符差异 二进制文件 diff --git a/src/Views/Widgets/DiffViewer.xaml b/src/Views/Widgets/DiffViewer.xaml index a506d54b..e7d29936 100644 --- a/src/Views/Widgets/DiffViewer.xaml +++ b/src/Views/Widgets/DiffViewer.xaml @@ -58,12 +58,19 @@ + + diff --git a/src/Views/Widgets/DiffViewer.xaml.cs b/src/Views/Widgets/DiffViewer.xaml.cs index 1f27e00c..984180c4 100644 --- a/src/Views/Widgets/DiffViewer.xaml.cs +++ b/src/Views/Widgets/DiffViewer.xaml.cs @@ -668,6 +668,35 @@ namespace SourceGit.Views.Widgets { } } } + + private async void OpenWithMerger(object sender, RoutedEventArgs e) { + var mergeType = Models.Preference.Instance.MergeTool.Type; + var mergeExe = Models.Preference.Instance.MergeTool.Path; + + var merger = Models.MergeTool.Supported.Find(x => x.Type == mergeType); + if (merger == null || merger.Type == 0 || !System.IO.File.Exists(mergeExe)) { + Models.Exception.Raise("Invalid merge tool in preference setting!"); + return; + } + + var args = $"{opt.ExtraArgs} "; + if (opt.RevisionRange.Length > 0) args += $"{opt.RevisionRange[0]} "; + if (opt.RevisionRange.Length > 1) args += $"{opt.RevisionRange[1]} "; + + args += "-- "; + + if (!string.IsNullOrEmpty(opt.OrgPath)) args += $"\"{opt.OrgPath}\" "; + args += $"\"{opt.Path}\""; + + var cmd = new Commands.Command(); + cmd.Cwd = repo; + cmd.DontRaiseError = true; + cmd.Args = $"-c difftool.sourcegit.cmd=\"\\\"{mergeExe}\\\" {merger.DiffCmd}\" "; + cmd.Args += $"difftool --tool=sourcegit --no-prompt {args}"; + + await Task.Run(() => cmd.Exec()); + e.Handled = true; + } #endregion } }