diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index d8a28b82..fddd9986 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -793,6 +793,7 @@ Trigger click event Commit (Edit) Stage all changes and commit + You are creating commit on a detached HEAD. Do you want to continue? You have staged {0} file(s) but only {1} file(s) displayed ({2} files are filtered out). Do you want to continue? CONFLICTS DETECTED OPEN EXTERNAL MERGETOOL diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index a25a4651..1debd516 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -797,6 +797,7 @@ 触发点击事件 提交(修改原始提交) 自动暂存所有变更并提交 + 您正在向一个游离的 HEAD 提交变更,是否继续提交? 当前有 {0} 个文件在暂存区中,但仅显示了 {1} 个文件({2} 个文件被过滤掉了),是否继续提交? 检测到冲突 打开合并工具 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 625f2873..aed59a18 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -797,6 +797,7 @@ 觸發點擊事件 提交 (修改原始提交) 自動暫存全部變更並提交 + 您正在向一个分離狀態的 HEAD 提交變更,您確定要繼續提交嗎? 您已暫存 {0} 個檔案,但只顯示 {1} 個檔案 ({2} 個檔案被篩選器隱藏)。您確定要繼續提交嗎? 偵測到衝突 使用外部合併工具開啟 diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index be9e1a7d..e03e8e49 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -261,7 +261,6 @@ namespace SourceGit.ViewModels } _cached = changes; - _count = _cached.Count; var lastSelectedUnstaged = new HashSet(); var lastSelectedStaged = new HashSet(); @@ -1782,7 +1781,7 @@ namespace SourceGit.ViewModels DetailContext = new DiffContext(_repo.FullPath, new Models.DiffOption(change, isUnstaged), _detailContext as DiffContext); } - private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty = false, bool confirmWithFilter = false) + private void DoCommit(bool autoStage, bool autoPush, CommitCheckPassed checkPassed = CommitCheckPassed.None) { if (string.IsNullOrWhiteSpace(_commitMessage)) return; @@ -1793,18 +1792,25 @@ namespace SourceGit.ViewModels return; } - if (!string.IsNullOrEmpty(_filter) && _staged.Count > _visibleStaged.Count && !confirmWithFilter) + if (_repo.CurrentBranch is { IsDetachedHead: true } && checkPassed < CommitCheckPassed.DetachedHead) { - var confirmMessage = App.Text("WorkingCopy.ConfirmCommitWithFilter", _staged.Count, _visibleStaged.Count, _staged.Count - _visibleStaged.Count); - App.ShowWindow(new ConfirmCommit(confirmMessage, () => DoCommit(autoStage, autoPush, allowEmpty, true)), true); + var msg = App.Text("WorkingCopy.ConfirmCommitWithDetachedHead"); + App.ShowWindow(new ConfirmCommit(msg, () => DoCommit(autoStage, autoPush, CommitCheckPassed.DetachedHead)), true); return; } - if (!_useAmend && !allowEmpty) + if (!string.IsNullOrEmpty(_filter) && _staged.Count > _visibleStaged.Count && checkPassed < CommitCheckPassed.Filter) { - if ((autoStage && _count == 0) || (!autoStage && _staged.Count == 0)) + var msg = App.Text("WorkingCopy.ConfirmCommitWithFilter", _staged.Count, _visibleStaged.Count, _staged.Count - _visibleStaged.Count); + App.ShowWindow(new ConfirmCommit(msg, () => DoCommit(autoStage, autoPush, CommitCheckPassed.Filter)), true); + return; + } + + if (checkPassed < CommitCheckPassed.FileCount && !_useAmend) + { + if ((!autoStage && _staged.Count == 0) || (autoStage && _cached.Count == 0)) { - App.ShowWindow(new ConfirmEmptyCommit(_count > 0, stageAll => DoCommit(stageAll, autoPush, true, confirmWithFilter)), true); + App.ShowWindow(new ConfirmEmptyCommit(_cached.Count > 0, stageAll => DoCommit(stageAll, autoPush, CommitCheckPassed.FileCount)), true); return; } } @@ -1871,6 +1877,14 @@ namespace SourceGit.ViewModels return false; } + private enum CommitCheckPassed + { + None = 0, + DetachedHead, + Filter, + FileCount, + } + private Repository _repo = null; private bool _isLoadingData = false; private bool _isStaging = false; @@ -1886,7 +1900,6 @@ namespace SourceGit.ViewModels private List _visibleStaged = []; private List _selectedUnstaged = []; private List _selectedStaged = []; - private int _count = 0; private object _detailContext = null; private string _filter = string.Empty; private string _commitMessage = string.Empty;