diff --git a/src/Commands/MergeTool.cs b/src/Commands/MergeTool.cs index 75b88bc9..d3478d59 100644 --- a/src/Commands/MergeTool.cs +++ b/src/Commands/MergeTool.cs @@ -6,57 +6,63 @@ namespace SourceGit.Commands { public static class MergeTool { - public static bool OpenForMerge(string repo, string tool, string mergeCmd, string file) + public static bool OpenForMerge(string repo, int toolType, string toolPath, string file) { - if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(mergeCmd)) - { - Dispatcher.UIThread.Invoke(() => - { - App.RaiseException(repo, "Invalid external merge tool settings!"); - }); - return false; - } - - if (!File.Exists(tool)) - { - Dispatcher.UIThread.Invoke(() => - { - App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!"); - }); - return false; - } - var cmd = new Command(); cmd.WorkingDirectory = repo; - cmd.RaiseError = false; - cmd.Args = $"-c mergetool.sourcegit.cmd=\"\\\"{tool}\\\" {mergeCmd}\" -c mergetool.writeToTemp=true -c mergetool.keepBackup=false -c mergetool.trustExitCode=true mergetool --tool=sourcegit \"{file}\""; + cmd.Context = repo; + cmd.RaiseError = true; + + if (toolType == 0) + { + cmd.Args = $"mergetool \"{file}\""; + return cmd.Exec(); + } + + if (!File.Exists(toolPath)) + { + Dispatcher.UIThread.Post(() => App.RaiseException(repo, $"Can NOT found external merge tool in '{toolPath}'!")); + return false; + } + + var supported = Models.ExternalMerger.Supported.Find(x => x.Type == toolType); + if (supported == null) + { + Dispatcher.UIThread.Post(() => App.RaiseException(repo, "Invalid merge tool in preference setting!")); + return false; + } + + cmd.Args = $"-c mergetool.sourcegit.cmd=\"\\\"{toolPath}\\\" {supported.Cmd}\" -c mergetool.writeToTemp=true -c mergetool.keepBackup=false -c mergetool.trustExitCode=true mergetool --tool=sourcegit \"{file}\""; return cmd.Exec(); } - public static bool OpenForDiff(string repo, string tool, string diffCmd, Models.DiffOption option) + public static bool OpenForDiff(string repo, int toolType, string toolPath, Models.DiffOption option) { - if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(diffCmd)) - { - Dispatcher.UIThread.Invoke(() => - { - App.RaiseException(repo, "Invalid external merge tool settings!"); - }); - return false; - } - - if (!File.Exists(tool)) - { - Dispatcher.UIThread.Invoke(() => - { - App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!"); - }); - return false; - } - var cmd = new Command(); cmd.WorkingDirectory = repo; - cmd.RaiseError = false; - cmd.Args = $"-c difftool.sourcegit.cmd=\"\\\"{tool}\\\" {diffCmd}\" difftool --tool=sourcegit --no-prompt {option}"; + cmd.Context = repo; + cmd.RaiseError = true; + + if (toolType == 0) + { + cmd.Args = $"difftool -g --no-prompt {option}"; + return cmd.Exec(); + } + + if (!File.Exists(toolPath)) + { + Dispatcher.UIThread.Invoke(() => App.RaiseException(repo, $"Can NOT found external diff tool in '{toolPath}'!")); + return false; + } + + var supported = Models.ExternalMerger.Supported.Find(x => x.Type == toolType); + if (supported == null) + { + Dispatcher.UIThread.Post(() => App.RaiseException(repo, "Invalid merge tool in preference setting!")); + return false; + } + + cmd.Args = $"-c difftool.sourcegit.cmd=\"\\\"{toolPath}\\\" {supported.DiffCmd}\" difftool --tool=sourcegit --no-prompt {option}"; return cmd.Exec(); } } diff --git a/src/Models/ExternalMerger.cs b/src/Models/ExternalMerger.cs index d61ce055..3130408e 100644 --- a/src/Models/ExternalMerger.cs +++ b/src/Models/ExternalMerger.cs @@ -32,7 +32,7 @@ namespace SourceGit.Models if (OperatingSystem.IsWindows()) { Supported = new List() { - new ExternalMerger(0, "custom_diff", "Custom", "", "", ""), + new ExternalMerger(0, "git", "Use Git Settings", "", "", ""), new ExternalMerger(1, "vscode", "Visual Studio Code", "Code.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), new ExternalMerger(2, "vscode_insiders", "Visual Studio Code - Insiders", "Code - Insiders.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), new ExternalMerger(3, "vs", "Visual Studio", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" /m", "\"$LOCAL\" \"$REMOTE\""), @@ -46,7 +46,7 @@ namespace SourceGit.Models else if (OperatingSystem.IsMacOS()) { Supported = new List() { - new ExternalMerger(0, "custom_diff", "Custom", "", "", ""), + new ExternalMerger(0, "git", "Use Git Settings", "", "", ""), new ExternalMerger(1, "xcode", "FileMerge", "/usr/bin/opendiff", "\"$BASE\" \"$LOCAL\" \"$REMOTE\" -ancestor \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), new ExternalMerger(2, "vscode", "Visual Studio Code", "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), new ExternalMerger(3, "vscode_insiders", "Visual Studio Code - Insiders", "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), @@ -58,7 +58,7 @@ namespace SourceGit.Models else if (OperatingSystem.IsLinux()) { Supported = new List() { - new ExternalMerger(0, "custom_diff", "Custom", "", "", ""), + new ExternalMerger(0, "git", "Use Git Settings", "", "", ""), new ExternalMerger(1, "vscode", "Visual Studio Code", "/usr/share/code/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), new ExternalMerger(2, "vscode_insiders", "Visual Studio Code - Insiders", "/usr/share/code-insiders/code-insiders", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), new ExternalMerger(3, "kdiff3", "KDiff3", "/usr/bin/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), @@ -70,7 +70,7 @@ namespace SourceGit.Models else { Supported = new List() { - new ExternalMerger(0, "custom_diff", "Custom", "", "", ""), + new ExternalMerger(0, "git", "Use Git Settings", "", "", ""), }; } } diff --git a/src/Resources/ExternalToolIcons/custom_diff.png b/src/Resources/ExternalToolIcons/custom_diff.png deleted file mode 100644 index 8d046a2f..00000000 Binary files a/src/Resources/ExternalToolIcons/custom_diff.png and /dev/null differ diff --git a/src/Resources/ExternalToolIcons/git.png b/src/Resources/ExternalToolIcons/git.png new file mode 100644 index 00000000..cbb908b9 Binary files /dev/null and b/src/Resources/ExternalToolIcons/git.png differ diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 28afdf9c..25b50e63 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -339,12 +339,10 @@ Input path for installed gpg program User Signing Key User's gpg signing key - EXTERNAL MERGE TOOL - Diff Command - Merge Command - Install Path - Input path for merge tool - Merger + DIFF/MERGE TOOL + Install Path + Input path for diff/merge tool + Tool Prune Remote Target: Pull diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index b1658c34..c2c69099 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -342,12 +342,10 @@ 签名程序所在路径 用户签名KEY 输入签名提交所使用的KEY - 外部合并工具 - 对比模式启动参数 - 合并模式启动参数 - 安装路径 - 填写工具可执行文件所在位置 - 工具 + 对比/合并工具 + 安装路径 + 填写工具可执行文件所在位置 + 工具 清理远程已删除分支 目标 : 拉回(pull) diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 7a8bd837..8cd3c88b 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -342,12 +342,10 @@ gpg.exe所在路徑 使用者簽名KEY 輸入簽名提交所使用的KEY - 外部合併工具 - 對比模式啟動引數 - 合併模式啟動引數 - 安裝路徑 - 填寫工具可執行檔案所在位置 - 工具 + 對比/合併工具 + 安裝路徑 + 填寫工具可執行檔案所在位置 + 工具 清理遠端已刪除分支 目標 : 拉回(pull) diff --git a/src/ViewModels/BranchCompare.cs b/src/ViewModels/BranchCompare.cs index 6b19d249..be133bd2 100644 --- a/src/ViewModels/BranchCompare.cs +++ b/src/ViewModels/BranchCompare.cs @@ -133,19 +133,11 @@ namespace SourceGit.ViewModels diffWithMerger.Icon = App.CreateMenuIcon("Icons.Diff"); diffWithMerger.Click += (_, ev) => { + var toolType = Preference.Instance.ExternalMergeToolType; + var toolPath = Preference.Instance.ExternalMergeToolPath; var opt = new Models.DiffOption(Base.Head, To.Head, change); - var type = Preference.Instance.ExternalMergeToolType; - var exec = Preference.Instance.ExternalMergeToolPath; - var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); - if (tool == null || !File.Exists(exec)) - { - App.RaiseException(_repo, "Invalid merge tool in preference setting!"); - return; - } - - var args = tool.Type != 0 ? tool.DiffCmd : Preference.Instance.ExternalMergeToolDiffCmd; - Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, exec, args, opt)); + Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, toolType, toolPath, opt)); ev.Handled = true; }; menu.Items.Add(diffWithMerger); diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index 430f4b7d..4ab521b8 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -218,19 +218,11 @@ namespace SourceGit.ViewModels diffWithMerger.Icon = App.CreateMenuIcon("Icons.Diff"); diffWithMerger.Click += (_, ev) => { + var toolType = Preference.Instance.ExternalMergeToolType; + var toolPath = Preference.Instance.ExternalMergeToolPath; var opt = new Models.DiffOption(_commit, change); - var type = Preference.Instance.ExternalMergeToolType; - var exec = Preference.Instance.ExternalMergeToolPath; - var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); - if (tool == null || !File.Exists(exec)) - { - App.RaiseException(_repo, "Invalid merge tool in preference setting!"); - return; - } - - var args = tool.Type != 0 ? tool.DiffCmd : Preference.Instance.ExternalMergeToolDiffCmd; - Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, exec, args, opt)); + Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, toolType, toolPath, opt)); ev.Handled = true; }; menu.Items.Add(diffWithMerger); diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 53f6839c..8a240752 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -98,18 +98,9 @@ namespace SourceGit.ViewModels public void OpenExternalMergeTool() { - var type = Preference.Instance.ExternalMergeToolType; - var exec = Preference.Instance.ExternalMergeToolPath; - - var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); - if (tool == null || !File.Exists(exec)) - { - App.RaiseException(_repo, "Invalid merge tool in preference setting!"); - return; - } - - var args = tool.Type != 0 ? tool.DiffCmd : Preference.Instance.ExternalMergeToolDiffCmd; - Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, exec, args, _option)); + var toolType = Preference.Instance.ExternalMergeToolType; + var toolPath = Preference.Instance.ExternalMergeToolPath; + Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, toolType, toolPath, _option)); } private void LoadDiffContent() diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index debe672a..b72fb8c4 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -290,18 +290,6 @@ namespace SourceGit.ViewModels set => SetProperty(ref _externalMergeToolPath, value); } - public string ExternalMergeToolCmd - { - get => _externalMergeToolCmd; - set => SetProperty(ref _externalMergeToolCmd, value); - } - - public string ExternalMergeToolDiffCmd - { - get => _externalMergeToolDiffCmd; - set => SetProperty(ref _externalMergeToolDiffCmd, value); - } - public List Repositories { get; @@ -556,8 +544,6 @@ namespace SourceGit.ViewModels private int _externalMergeToolType = 0; private string _externalMergeToolPath = string.Empty; - private string _externalMergeToolCmd = string.Empty; - private string _externalMergeToolDiffCmd = string.Empty; private AvaloniaList _repositoryNodes = new AvaloniaList(); } diff --git a/src/ViewModels/RevisionCompare.cs b/src/ViewModels/RevisionCompare.cs index 99fae39f..80a06757 100644 --- a/src/ViewModels/RevisionCompare.cs +++ b/src/ViewModels/RevisionCompare.cs @@ -142,18 +142,10 @@ namespace SourceGit.ViewModels diffWithMerger.Click += (_, ev) => { var opt = new Models.DiffOption(StartPoint.SHA, _endPoint, change); - var type = Preference.Instance.ExternalMergeToolType; - var exec = Preference.Instance.ExternalMergeToolPath; + var toolType = Preference.Instance.ExternalMergeToolType; + var toolPath = Preference.Instance.ExternalMergeToolPath; - var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); - if (tool == null || !File.Exists(exec)) - { - App.RaiseException(_repo, "Invalid merge tool in preference setting!"); - return; - } - - var args = tool.Type != 0 ? tool.DiffCmd : Preference.Instance.ExternalMergeToolDiffCmd; - Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, exec, args, opt)); + Task.Run(() => Commands.MergeTool.OpenForDiff(_repo, toolType, toolPath, opt)); ev.Handled = true; }; menu.Items.Add(diffWithMerger); diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index a0b406cb..434923f2 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -1120,20 +1120,11 @@ namespace SourceGit.ViewModels private async void UseExternalMergeTool(Models.Change change) { - var type = Preference.Instance.ExternalMergeToolType; - var exec = Preference.Instance.ExternalMergeToolPath; - - var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); - if (tool == null) - { - App.RaiseException(_repo.FullPath, "Invalid merge tool in preference setting!"); - return; - } - - var args = tool.Type != 0 ? tool.Cmd : Preference.Instance.ExternalMergeToolCmd; + var toolType = Preference.Instance.ExternalMergeToolType; + var toolPath = Preference.Instance.ExternalMergeToolPath; _repo.SetWatcherEnabled(false); - await Task.Run(() => Commands.MergeTool.OpenForMerge(_repo.FullPath, exec, args, change.Path)); + await Task.Run(() => Commands.MergeTool.OpenForMerge(_repo.FullPath, toolType, toolPath, change.Path)); _repo.SetWatcherEnabled(true); } diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index d502e818..b84354aa 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -449,12 +449,12 @@ - + - + + Margin="0,0,16,0" + IsVisible="{Binding ExternalMergeToolType, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"/> + Text="{Binding ExternalMergeToolPath, Mode=TwoWay}" + Watermark="{DynamicResource Text.Preference.DiffMerge.Path.Placeholder}" + IsVisible="{Binding ExternalMergeToolType, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"> - - - - - - diff --git a/src/Views/Preference.axaml.cs b/src/Views/Preference.axaml.cs index cccbd522..2cb9dca4 100644 --- a/src/Views/Preference.axaml.cs +++ b/src/Views/Preference.axaml.cs @@ -287,6 +287,7 @@ namespace SourceGit.Views { ViewModels.Preference.Instance.ExternalMergeToolType = 0; type = 0; + return; } var tool = Models.ExternalMerger.Supported[type];