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.Icon = App.CreateMenuIcon("Icons.Edit");
reword.Click += (o, e) => 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()) if (PopupHost.CanCreatePopup())
PopupHost.ShowPopup(new Reword(_repo, commit)); PopupHost.ShowPopup(new Reword(_repo, commit));
e.Handled = true; e.Handled = true;
@ -229,6 +235,12 @@ namespace SourceGit.ViewModels
squash.IsEnabled = commit.Parents.Count == 1; squash.IsEnabled = commit.Parents.Count == 1;
squash.Click += (o, e) => 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) if (commit.Parents.Count == 1)
{ {
var parent = _commits.Find(x => x.SHA == commit.Parents[0]); 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) public Squash(Repository repo, Models.Commit head, Models.Commit parent)
{ {
_repo = repo; _repo = repo;
_message = new Commands.QueryCommitFullMessage(_repo.FullPath, parent.SHA).Result(); _message = new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).Result();
Head = head; Head = head;
Parent = parent; Parent = parent;

View file

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