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" <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.Head}"/> </Border>
<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}"/> <Path Grid.Column="1"
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding Head.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange"/> Width="14" Height="14"
<TextBlock Grid.Column="2" Text="{Binding Head.Subject}" Margin="8,0,0,0" TextTrimming="CharacterEllipsis"/> Margin="12,0,0,0"
Fill="{DynamicResource Brush.FG1}"
Data="{StaticResource Icons.Down}"
VerticalAlignment="Center"
RenderTransformOrigin="50%,50%"
RenderTransform="rotate(270deg)"/>
<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> </Grid>
<TextBlock Grid.Row="1" Grid.Column="0" <v:CommitMessageTextBox Height="120" Margin="0,4,0,0" Text="{Binding Message, Mode=TwoWay}"/>
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>
<TextBlock Grid.Row="2" Grid.Column="0" <TextBlock Margin="0,6,0,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}" Text="{DynamicResource Text.Reword.Tip}"
TextWrapping="Wrap" TextWrapping="Wrap"
Foreground="{DynamicResource Brush.FG2}"/> Foreground="{DynamicResource Brush.FG2}"/>
</Grid>
</StackPanel> </StackPanel>
</UserControl> </UserControl>