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
|
|
|
|
|
{
|
|
|
|
|
public static bool OpenForMerge(string repo, string tool, string mergeCmd, string file)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(mergeCmd))
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-25 19:29:57 -08:00
|
|
|
|
App.RaiseException(repo, "Invalid external merge tool settings!");
|
|
|
|
|
});
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (!File.Exists(tool))
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-25 19:29:57 -08:00
|
|
|
|
App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
});
|
2024-02-05 23:08:37 -08:00
|
|
|
|
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}\"";
|
|
|
|
|
return cmd.Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static bool OpenForDiff(string repo, string tool, string diffCmd, Models.DiffOption option)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(tool) || string.IsNullOrWhiteSpace(diffCmd))
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-25 19:29:57 -08:00
|
|
|
|
App.RaiseException(repo, "Invalid external merge tool settings!");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
});
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (!File.Exists(tool))
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
|
|
{
|
2024-02-25 19:29:57 -08:00
|
|
|
|
App.RaiseException(repo, $"Can NOT found external merge tool in '{tool}'!");
|
|
|
|
|
});
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cmd = new Command();
|
|
|
|
|
cmd.WorkingDirectory = repo;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
cmd.RaiseError = false;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
cmd.Args = $"-c difftool.sourcegit.cmd=\"\\\"{tool}\\\" {diffCmd}\" difftool --tool=sourcegit --no-prompt {option}";
|
|
|
|
|
return cmd.Exec();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|