diff --git a/src/ViewModels/InProgressContexts.cs b/src/ViewModels/InProgressContexts.cs index ba095fb5..78f845f3 100644 --- a/src/ViewModels/InProgressContexts.cs +++ b/src/ViewModels/InProgressContexts.cs @@ -4,51 +4,29 @@ namespace SourceGit.ViewModels { public abstract class InProgressContext { - public string Repository + public InProgressContext(string repo, string cmd) { - get; - set; - } - - public string Cmd - { - get; - set; - } - - public bool CanSkip - { - get; - protected set; - } - - public InProgressContext(string repo, string cmd, bool canSkip) - { - Repository = repo; - Cmd = cmd; - CanSkip = canSkip; + _repo = repo; + _cmd = cmd; } public bool Abort() { return new Commands.Command() { - WorkingDirectory = Repository, - Context = Repository, - Args = $"{Cmd} --abort", + WorkingDirectory = _repo, + Context = _repo, + Args = $"{_cmd} --abort", }.Exec(); } - public bool Skip() + public virtual bool Skip() { - if (!CanSkip) - return true; - return new Commands.Command() { - WorkingDirectory = Repository, - Context = Repository, - Args = $"{Cmd} --skip", + WorkingDirectory = _repo, + Context = _repo, + Args = $"{_cmd} --skip", }.Exec(); } @@ -56,10 +34,10 @@ namespace SourceGit.ViewModels { return new Commands.Command() { - WorkingDirectory = Repository, - Context = Repository, + WorkingDirectory = _repo, + Context = _repo, Editor = Commands.Command.EditorType.None, - Args = $"{Cmd} --continue", + Args = $"{_cmd} --continue", }.Exec(); } @@ -75,6 +53,9 @@ namespace SourceGit.ViewModels return commit.SHA.Substring(0, 10); } + + protected string _repo = string.Empty; + protected string _cmd = string.Empty; } public class CherryPickInProgress : InProgressContext @@ -90,7 +71,7 @@ namespace SourceGit.ViewModels get => GetFriendlyNameOfCommit(Head); } - public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick", true) + public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick") { var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "CHERRY_PICK_HEAD")).Trim(); Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA }; @@ -122,7 +103,7 @@ namespace SourceGit.ViewModels private set; } - public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase", true) + public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase") { _gitDir = repo.GitDir; @@ -141,8 +122,8 @@ namespace SourceGit.ViewModels { var succ = new Commands.Command() { - WorkingDirectory = Repository, - Context = Repository, + WorkingDirectory = _repo, + Context = _repo, Editor = Commands.Command.EditorType.RebaseEditor, Args = $"rebase --continue", }.Exec(); @@ -177,7 +158,7 @@ namespace SourceGit.ViewModels private set; } - public RevertInProgress(Repository repo) : base(repo.FullPath, "revert", false) + public RevertInProgress(Repository repo) : base(repo.FullPath, "revert") { var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "REVERT_HEAD")).Trim(); Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA }; @@ -203,12 +184,17 @@ namespace SourceGit.ViewModels get => GetFriendlyNameOfCommit(Source); } - public MergeInProgress(Repository repo) : base(repo.FullPath, "merge", false) + public MergeInProgress(Repository repo) : base(repo.FullPath, "merge") { Current = Commands.Branch.ShowCurrent(repo.FullPath); var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim(); Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result() ?? new Models.Commit() { SHA = sourceSHA }; } + + public override bool Skip() + { + return true; + } } } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index f298bc3e..d8d6806c 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -764,6 +764,11 @@ namespace SourceGit.ViewModels _workingCopy?.StashAll(autoStart); } + public void SkipMerge() + { + _workingCopy?.SkipMerge(); + } + public void AbortMerge() { _workingCopy?.AbortMerge(); diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index d748b7ef..bf788bb0 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -491,6 +491,29 @@ namespace SourceGit.ViewModels } } + public void SkipMerge() + { + if (_inProgressContext != null) + { + _repo.SetWatcherEnabled(false); + Task.Run(() => + { + var succ = _inProgressContext.Skip(); + Dispatcher.UIThread.Invoke(() => + { + if (succ) + CommitMessage = string.Empty; + + _repo.SetWatcherEnabled(true); + }); + }); + } + else + { + _repo.MarkWorkingCopyDirtyManually(); + } + } + public void AbortMerge() { if (_inProgressContext != null) diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 24b58fa2..6d034130 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -546,8 +546,8 @@ BorderBrush="{DynamicResource Brush.Border0}"/> - - + + @@ -563,27 +563,39 @@ - - - - - + + + + + + + +