mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
feature: allow empty commit (#587)
This commit is contained in:
parent
a8a7775b83
commit
1855b43750
8 changed files with 147 additions and 20 deletions
|
@ -637,6 +637,7 @@
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitMessageHelper" xml:space="preserve">Template/Histories</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitMessageHelper" xml:space="preserve">Template/Histories</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">Trigger click event</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">Trigger click event</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitWithAutoStage" xml:space="preserve">Stage all changes and commit</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitWithAutoStage" xml:space="preserve">Stage all changes and commit</x:String>
|
||||||
|
<x:String x:Key="Text.WorkingCopy.ConfirmCommitWithoutFiles" xml:space="preserve">Empty commit detected! Do you want to continue (--allow-empty)?</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">CONFLICTS DETECTED</x:String>
|
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">CONFLICTS DETECTED</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">FILE CONFLICTS ARE RESOLVED</x:String>
|
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">FILE CONFLICTS ARE RESOLVED</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
|
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
|
||||||
|
|
|
@ -635,6 +635,7 @@
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitMessageHelper" xml:space="preserve">历史输入/模板</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitMessageHelper" xml:space="preserve">历史输入/模板</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">触发点击事件</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">触发点击事件</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitWithAutoStage" xml:space="preserve">自动暂存所有变更并提交</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitWithAutoStage" xml:space="preserve">自动暂存所有变更并提交</x:String>
|
||||||
|
<x:String x:Key="Text.WorkingCopy.ConfirmCommitWithoutFiles" xml:space="preserve">提交未包含变更文件!是否继续(--allow-empty)?</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">检测到冲突</x:String>
|
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">检测到冲突</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">文件冲突已解决</x:String>
|
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">文件冲突已解决</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">显示未跟踪文件</x:String>
|
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">显示未跟踪文件</x:String>
|
||||||
|
|
|
@ -640,6 +640,7 @@
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitMessageHelper" xml:space="preserve">歷史輸入/範本</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitMessageHelper" xml:space="preserve">歷史輸入/範本</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">觸發點擊事件</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitTip" xml:space="preserve">觸發點擊事件</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.CommitWithAutoStage" xml:space="preserve">自動暫存全部變更並提交</x:String>
|
<x:String x:Key="Text.WorkingCopy.CommitWithAutoStage" xml:space="preserve">自動暫存全部變更並提交</x:String>
|
||||||
|
<x:String x:Key="Text.WorkingCopy.ConfirmCommitWithoutFiles" xml:space="preserve">提交未包含變更檔案!是否繼續(--allow-empty)?</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">檢測到衝突</x:String>
|
<x:String x:Key="Text.WorkingCopy.Conflicts" xml:space="preserve">檢測到衝突</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">檔案衝突已解決</x:String>
|
<x:String x:Key="Text.WorkingCopy.Conflicts.Resolved" xml:space="preserve">檔案衝突已解決</x:String>
|
||||||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">顯示未追蹤檔案</x:String>
|
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">顯示未追蹤檔案</x:String>
|
||||||
|
|
19
src/ViewModels/ConfirmCommitWithoutFiles.cs
Normal file
19
src/ViewModels/ConfirmCommitWithoutFiles.cs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
namespace SourceGit.ViewModels
|
||||||
|
{
|
||||||
|
public class ConfirmCommitWithoutFiles
|
||||||
|
{
|
||||||
|
public ConfirmCommitWithoutFiles(WorkingCopy wc, bool autoPush)
|
||||||
|
{
|
||||||
|
_wc = wc;
|
||||||
|
_autoPush = autoPush;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Continue()
|
||||||
|
{
|
||||||
|
_wc.CommitWithoutFiles(_autoPush);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly WorkingCopy _wc;
|
||||||
|
private bool _autoPush;
|
||||||
|
}
|
||||||
|
}
|
|
@ -410,17 +410,22 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public void Commit()
|
public void Commit()
|
||||||
{
|
{
|
||||||
DoCommit(false, false);
|
DoCommit(false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CommitWithAutoStage()
|
public void CommitWithAutoStage()
|
||||||
{
|
{
|
||||||
DoCommit(true, false);
|
DoCommit(true, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CommitWithPush()
|
public void CommitWithPush()
|
||||||
{
|
{
|
||||||
DoCommit(false, true);
|
DoCommit(false, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CommitWithoutFiles(bool autoPush)
|
||||||
|
{
|
||||||
|
DoCommit(false, autoPush, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContextMenu CreateContextMenuForUnstagedChanges()
|
public ContextMenu CreateContextMenuForUnstagedChanges()
|
||||||
|
@ -1268,7 +1273,7 @@ namespace SourceGit.ViewModels
|
||||||
_repo.SetWatcherEnabled(true);
|
_repo.SetWatcherEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoCommit(bool autoStage, bool autoPush)
|
private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty)
|
||||||
{
|
{
|
||||||
if (!PopupHost.CanCreatePopup())
|
if (!PopupHost.CanCreatePopup())
|
||||||
{
|
{
|
||||||
|
@ -1282,23 +1287,16 @@ namespace SourceGit.ViewModels
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_useAmend)
|
if (!_useAmend && !allowEmpty)
|
||||||
{
|
{
|
||||||
if (autoStage)
|
if ((autoStage && _count == 0) || (!autoStage && _staged.Count == 0))
|
||||||
{
|
{
|
||||||
if (_count == 0)
|
App.OpenDialog(new Views.ConfirmCommitWithoutFiles()
|
||||||
{
|
{
|
||||||
App.RaiseException(_repo.FullPath, "No files added to commit!");
|
DataContext = new ConfirmCommitWithoutFiles(this, autoPush)
|
||||||
return;
|
});
|
||||||
}
|
|
||||||
}
|
return;
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_staged.Count == 0)
|
|
||||||
{
|
|
||||||
App.RaiseException(_repo.FullPath, "No files added to commit!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1313,7 +1311,7 @@ namespace SourceGit.ViewModels
|
||||||
succ = new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Exec();
|
succ = new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Exec();
|
||||||
|
|
||||||
if (succ)
|
if (succ)
|
||||||
succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend).Exec();
|
succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend, true).Exec();
|
||||||
|
|
||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
{
|
{
|
||||||
|
|
74
src/Views/ConfirmCommitWithoutFiles.axaml
Normal file
74
src/Views/ConfirmCommitWithoutFiles.axaml
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<v:ChromelessWindow xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:v="using:SourceGit.Views"
|
||||||
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="SourceGit.Views.ConfirmCommitWithoutFiles"
|
||||||
|
x:DataType="vm:ConfirmCommitWithoutFiles"
|
||||||
|
x:Name="ThisControl"
|
||||||
|
Icon="/App.ico"
|
||||||
|
Title="{DynamicResource Text.Warn}"
|
||||||
|
SizeToContent="WidthAndHeight"
|
||||||
|
CanResize="False"
|
||||||
|
WindowStartupLocation="CenterOwner">
|
||||||
|
<Grid RowDefinitions="Auto,Auto,Auto">
|
||||||
|
<!-- TitleBar -->
|
||||||
|
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
|
||||||
|
<Border Grid.Column="0" Grid.ColumnSpan="3"
|
||||||
|
Background="{DynamicResource Brush.TitleBar}"
|
||||||
|
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
||||||
|
PointerPressed="BeginMoveWindow"/>
|
||||||
|
|
||||||
|
<Path Grid.Column="0"
|
||||||
|
Width="14" Height="14"
|
||||||
|
Data="{StaticResource Icons.Error}"
|
||||||
|
Margin="10,0,0,0"
|
||||||
|
IsVisible="{OnPlatform True, macOS=False}"/>
|
||||||
|
|
||||||
|
<v:CaptionButtonsMacOS Grid.Column="0"
|
||||||
|
Margin="0,2,0,0"
|
||||||
|
IsCloseButtonOnly="True"
|
||||||
|
IsVisible="{OnPlatform False, macOS=True}"/>
|
||||||
|
|
||||||
|
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
|
||||||
|
Classes="bold"
|
||||||
|
Text="{DynamicResource Text.Warn}"
|
||||||
|
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||||
|
IsHitTestVisible="False"/>
|
||||||
|
|
||||||
|
<v:CaptionButtons Grid.Column="2"
|
||||||
|
IsCloseButtonOnly="True"
|
||||||
|
IsVisible="{OnPlatform True, macOS=False}"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Body -->
|
||||||
|
<Border Grid.Row="1" Margin="16">
|
||||||
|
<TextBlock Text="{DynamicResource Text.WorkingCopy.ConfirmCommitWithoutFiles}"/>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- Buttons -->
|
||||||
|
<StackPanel Grid.Row="2" Margin="0,0,0,16" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
|
<Button Classes="flat"
|
||||||
|
Width="80"
|
||||||
|
Height="30"
|
||||||
|
Margin="4,0"
|
||||||
|
Click="Sure"
|
||||||
|
Content="{DynamicResource Text.Sure}"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
HorizontalContentAlignment="Center"
|
||||||
|
VerticalContentAlignment="Center"/>
|
||||||
|
|
||||||
|
<Button Classes="flat primary"
|
||||||
|
Width="80"
|
||||||
|
Height="30"
|
||||||
|
Margin="4,0"
|
||||||
|
Click="CloseWindow"
|
||||||
|
Content="{DynamicResource Text.Cancel}"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
HorizontalContentAlignment="Center"
|
||||||
|
VerticalContentAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</v:ChromelessWindow>
|
33
src/Views/ConfirmCommitWithoutFiles.axaml.cs
Normal file
33
src/Views/ConfirmCommitWithoutFiles.axaml.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
|
namespace SourceGit.Views
|
||||||
|
{
|
||||||
|
public partial class ConfirmCommitWithoutFiles : ChromelessWindow
|
||||||
|
{
|
||||||
|
public ConfirmCommitWithoutFiles()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
BeginMoveDrag(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Sure(object _1, RoutedEventArgs _2)
|
||||||
|
{
|
||||||
|
if (DataContext is ViewModels.ConfirmCommitWithoutFiles vm)
|
||||||
|
{
|
||||||
|
vm.Continue();
|
||||||
|
}
|
||||||
|
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CloseWindow(object _1, RoutedEventArgs _2)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@
|
||||||
SizeToContent="Height"
|
SizeToContent="Height"
|
||||||
CanResize="False"
|
CanResize="False"
|
||||||
WindowStartupLocation="CenterOwner">
|
WindowStartupLocation="CenterOwner">
|
||||||
<Grid RowDefinitions="Auto,Auto,Auto" MinWidth="494">
|
<Grid RowDefinitions="Auto,Auto,Auto">
|
||||||
<!-- TitleBar -->
|
<!-- TitleBar -->
|
||||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
|
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
|
||||||
<Border Grid.Column="0" Grid.ColumnSpan="3"
|
<Border Grid.Column="0" Grid.ColumnSpan="3"
|
||||||
|
|
Loading…
Reference in a new issue