diff --git a/src/Commands/Commit.cs b/src/Commands/Commit.cs index 8ac6501f..492d00c7 100644 --- a/src/Commands/Commit.cs +++ b/src/Commands/Commit.cs @@ -4,7 +4,7 @@ namespace SourceGit.Commands { public class Commit : Command { - public Commit(string repo, string message, bool amend, bool allowEmpty = false) + public Commit(string repo, string message, bool autoStage, bool amend, bool allowEmpty = false) { var file = Path.GetTempFileName(); File.WriteAllText(file, message); @@ -12,6 +12,8 @@ namespace SourceGit.Commands WorkingDirectory = repo; Context = repo; Args = $"commit --file=\"{file}\""; + if (autoStage) + Args += " --all"; if (amend) Args += " --amend --no-edit"; if (allowEmpty) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 546a300b..55b05a01 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -543,6 +543,8 @@ Ignore files in the same folder Ignore this file only Amend + Auto-Stage + 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. You can stage this file now. COMMIT COMMIT & PUSH diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index fcc2f40f..58a72d47 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -545,6 +545,8 @@ 忽略同目录下所有文件 忽略本文件 修补(--amend) + 自动暂存(--all) + 提交前自动将修改过和删除的文件加入暂存区,但新增文件需要手动添加。 现在您已可将其加入暂存区中 提交 提交并推送 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 159009b9..73176126 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -545,6 +545,8 @@ 忽略同路徑下所有檔案 忽略本檔案 修補(--amend) + 自動暫存(--all) + 提交前自動將修改過和刪除的檔案加入暫存區,但新增檔案需要手動添加。 現在您已可將其加入暫存區中 提交 提交併推送 diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 67250c4b..1c087506 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -64,6 +64,12 @@ namespace SourceGit.ViewModels set; } = true; + public bool AutoStageBeforeCommit + { + get; + set; + } = false; + public AvaloniaList Filters { get; diff --git a/src/ViewModels/Reword.cs b/src/ViewModels/Reword.cs index 47b1bd06..b3f0e9f8 100644 --- a/src/ViewModels/Reword.cs +++ b/src/ViewModels/Reword.cs @@ -39,7 +39,7 @@ namespace SourceGit.ViewModels return Task.Run(() => { - var succ = new Commands.Commit(_repo.FullPath, _message, true, true).Exec(); + var succ = new Commands.Commit(_repo.FullPath, _message, false, true, true).Exec(); CallUIThread(() => _repo.SetWatcherEnabled(true)); return succ; }); diff --git a/src/ViewModels/Squash.cs b/src/ViewModels/Squash.cs index 4b35266b..8e78658d 100644 --- a/src/ViewModels/Squash.cs +++ b/src/ViewModels/Squash.cs @@ -43,7 +43,7 @@ namespace SourceGit.ViewModels { var succ = new Commands.Reset(_repo.FullPath, Parent.SHA, "--soft").Exec(); if (succ) - succ = new Commands.Commit(_repo.FullPath, _message, true).Exec(); + succ = new Commands.Commit(_repo.FullPath, _message, false, true).Exec(); CallUIThread(() => _repo.SetWatcherEnabled(true)); return succ; }); diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 8b32240c..a4d8b84e 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -77,6 +77,12 @@ namespace SourceGit.ViewModels private set => SetProperty(ref _isCommitting, value); } + public bool AutoStageBeforeCommit + { + get => _repo.Settings.AutoStageBeforeCommit; + set => _repo.Settings.AutoStageBeforeCommit = value; + } + public bool UseAmend { get => _useAmend; @@ -1216,7 +1222,13 @@ namespace SourceGit.ViewModels return; } - if (_staged.Count == 0) + if (_count == 0) + { + App.RaiseException(_repo.FullPath, "No files added to commit!"); + return; + } + + if (!AutoStageBeforeCommit && _staged.Count == 0) { App.RaiseException(_repo.FullPath, "No files added to commit!"); return; @@ -1234,9 +1246,10 @@ namespace SourceGit.ViewModels IsCommitting = true; _repo.SetWatcherEnabled(false); + var autoStage = AutoStageBeforeCommit; Task.Run(() => { - var succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend).Exec(); + var succ = new Commands.Commit(_repo.FullPath, _commitMessage, autoStage, _useAmend).Exec(); Dispatcher.UIThread.Post(() => { if (succ) diff --git a/src/Views/WorkingCopy.axaml b/src/Views/WorkingCopy.axaml index 49d693ae..8e77d9d8 100644 --- a/src/Views/WorkingCopy.axaml +++ b/src/Views/WorkingCopy.axaml @@ -174,7 +174,7 @@ - +