2024-03-17 18:37:06 -07:00
|
|
|
|
using System.IO;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public static class MergeTool
|
|
|
|
|
{
|
2024-06-17 21:10:38 -07:00
|
|
|
|
public static bool OpenForMerge(string repo, int toolType, string toolPath, string file)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-06-17 21:10:38 -07:00
|
|
|
|
var cmd = new Command();
|
|
|
|
|
cmd.WorkingDirectory = repo;
|
|
|
|
|
cmd.Context = repo;
|
|
|
|
|
cmd.RaiseError = true;
|
|
|
|
|
|
|
|
|
|
if (toolType == 0)
|
|
|
|
|
{
|
|
|
|
|
cmd.Args = $"mergetool \"{file}\"";
|
|
|
|
|
return cmd.Exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(toolPath))
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-06-17 21:10:38 -07:00
|
|
|
|
Dispatcher.UIThread.Post(() => App.RaiseException(repo, $"Can NOT found external merge tool in '{toolPath}'!"));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 21:10:38 -07:00
|
|
|
|
var supported = Models.ExternalMerger.Supported.Find(x => x.Type == toolType);
|
|
|
|
|
if (supported == null)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-06-17 21:10:38 -07:00
|
|
|
|
Dispatcher.UIThread.Post(() => App.RaiseException(repo, "Invalid merge tool in preference setting!"));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 21:10:38 -07:00
|
|
|
|
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}\"";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return cmd.Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 21:10:38 -07:00
|
|
|
|
public static bool OpenForDiff(string repo, int toolType, string toolPath, Models.DiffOption option)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-06-17 21:10:38 -07:00
|
|
|
|
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))
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-06-17 21:10:38 -07:00
|
|
|
|
Dispatcher.UIThread.Invoke(() => App.RaiseException(repo, $"Can NOT found external diff tool in '{toolPath}'!"));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 21:10:38 -07:00
|
|
|
|
var supported = Models.ExternalMerger.Supported.Find(x => x.Type == toolType);
|
|
|
|
|
if (supported == null)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-06-17 21:10:38 -07:00
|
|
|
|
Dispatcher.UIThread.Post(() => App.RaiseException(repo, "Invalid merge tool in preference setting!"));
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 21:10:38 -07:00
|
|
|
|
cmd.Args = $"-c difftool.sourcegit.cmd=\"\\\"{toolPath}\\\" {supported.DiffCmd}\" difftool --tool=sourcegit --no-prompt {option}";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return cmd.Exec();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|