mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
enhance: supports --skip
while reverting commits
This commit is contained in:
parent
dcaeaef48a
commit
0dd6692cd8
5 changed files with 94 additions and 78 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -764,6 +764,11 @@ namespace SourceGit.ViewModels
|
|||
_workingCopy?.StashAll(autoStart);
|
||||
}
|
||||
|
||||
public void SkipMerge()
|
||||
{
|
||||
_workingCopy?.SkipMerge();
|
||||
}
|
||||
|
||||
public void AbortMerge()
|
||||
{
|
||||
_workingCopy?.AbortMerge();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -546,8 +546,8 @@
|
|||
BorderBrush="{DynamicResource Brush.Border0}"/>
|
||||
|
||||
<!-- Right -->
|
||||
<Grid Grid.Column="2" RowDefinitions="Auto,Auto,*">
|
||||
<Grid Grid.Row="0" Height="28" ColumnDefinitions="*,Auto,Auto" Background="{DynamicResource Brush.Conflict}" IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<Grid Grid.Column="2" RowDefinitions="Auto,Auto,*">
|
||||
<Grid Grid.Row="0" Height="28" ColumnDefinitions="*,Auto" Background="{DynamicResource Brush.Conflict}" IsVisible="{Binding InProgressContext, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<ContentControl Grid.Column="0" Margin="8,0" Content="{Binding InProgressContext}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="m:Commit">
|
||||
|
@ -563,27 +563,39 @@
|
|||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:CherryPickInProgress">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick.Head}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding Head}"/>
|
||||
</StackPanel>
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick.Head}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding Head}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:RebaseInProgress">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase.StoppedAt}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding StoppedAt.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding StoppedAt}"/>
|
||||
</StackPanel>
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase.StoppedAt}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding StoppedAt.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding StoppedAt}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:RevertInProgress">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert.Head}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding Head}"/>
|
||||
</StackPanel>
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert.Head}"/>
|
||||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Foreground="DarkOrange" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" ToolTip.Tip="{Binding Head}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:MergeInProgress">
|
||||
|
@ -597,31 +609,13 @@
|
|||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
|
||||
<ContentControl Grid.Column="1" Margin="4,0" Content="{Binding InProgressContext}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="vm:CherryPickInProgress">
|
||||
<Button Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Command="{Binding Skip}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:RebaseInProgress">
|
||||
<Button Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Command="{Binding Skip}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:RevertInProgress">
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:MergeInProgress">
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
<Button Grid.Column="1"
|
||||
Classes="flat"
|
||||
FontWeight="Regular"
|
||||
BorderThickness="0"
|
||||
Content="{DynamicResource Text.Repository.Abort}"
|
||||
Padding="8,2" Margin="4,0"
|
||||
Padding="8,2" Margin="0,0,8,0"
|
||||
Command="{Binding AbortMerge}"/>
|
||||
</Grid>
|
||||
|
||||
|
|
|
@ -428,5 +428,13 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnSkipInProgress(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
repo.SkipMerge();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue