Skip to content

Commit 09b4183

Browse files
committed
feature: add an option to enable -a,--all in commit command (#244)
1 parent fda1346 commit 09b4183

File tree

9 files changed

+44
-9
lines changed

9 files changed

+44
-9
lines changed

src/Commands/Commit.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ namespace SourceGit.Commands
44
{
55
public class Commit : Command
66
{
7-
public Commit(string repo, string message, bool amend, bool allowEmpty = false)
7+
public Commit(string repo, string message, bool autoStage, bool amend, bool allowEmpty = false)
88
{
99
var file = Path.GetTempFileName();
1010
File.WriteAllText(file, message);
1111

1212
WorkingDirectory = repo;
1313
Context = repo;
1414
Args = $"commit --file=\"{file}\"";
15+
if (autoStage)
16+
Args += " --all";
1517
if (amend)
1618
Args += " --amend --no-edit";
1719
if (allowEmpty)

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@
543543
<x:String x:Key="Text.WorkingCopy.AddToGitIgnore.InSameFolder" xml:space="preserve">Ignore files in the same folder</x:String>
544544
<x:String x:Key="Text.WorkingCopy.AddToGitIgnore.SingleFile" xml:space="preserve">Ignore this file only</x:String>
545545
<x:String x:Key="Text.WorkingCopy.Amend" xml:space="preserve">Amend</x:String>
546+
<x:String x:Key="Text.WorkingCopy.AutoStage" xml:space="preserve">Auto-Stage</x:String>
547+
<x:String x:Key="Text.WorkingCopy.AutoStage.Tip" xml:space="preserve">Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.</x:String>
546548
<x:String x:Key="Text.WorkingCopy.CanStageTip" xml:space="preserve">You can stage this file now.</x:String>
547549
<x:String x:Key="Text.WorkingCopy.Commit" xml:space="preserve">COMMIT</x:String>
548550
<x:String x:Key="Text.WorkingCopy.CommitAndPush" xml:space="preserve">COMMIT &amp; PUSH</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@
545545
<x:String x:Key="Text.WorkingCopy.AddToGitIgnore.InSameFolder" xml:space="preserve">忽略同目录下所有文件</x:String>
546546
<x:String x:Key="Text.WorkingCopy.AddToGitIgnore.SingleFile" xml:space="preserve">忽略本文件</x:String>
547547
<x:String x:Key="Text.WorkingCopy.Amend" xml:space="preserve">修补(--amend)</x:String>
548+
<x:String x:Key="Text.WorkingCopy.AutoStage" xml:space="preserve">自动暂存(--all)</x:String>
549+
<x:String x:Key="Text.WorkingCopy.AutoStage.Tip" xml:space="preserve">提交前自动将修改过和删除的文件加入暂存区,但新增文件需要手动添加。</x:String>
548550
<x:String x:Key="Text.WorkingCopy.CanStageTip" xml:space="preserve">现在您已可将其加入暂存区中</x:String>
549551
<x:String x:Key="Text.WorkingCopy.Commit" xml:space="preserve">提交</x:String>
550552
<x:String x:Key="Text.WorkingCopy.CommitAndPush" xml:space="preserve">提交并推送</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@
545545
<x:String x:Key="Text.WorkingCopy.AddToGitIgnore.InSameFolder" xml:space="preserve">忽略同路徑下所有檔案</x:String>
546546
<x:String x:Key="Text.WorkingCopy.AddToGitIgnore.SingleFile" xml:space="preserve">忽略本檔案</x:String>
547547
<x:String x:Key="Text.WorkingCopy.Amend" xml:space="preserve">修補(--amend)</x:String>
548+
<x:String x:Key="Text.WorkingCopy.AutoStage" xml:space="preserve">自動暫存(--all)</x:String>
549+
<x:String x:Key="Text.WorkingCopy.AutoStage.Tip" xml:space="preserve">提交前自動將修改過和刪除的檔案加入暫存區,但新增檔案需要手動添加。</x:String>
548550
<x:String x:Key="Text.WorkingCopy.CanStageTip" xml:space="preserve">現在您已可將其加入暫存區中</x:String>
549551
<x:String x:Key="Text.WorkingCopy.Commit" xml:space="preserve">提交</x:String>
550552
<x:String x:Key="Text.WorkingCopy.CommitAndPush" xml:space="preserve">提交併推送</x:String>

src/ViewModels/Repository.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public bool CheckoutBranchOnCreateBranch
6464
set;
6565
} = true;
6666

67+
public bool AutoStageBeforeCommit
68+
{
69+
get;
70+
set;
71+
} = false;
72+
6773
public AvaloniaList<string> Filters
6874
{
6975
get;

src/ViewModels/Reword.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override Task<bool> Sure()
3939

4040
return Task.Run(() =>
4141
{
42-
var succ = new Commands.Commit(_repo.FullPath, _message, true, true).Exec();
42+
var succ = new Commands.Commit(_repo.FullPath, _message, false, true, true).Exec();
4343
CallUIThread(() => _repo.SetWatcherEnabled(true));
4444
return succ;
4545
});

src/ViewModels/Squash.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public override Task<bool> Sure()
4343
{
4444
var succ = new Commands.Reset(_repo.FullPath, Parent.SHA, "--soft").Exec();
4545
if (succ)
46-
succ = new Commands.Commit(_repo.FullPath, _message, true).Exec();
46+
succ = new Commands.Commit(_repo.FullPath, _message, false, true).Exec();
4747
CallUIThread(() => _repo.SetWatcherEnabled(true));
4848
return succ;
4949
});

src/ViewModels/WorkingCopy.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public bool IsCommitting
7777
private set => SetProperty(ref _isCommitting, value);
7878
}
7979

80+
public bool AutoStageBeforeCommit
81+
{
82+
get => _repo.Settings.AutoStageBeforeCommit;
83+
set => _repo.Settings.AutoStageBeforeCommit = value;
84+
}
85+
8086
public bool UseAmend
8187
{
8288
get => _useAmend;
@@ -1216,7 +1222,13 @@ private void DoCommit(bool autoPush)
12161222
return;
12171223
}
12181224

1219-
if (_staged.Count == 0)
1225+
if (_count == 0)
1226+
{
1227+
App.RaiseException(_repo.FullPath, "No files added to commit!");
1228+
return;
1229+
}
1230+
1231+
if (!AutoStageBeforeCommit && _staged.Count == 0)
12201232
{
12211233
App.RaiseException(_repo.FullPath, "No files added to commit!");
12221234
return;
@@ -1234,9 +1246,10 @@ private void DoCommit(bool autoPush)
12341246
IsCommitting = true;
12351247
_repo.SetWatcherEnabled(false);
12361248

1249+
var autoStage = AutoStageBeforeCommit;
12371250
Task.Run(() =>
12381251
{
1239-
var succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend).Exec();
1252+
var succ = new Commands.Commit(_repo.FullPath, _commitMessage, autoStage, _useAmend).Exec();
12401253
Dispatcher.UIThread.Post(() =>
12411254
{
12421255
if (succ)

src/Views/WorkingCopy.axaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
<v:CommitMessageTextBox Grid.Row="2" Text="{Binding CommitMessage, Mode=TwoWay}"/>
175175

176176
<!-- Commit Options -->
177-
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,*,Auto,Auto,Auto">
177+
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,Auto,*,Auto,Auto,Auto">
178178
<Button Grid.Column="0"
179179
Classes="icon_button"
180180
Width="14" Height="14"
@@ -184,15 +184,23 @@
184184
</Button>
185185

186186
<CheckBox Grid.Column="1"
187+
Height="24"
188+
Margin="12,0,0,0"
189+
HorizontalAlignment="Left"
190+
IsChecked="{Binding AutoStageBeforeCommit, Mode=TwoWay}"
191+
Content="{DynamicResource Text.WorkingCopy.AutoStage}"
192+
ToolTip.Tip="{DynamicResource Text.WorkingCopy.AutoStage.Tip}"/>
193+
194+
<CheckBox Grid.Column="2"
187195
Height="24"
188196
Margin="12,0,0,0"
189197
HorizontalAlignment="Left"
190198
IsChecked="{Binding UseAmend, Mode=TwoWay}"
191199
Content="{DynamicResource Text.WorkingCopy.Amend}"/>
192200

193-
<v:LoadingIcon Grid.Column="3" Width="18" Height="18" IsVisible="{Binding IsCommitting}"/>
201+
<v:LoadingIcon Grid.Column="4" Width="18" Height="18" IsVisible="{Binding IsCommitting}"/>
194202

195-
<Button Grid.Column="4"
203+
<Button Grid.Column="5"
196204
Classes="flat primary"
197205
Content="{DynamicResource Text.WorkingCopy.Commit}"
198206
Height="28"
@@ -202,7 +210,7 @@
202210
HotKey="{OnPlatform Ctrl+Enter, macOS=⌘+Enter}"
203211
ToolTip.Tip="{OnPlatform Ctrl+Enter, macOS=⌘+Enter}"/>
204212

205-
<Button Grid.Column="5"
213+
<Button Grid.Column="6"
206214
Classes="flat"
207215
Content="{DynamicResource Text.WorkingCopy.CommitAndPush}"
208216
Height="28"

0 commit comments

Comments
 (0)