mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-02 09:35:00 +00:00

- rename c-style `file_arg` to `fileArg` - add missing translations for zh_CN and zh_TW - re-design conflict view and add tooltip for `USE THEIRS` and `USE MINE` - re-order unstaged toolbar buttons Signed-off-by: leo <longshuang@msn.cn>
72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using System.IO;
|
|
|
|
using Avalonia.Threading;
|
|
|
|
namespace SourceGit.Commands
|
|
{
|
|
public static class MergeTool
|
|
{
|
|
public static bool OpenForMerge(string repo, int toolType, string toolPath, string file)
|
|
{
|
|
var cmd = new Command();
|
|
cmd.WorkingDirectory = repo;
|
|
cmd.Context = repo;
|
|
cmd.RaiseError = true;
|
|
|
|
// NOTE: If no <file> names are specified, 'git mergetool' will run the merge tool program on every file with merge conflicts.
|
|
var fileArg = string.IsNullOrEmpty(file) ? "" : $"\"{file}\"";
|
|
|
|
if (toolType == 0)
|
|
{
|
|
cmd.Args = $"mergetool {fileArg}";
|
|
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 {fileArg}";
|
|
return cmd.Exec();
|
|
}
|
|
|
|
public static bool OpenForDiff(string repo, int toolType, string toolPath, Models.DiffOption option)
|
|
{
|
|
var cmd = new Command();
|
|
cmd.WorkingDirectory = repo;
|
|
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();
|
|
}
|
|
}
|
|
}
|