refactor: commandline parsing

* `--rebase-todo-editor` launches this app as a git `sequence.editor`
* `--rebase-message-editor` launches this app as a git `core.editor` which runs on background by reading rebasing jobs
* `--core-editor` launches this app as a git `core.editor`
* `--askpass` launches this app as a SSH askpass program
This commit is contained in:
leo 2024-07-09 10:16:15 +08:00
parent cbe4c36525
commit 6930b51c64
No known key found for this signature in database
14 changed files with 320 additions and 155 deletions

View file

@ -1,5 +1,4 @@
using System.Diagnostics;
using System.IO;
using System.IO;
namespace SourceGit.ViewModels
{
@ -39,7 +38,8 @@ namespace SourceGit.ViewModels
{
WorkingDirectory = Repository,
Context = Repository,
Args = $"-c core.editor=true {Cmd} --continue",
Editor = Commands.Command.EditorType.None,
Args = $"{Cmd} --continue",
}.Exec();
}
}
@ -58,14 +58,12 @@ namespace SourceGit.ViewModels
public override bool Continue()
{
var exec = Process.GetCurrentProcess().MainModule.FileName;
var editor = $"\\\"{exec}\\\" --rebase-editor";
var succ = new Commands.Command()
{
WorkingDirectory = Repository,
Context = Repository,
Args = $"-c core.editor=\"{editor}\" rebase --continue",
Editor = Commands.Command.EditorType.RebaseEditor,
Args = $"rebase --continue",
}.Exec();
if (succ)

View file

@ -168,18 +168,18 @@ namespace SourceGit.ViewModels
_repo.SetWatcherEnabled(false);
var saveFile = Path.Combine(_repo.GitDir, "sourcegit_rebase_jobs.json");
var jobs = new List<Models.InteractiveRebaseJob>();
var collection = new Models.InteractiveRebaseJobCollection();
for (int i = Items.Count - 1; i >= 0; i--)
{
var item = Items[i];
jobs.Add(new Models.InteractiveRebaseJob()
collection.Jobs.Add(new Models.InteractiveRebaseJob()
{
SHA = item.Commit.SHA,
Action = item.Action,
Message = item.FullMessage,
});
}
File.WriteAllText(saveFile, JsonSerializer.Serialize(jobs, JsonCodeGen.Default.ListInteractiveRebaseJob));
File.WriteAllText(saveFile, JsonSerializer.Serialize(collection, JsonCodeGen.Default.InteractiveRebaseJobCollection));
return Task.Run(() =>
{

View file

@ -28,21 +28,20 @@ namespace SourceGit.ViewModels
}
}
public Launcher(string[] commandlines)
public Launcher(string startupRepo)
{
Pages = new AvaloniaList<LauncherPage>();
AddNewTab();
if (commandlines.Length == 2)
if (!string.IsNullOrEmpty(startupRepo))
{
var path = commandlines[1];
var root = new Commands.QueryRepositoryRootPath(path).Result();
var root = new Commands.QueryRepositoryRootPath(startupRepo).Result();
if (string.IsNullOrEmpty(root))
{
Pages[0].Notifications.Add(new Notification
{
IsError = true,
Message = $"Given path: '{path}' is NOT a valid repository!"
Message = $"Given path: '{startupRepo}' is NOT a valid repository!"
});
return;
}