Skip to content

Commit 0dd6692

Browse files
committed
enhance: supports --skip while reverting commits
1 parent dcaeaef commit 0dd6692

File tree

5 files changed

+94
-78
lines changed

5 files changed

+94
-78
lines changed

src/ViewModels/InProgressContexts.cs

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,40 @@ namespace SourceGit.ViewModels
44
{
55
public abstract class InProgressContext
66
{
7-
public string Repository
7+
public InProgressContext(string repo, string cmd)
88
{
9-
get;
10-
set;
11-
}
12-
13-
public string Cmd
14-
{
15-
get;
16-
set;
17-
}
18-
19-
public bool CanSkip
20-
{
21-
get;
22-
protected set;
23-
}
24-
25-
public InProgressContext(string repo, string cmd, bool canSkip)
26-
{
27-
Repository = repo;
28-
Cmd = cmd;
29-
CanSkip = canSkip;
9+
_repo = repo;
10+
_cmd = cmd;
3011
}
3112

3213
public bool Abort()
3314
{
3415
return new Commands.Command()
3516
{
36-
WorkingDirectory = Repository,
37-
Context = Repository,
38-
Args = $"{Cmd} --abort",
17+
WorkingDirectory = _repo,
18+
Context = _repo,
19+
Args = $"{_cmd} --abort",
3920
}.Exec();
4021
}
4122

42-
public bool Skip()
23+
public virtual bool Skip()
4324
{
44-
if (!CanSkip)
45-
return true;
46-
4725
return new Commands.Command()
4826
{
49-
WorkingDirectory = Repository,
50-
Context = Repository,
51-
Args = $"{Cmd} --skip",
27+
WorkingDirectory = _repo,
28+
Context = _repo,
29+
Args = $"{_cmd} --skip",
5230
}.Exec();
5331
}
5432

5533
public virtual bool Continue()
5634
{
5735
return new Commands.Command()
5836
{
59-
WorkingDirectory = Repository,
60-
Context = Repository,
37+
WorkingDirectory = _repo,
38+
Context = _repo,
6139
Editor = Commands.Command.EditorType.None,
62-
Args = $"{Cmd} --continue",
40+
Args = $"{_cmd} --continue",
6341
}.Exec();
6442
}
6543

@@ -75,6 +53,9 @@ protected string GetFriendlyNameOfCommit(Models.Commit commit)
7553

7654
return commit.SHA.Substring(0, 10);
7755
}
56+
57+
protected string _repo = string.Empty;
58+
protected string _cmd = string.Empty;
7859
}
7960

8061
public class CherryPickInProgress : InProgressContext
@@ -90,7 +71,7 @@ public string HeadName
9071
get => GetFriendlyNameOfCommit(Head);
9172
}
9273

93-
public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick", true)
74+
public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick")
9475
{
9576
var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "CHERRY_PICK_HEAD")).Trim();
9677
Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA };
@@ -122,7 +103,7 @@ public Models.Commit Onto
122103
private set;
123104
}
124105

125-
public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase", true)
106+
public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase")
126107
{
127108
_gitDir = repo.GitDir;
128109

@@ -141,8 +122,8 @@ public override bool Continue()
141122
{
142123
var succ = new Commands.Command()
143124
{
144-
WorkingDirectory = Repository,
145-
Context = Repository,
125+
WorkingDirectory = _repo,
126+
Context = _repo,
146127
Editor = Commands.Command.EditorType.RebaseEditor,
147128
Args = $"rebase --continue",
148129
}.Exec();
@@ -177,7 +158,7 @@ public Models.Commit Head
177158
private set;
178159
}
179160

180-
public RevertInProgress(Repository repo) : base(repo.FullPath, "revert", false)
161+
public RevertInProgress(Repository repo) : base(repo.FullPath, "revert")
181162
{
182163
var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "REVERT_HEAD")).Trim();
183164
Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA };
@@ -203,12 +184,17 @@ public string SourceName
203184
get => GetFriendlyNameOfCommit(Source);
204185
}
205186

206-
public MergeInProgress(Repository repo) : base(repo.FullPath, "merge", false)
187+
public MergeInProgress(Repository repo) : base(repo.FullPath, "merge")
207188
{
208189
Current = Commands.Branch.ShowCurrent(repo.FullPath);
209190

210191
var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim();
211192
Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result() ?? new Models.Commit() { SHA = sourceSHA };
212193
}
194+
195+
public override bool Skip()
196+
{
197+
return true;
198+
}
213199
}
214200
}

src/ViewModels/Repository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,11 @@ public void StashAll(bool autoStart)
764764
_workingCopy?.StashAll(autoStart);
765765
}
766766

767+
public void SkipMerge()
768+
{
769+
_workingCopy?.SkipMerge();
770+
}
771+
767772
public void AbortMerge()
768773
{
769774
_workingCopy?.AbortMerge();

src/ViewModels/WorkingCopy.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,29 @@ public void ContinueMerge()
491491
}
492492
}
493493

494+
public void SkipMerge()
495+
{
496+
if (_inProgressContext != null)
497+
{
498+
_repo.SetWatcherEnabled(false);
499+
Task.Run(() =>
500+
{
501+
var succ = _inProgressContext.Skip();
502+
Dispatcher.UIThread.Invoke(() =>
503+
{
504+
if (succ)
505+
CommitMessage = string.Empty;
506+
507+
_repo.SetWatcherEnabled(true);
508+
});
509+
});
510+
}
511+
else
512+
{
513+
_repo.MarkWorkingCopyDirtyManually();
514+
}
515+
}
516+
494517
public void AbortMerge()
495518
{
496519
if (_inProgressContext != null)

src/Views/Repository.axaml

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@
546546
BorderBrush="{DynamicResource Brush.Border0}"/>
547547

548548
<!-- Right -->
549-
<Grid Grid.Column="2" RowDefinitions="Auto,Auto,*">
550-
<Grid Grid.Row="0" Height="28" ColumnDefinitions="*,Auto,Auto" Background="{DynamicResource Brush.Conflict}" IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNotNull}}">
549+
<Grid Grid.Column="2" RowDefinitions="Auto,Auto,*">
550+
<Grid Grid.Row="0" Height="28" ColumnDefinitions="*,Auto" Background="{DynamicResource Brush.Conflict}" IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNotNull}}">
551551
<ContentControl Grid.Column="0" Margin="8,0" Content="{Binding InProgressContext}">
552552
<ContentControl.DataTemplates>
553553
<DataTemplate DataType="m:Commit">
@@ -563,27 +563,39 @@
563563
</DataTemplate>
564564

565565
<DataTemplate DataType="vm:CherryPickInProgress">
566-
<StackPanel Orientation="Horizontal">
567-
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick}"/>
568-
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick.Head}"/>
569-
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding Head}"/>
570-
</StackPanel>
566+
<Grid ColumnDefinitions="*,Auto">
567+
<StackPanel Grid.Column="0" Orientation="Horizontal">
568+
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick}"/>
569+
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick.Head}"/>
570+
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding Head}"/>
571+
</StackPanel>
572+
573+
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
574+
</Grid>
571575
</DataTemplate>
572576

573577
<DataTemplate DataType="vm:RebaseInProgress">
574-
<StackPanel Orientation="Horizontal">
575-
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase}"/>
576-
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase.StoppedAt}"/>
577-
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding StoppedAt.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding StoppedAt}"/>
578-
</StackPanel>
578+
<Grid ColumnDefinitions="*,Auto">
579+
<StackPanel Grid.Column="0" Orientation="Horizontal">
580+
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase}"/>
581+
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase.StoppedAt}"/>
582+
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding StoppedAt.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding StoppedAt}"/>
583+
</StackPanel>
584+
585+
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
586+
</Grid>
579587
</DataTemplate>
580588

581589
<DataTemplate DataType="vm:RevertInProgress">
582-
<StackPanel Orientation="Horizontal">
583-
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert}"/>
584-
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert.Head}"/>
585-
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding Head}"/>
586-
</StackPanel>
590+
<Grid ColumnDefinitions="*,Auto">
591+
<StackPanel Grid.Column="0" Orientation="Horizontal">
592+
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert}"/>
593+
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert.Head}"/>
594+
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding Head}"/>
595+
</StackPanel>
596+
597+
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
598+
</Grid>
587599
</DataTemplate>
588600

589601
<DataTemplate DataType="vm:MergeInProgress">
@@ -597,31 +609,13 @@
597609
</DataTemplate>
598610
</ContentControl.DataTemplates>
599611
</ContentControl>
600-
601-
<ContentControl Grid.Column="1" Margin="4,0" Content="{Binding InProgressContext}">
602-
<ContentControl.DataTemplates>
603-
<DataTemplate DataType="vm:CherryPickInProgress">
604-
<Button Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Command="{Binding Skip}"/>
605-
</DataTemplate>
606-
607-
<DataTemplate DataType="vm:RebaseInProgress">
608-
<Button Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Command="{Binding Skip}"/>
609-
</DataTemplate>
610-
611-
<DataTemplate DataType="vm:RevertInProgress">
612-
</DataTemplate>
613-
614-
<DataTemplate DataType="vm:MergeInProgress">
615-
</DataTemplate>
616-
</ContentControl.DataTemplates>
617-
</ContentControl>
618612

619-
<Button Grid.Column="2"
613+
<Button Grid.Column="1"
620614
Classes="flat"
621615
FontWeight="Regular"
622616
BorderThickness="0"
623617
Content="{DynamicResource Text.Repository.Abort}"
624-
Padding="8,2" Margin="4,0"
618+
Padding="8,2" Margin="0,0,8,0"
625619
Command="{Binding AbortMerge}"/>
626620
</Grid>
627621

src/Views/Repository.axaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,5 +428,13 @@ private void OnSwitchHistoriesOrderClicked(object sender, RoutedEventArgs e)
428428

429429
e.Handled = true;
430430
}
431+
432+
private void OnSkipInProgress(object sender, RoutedEventArgs e)
433+
{
434+
if (DataContext is ViewModels.Repository repo)
435+
repo.SkipMerge();
436+
437+
e.Handled = true;
438+
}
431439
}
432440
}

0 commit comments

Comments
 (0)