mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -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 abstract class InProgressContext
|
||||||
{
|
{
|
||||||
public string Repository
|
public InProgressContext(string repo, string cmd)
|
||||||
{
|
{
|
||||||
get;
|
_repo = repo;
|
||||||
set;
|
_cmd = cmd;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Abort()
|
public bool Abort()
|
||||||
{
|
{
|
||||||
return new Commands.Command()
|
return new Commands.Command()
|
||||||
{
|
{
|
||||||
WorkingDirectory = Repository,
|
WorkingDirectory = _repo,
|
||||||
Context = Repository,
|
Context = _repo,
|
||||||
Args = $"{Cmd} --abort",
|
Args = $"{_cmd} --abort",
|
||||||
}.Exec();
|
}.Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Skip()
|
public virtual bool Skip()
|
||||||
{
|
{
|
||||||
if (!CanSkip)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return new Commands.Command()
|
return new Commands.Command()
|
||||||
{
|
{
|
||||||
WorkingDirectory = Repository,
|
WorkingDirectory = _repo,
|
||||||
Context = Repository,
|
Context = _repo,
|
||||||
Args = $"{Cmd} --skip",
|
Args = $"{_cmd} --skip",
|
||||||
}.Exec();
|
}.Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,10 +34,10 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
return new Commands.Command()
|
return new Commands.Command()
|
||||||
{
|
{
|
||||||
WorkingDirectory = Repository,
|
WorkingDirectory = _repo,
|
||||||
Context = Repository,
|
Context = _repo,
|
||||||
Editor = Commands.Command.EditorType.None,
|
Editor = Commands.Command.EditorType.None,
|
||||||
Args = $"{Cmd} --continue",
|
Args = $"{_cmd} --continue",
|
||||||
}.Exec();
|
}.Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +53,9 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
return commit.SHA.Substring(0, 10);
|
return commit.SHA.Substring(0, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected string _repo = string.Empty;
|
||||||
|
protected string _cmd = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CherryPickInProgress : InProgressContext
|
public class CherryPickInProgress : InProgressContext
|
||||||
|
@ -90,7 +71,7 @@ namespace SourceGit.ViewModels
|
||||||
get => GetFriendlyNameOfCommit(Head);
|
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();
|
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 };
|
Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA };
|
||||||
|
@ -122,7 +103,7 @@ namespace SourceGit.ViewModels
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase", true)
|
public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase")
|
||||||
{
|
{
|
||||||
_gitDir = repo.GitDir;
|
_gitDir = repo.GitDir;
|
||||||
|
|
||||||
|
@ -141,8 +122,8 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
var succ = new Commands.Command()
|
var succ = new Commands.Command()
|
||||||
{
|
{
|
||||||
WorkingDirectory = Repository,
|
WorkingDirectory = _repo,
|
||||||
Context = Repository,
|
Context = _repo,
|
||||||
Editor = Commands.Command.EditorType.RebaseEditor,
|
Editor = Commands.Command.EditorType.RebaseEditor,
|
||||||
Args = $"rebase --continue",
|
Args = $"rebase --continue",
|
||||||
}.Exec();
|
}.Exec();
|
||||||
|
@ -177,7 +158,7 @@ namespace SourceGit.ViewModels
|
||||||
private set;
|
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();
|
var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "REVERT_HEAD")).Trim();
|
||||||
Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA };
|
Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).Result() ?? new Models.Commit() { SHA = headSHA };
|
||||||
|
@ -203,12 +184,17 @@ namespace SourceGit.ViewModels
|
||||||
get => GetFriendlyNameOfCommit(Source);
|
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);
|
Current = Commands.Branch.ShowCurrent(repo.FullPath);
|
||||||
|
|
||||||
var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim();
|
var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim();
|
||||||
Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).Result() ?? new Models.Commit() { SHA = sourceSHA };
|
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);
|
_workingCopy?.StashAll(autoStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SkipMerge()
|
||||||
|
{
|
||||||
|
_workingCopy?.SkipMerge();
|
||||||
|
}
|
||||||
|
|
||||||
public void AbortMerge()
|
public void AbortMerge()
|
||||||
{
|
{
|
||||||
_workingCopy?.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()
|
public void AbortMerge()
|
||||||
{
|
{
|
||||||
if (_inProgressContext != null)
|
if (_inProgressContext != null)
|
||||||
|
|
|
@ -547,7 +547,7 @@
|
||||||
|
|
||||||
<!-- Right -->
|
<!-- Right -->
|
||||||
<Grid Grid.Column="2" RowDefinitions="Auto,Auto,*">
|
<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.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 Grid.Column="0" Margin="8,0" Content="{Binding InProgressContext}">
|
||||||
<ContentControl.DataTemplates>
|
<ContentControl.DataTemplates>
|
||||||
<DataTemplate DataType="m:Commit">
|
<DataTemplate DataType="m:Commit">
|
||||||
|
@ -563,27 +563,39 @@
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="vm:CherryPickInProgress">
|
<DataTemplate DataType="vm:CherryPickInProgress">
|
||||||
<StackPanel Orientation="Horizontal">
|
<Grid ColumnDefinitions="*,Auto">
|
||||||
|
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.CherryPick}"/>
|
<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="{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}"/>
|
<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>
|
</StackPanel>
|
||||||
|
|
||||||
|
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
|
||||||
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="vm:RebaseInProgress">
|
<DataTemplate DataType="vm:RebaseInProgress">
|
||||||
<StackPanel Orientation="Horizontal">
|
<Grid ColumnDefinitions="*,Auto">
|
||||||
|
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Rebase}"/>
|
<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="{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}"/>
|
<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>
|
</StackPanel>
|
||||||
|
|
||||||
|
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
|
||||||
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="vm:RevertInProgress">
|
<DataTemplate DataType="vm:RevertInProgress">
|
||||||
<StackPanel Orientation="Horizontal">
|
<Grid ColumnDefinitions="*,Auto">
|
||||||
|
<StackPanel Grid.Column="0" Orientation="Horizontal">
|
||||||
<TextBlock FontWeight="Bold" Foreground="{DynamicResource Brush.ConflictForeground}" Text="{DynamicResource Text.InProgress.Revert}"/>
|
<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="{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}"/>
|
<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>
|
</StackPanel>
|
||||||
|
|
||||||
|
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" BorderThickness="0" Content="{DynamicResource Text.Repository.Skip}" Padding="8,2" Click="OnSkipInProgress"/>
|
||||||
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="vm:MergeInProgress">
|
<DataTemplate DataType="vm:MergeInProgress">
|
||||||
|
@ -598,30 +610,12 @@
|
||||||
</ContentControl.DataTemplates>
|
</ContentControl.DataTemplates>
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
|
|
||||||
<ContentControl Grid.Column="1" Margin="4,0" Content="{Binding InProgressContext}">
|
<Button Grid.Column="1"
|
||||||
<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"
|
|
||||||
Classes="flat"
|
Classes="flat"
|
||||||
FontWeight="Regular"
|
FontWeight="Regular"
|
||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
Content="{DynamicResource Text.Repository.Abort}"
|
Content="{DynamicResource Text.Repository.Abort}"
|
||||||
Padding="8,2" Margin="4,0"
|
Padding="8,2" Margin="0,0,8,0"
|
||||||
Command="{Binding AbortMerge}"/>
|
Command="{Binding AbortMerge}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
|
@ -428,5 +428,13 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
e.Handled = true;
|
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