enhance: forbid to reword or squash when there're local changes

This commit is contained in:
leo 2024-06-25 10:26:31 +08:00
parent 3b7545e4fb
commit 2d4f8709ca
No known key found for this signature in database
3 changed files with 43 additions and 33 deletions

View file

@ -217,6 +217,12 @@ namespace SourceGit.ViewModels
reword.Icon = App.CreateMenuIcon("Icons.Edit");
reword.Click += (o, e) =>
{
if (_repo.WorkingCopyChangesCount > 0)
{
App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first.");
return;
}
if (PopupHost.CanCreatePopup())
PopupHost.ShowPopup(new Reword(_repo, commit));
e.Handled = true;
@ -229,6 +235,12 @@ namespace SourceGit.ViewModels
squash.IsEnabled = commit.Parents.Count == 1;
squash.Click += (o, e) =>
{
if (_repo.WorkingCopyChangesCount > 0)
{
App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first.");
return;
}
if (commit.Parents.Count == 1)
{
var parent = _commits.Find(x => x.SHA == commit.Parents[0]);

View file

@ -27,7 +27,7 @@ namespace SourceGit.ViewModels
public Squash(Repository repo, Models.Commit head, Models.Commit parent)
{
_repo = repo;
_message = new Commands.QueryCommitFullMessage(_repo.FullPath, parent.SHA).Result();
_message = new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).Result();
Head = head;
Parent = parent;

View file

@ -12,40 +12,38 @@
<TextBlock FontSize="18"
Classes="bold"
Text="{DynamicResource Text.Squash}"/>
<Grid Margin="0,16,0,0" RowDefinitions="28,28,120,Auto" ColumnDefinitions="100,*">
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Squash.Head}"/>
<Grid Grid.Row="0" Grid.Column="1" ColumnDefinitions="Auto,Auto,*" Height="20" VerticalAlignment="Center">
<Path Grid.Column="0" Margin="0,6,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Commit}"/>
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange"/>
<TextBlock Grid.Column="2" Text="{Binding Head.Subject}" Margin="8,0,0,0" TextTrimming="CharacterEllipsis"/>
</Grid>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Squash.To}"/>
<Grid Grid.Row="1" Grid.Column="1" ColumnDefinitions="Auto,Auto,*" Height="20" VerticalAlignment="Center">
<Path Grid.Column="0" Margin="0,6,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Commit}"/>
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding Parent.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange"/>
<TextBlock Grid.Column="2" Text="{Binding Parent.Subject}" Margin="8,0,0,0" TextTrimming="CharacterEllipsis"/>
</Grid>
<Grid Margin="0,18,0,0" ColumnDefinitions="Auto,Auto,Auto,Auto,*">
<Border Grid.Column="0" Background="{DynamicResource Brush.Accent}" CornerRadius="4">
<TextBlock Text="HEAD" Classes="monospace" Margin="4,0" Foreground="#FFDDDDDD"/>
</Border>
<Path Grid.Column="1"
Width="14" Height="14"
Margin="12,0,0,0"
Fill="{DynamicResource Brush.FG1}"
Data="{StaticResource Icons.Down}"
VerticalAlignment="Center"
RenderTransformOrigin="50%,50%"
RenderTransform="rotate(270deg)"/>
<TextBlock Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="0,5,8,0"
Text="{DynamicResource Text.Squash.Message}"/>
<v:CommitMessageTextBox Grid.Row="2" Grid.Column="1"
Margin="0,4,0,0"
Text="{Binding Message, Mode=TwoWay}"/>
<TextBlock Grid.Row="3" Grid.Column="1"
Margin="0,4,0,0"
Text="{DynamicResource Text.Reword.Tip}"
TextWrapping="Wrap"
Foreground="{DynamicResource Brush.FG2}"/>
<Path Grid.Column="2"
Margin="6,6,8,0"
Width="14" Height="14"
Fill="{DynamicResource Brush.FG1}"
Data="{StaticResource Icons.Commit}"/>
<TextBlock Grid.Column="3"
Classes="monospace"
Text="{Binding Parent.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"
Foreground="DarkOrange"/>
<TextBlock Grid.Column="4" Margin="8,0,0,0" Text="{Binding Parent.Subject}" TextTrimming="CharacterEllipsis"/>
</Grid>
<v:CommitMessageTextBox Height="120" Margin="0,4,0,0" Text="{Binding Message, Mode=TwoWay}"/>
<TextBlock Margin="0,6,0,0"
Text="{DynamicResource Text.Reword.Tip}"
TextWrapping="Wrap"
Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel>
</UserControl>