2024-06-20 02:02:12 -07:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2024-04-01 06:27:08 -07:00
|
|
|
|
|
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public abstract class InProgressContext
|
|
|
|
|
{
|
|
|
|
|
public string Repository
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Cmd
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InProgressContext(string repo, string cmd)
|
|
|
|
|
{
|
|
|
|
|
Repository = repo;
|
|
|
|
|
Cmd = cmd;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 18:30:37 -07:00
|
|
|
|
public bool Abort()
|
2024-04-01 06:27:08 -07:00
|
|
|
|
{
|
2024-04-28 18:30:37 -07:00
|
|
|
|
return new Commands.Command()
|
2024-04-01 06:27:08 -07:00
|
|
|
|
{
|
|
|
|
|
WorkingDirectory = Repository,
|
|
|
|
|
Context = Repository,
|
|
|
|
|
Args = $"{Cmd} --abort",
|
|
|
|
|
}.Exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool Continue()
|
|
|
|
|
{
|
|
|
|
|
return new Commands.Command()
|
|
|
|
|
{
|
|
|
|
|
WorkingDirectory = Repository,
|
|
|
|
|
Context = Repository,
|
|
|
|
|
Args = $"-c core.editor=true {Cmd} --continue",
|
|
|
|
|
}.Exec();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CherryPickInProgress : InProgressContext
|
|
|
|
|
{
|
|
|
|
|
public CherryPickInProgress(string repo) : base(repo, "cherry-pick") { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RebaseInProgress : InProgressContext
|
|
|
|
|
{
|
|
|
|
|
public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase")
|
|
|
|
|
{
|
|
|
|
|
_gitDir = repo.GitDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Continue()
|
|
|
|
|
{
|
2024-06-20 02:02:12 -07:00
|
|
|
|
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",
|
|
|
|
|
}.Exec();
|
|
|
|
|
|
2024-04-01 06:27:08 -07:00
|
|
|
|
if (succ)
|
|
|
|
|
{
|
2024-06-20 02:02:12 -07:00
|
|
|
|
var jobsFile = Path.Combine(_gitDir, "sourcegit_rebase_jobs.json");
|
2024-04-01 06:27:08 -07:00
|
|
|
|
var rebaseMergeHead = Path.Combine(_gitDir, "REBASE_HEAD");
|
|
|
|
|
var rebaseMergeFolder = Path.Combine(_gitDir, "rebase-merge");
|
|
|
|
|
var rebaseApplyFolder = Path.Combine(_gitDir, "rebase-apply");
|
2024-06-20 02:02:12 -07:00
|
|
|
|
if (File.Exists(jobsFile))
|
|
|
|
|
File.Delete(jobsFile);
|
2024-04-01 06:27:08 -07:00
|
|
|
|
if (File.Exists(rebaseMergeHead))
|
|
|
|
|
File.Delete(rebaseMergeHead);
|
|
|
|
|
if (Directory.Exists(rebaseMergeFolder))
|
|
|
|
|
Directory.Delete(rebaseMergeFolder);
|
|
|
|
|
if (Directory.Exists(rebaseApplyFolder))
|
|
|
|
|
Directory.Delete(rebaseApplyFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return succ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _gitDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RevertInProgress : InProgressContext
|
|
|
|
|
{
|
|
|
|
|
public RevertInProgress(string repo) : base(repo, "revert") { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MergeInProgress : InProgressContext
|
|
|
|
|
{
|
|
|
|
|
public MergeInProgress(string repo) : base(repo, "merge") { }
|
|
|
|
|
}
|
|
|
|
|
}
|