refactor: rewrite amend behaviour (#300)

* toggle amend will show changes in HEAD commit
* since discard is not compatible with staged changes in `amend` mode, we only allows user to discard unstaged changes
This commit is contained in:
leo 2024-07-31 12:04:29 +08:00
parent 3c5a661fa0
commit f55a576013
No known key found for this signature in database
9 changed files with 261 additions and 86 deletions

View file

@ -77,7 +77,7 @@
<StackPanel x:Name="Popup" IsVisible="False" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" Effect="drop-shadow(0 0 6 #40000000)">
<Button Classes="flat" Content="{DynamicResource Text.Hunk.Stage}" Click="OnStageChunk" IsVisible="{Binding #ThisControl.IsUnstagedChange}"/>
<Button Classes="flat" Content="{DynamicResource Text.Hunk.Unstage}" Click="OnUnstageChunk" IsVisible="{Binding #ThisControl.IsUnstagedChange, Converter={x:Static BoolConverters.Not}}"/>
<Button Classes="flat" Content="{DynamicResource Text.Hunk.Discard}" Margin="8,0,0,0" Click="OnDiscardChunk"/>
<Button Classes="flat" Content="{DynamicResource Text.Hunk.Discard}" Margin="8,0,0,0" Click="OnDiscardChunk" IsVisible="{Binding #ThisControl.IsUnstagedChange}"/>
</StackPanel>
</Grid>
</UserControl>

View file

@ -1273,7 +1273,7 @@ namespace SourceGit.Views
return;
var workcopy = workcopyView.DataContext as ViewModels.WorkingCopy;
workcopy?.Discard(new List<Models.Change> { change }, diff.Option.IsUnstaged);
workcopy?.Discard(new List<Models.Change> { change });
}
else
{
@ -1303,7 +1303,7 @@ namespace SourceGit.Views
diff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, true, chunk.IsOldSide, tmpFile);
}
new Commands.Apply(diff.Repo, tmpFile, true, "nowarn", diff.Option.IsUnstaged ? "--reverse" : "--index --reverse").Exec();
new Commands.Apply(diff.Repo, tmpFile, true, "nowarn", "--reverse").Exec();
File.Delete(tmpFile);
repo.MarkWorkingCopyDirtyManually();