mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 12:45:00 +00:00
refactor: external diff merge tool - supports to use difftool/mergetool settings from git config directly (#181)
This commit is contained in:
parent
06245320a9
commit
c56d0cf85e
15 changed files with 89 additions and 163 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue