@@ -261,7 +261,6 @@ public void SetData(List<Models.Change> changes)
261261 }
262262
263263 _cached = changes ;
264- _count = _cached . Count ;
265264
266265 var lastSelectedUnstaged = new HashSet < string > ( ) ;
267266 var lastSelectedStaged = new HashSet < string > ( ) ;
@@ -1782,7 +1781,7 @@ private void SetDetail(Models.Change change, bool isUnstaged)
17821781 DetailContext = new DiffContext ( _repo . FullPath , new Models . DiffOption ( change , isUnstaged ) , _detailContext as DiffContext ) ;
17831782 }
17841783
1785- private void DoCommit ( bool autoStage , bool autoPush , bool allowEmpty = false , bool confirmWithFilter = false )
1784+ private void DoCommit ( bool autoStage , bool autoPush , CommitCheckPassed checkPassed = CommitCheckPassed . None )
17861785 {
17871786 if ( string . IsNullOrWhiteSpace ( _commitMessage ) )
17881787 return ;
@@ -1793,18 +1792,25 @@ private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty = false, bo
17931792 return ;
17941793 }
17951794
1796- if ( ! string . IsNullOrEmpty ( _filter ) && _staged . Count > _visibleStaged . Count && ! confirmWithFilter )
1795+ if ( _repo . CurrentBranch is { IsDetachedHead : true } && checkPassed < CommitCheckPassed . DetachedHead )
17971796 {
1798- var confirmMessage = App . Text ( "WorkingCopy.ConfirmCommitWithFilter" , _staged . Count , _visibleStaged . Count , _staged . Count - _visibleStaged . Count ) ;
1799- App . ShowWindow ( new ConfirmCommit ( confirmMessage , ( ) => DoCommit ( autoStage , autoPush , allowEmpty , true ) ) , true ) ;
1797+ var msg = App . Text ( "WorkingCopy.ConfirmCommitWithDetachedHead" ) ;
1798+ App . ShowWindow ( new ConfirmCommit ( msg , ( ) => DoCommit ( autoStage , autoPush , CommitCheckPassed . DetachedHead ) ) , true ) ;
18001799 return ;
18011800 }
18021801
1803- if ( ! _useAmend && ! allowEmpty )
1802+ if ( ! string . IsNullOrEmpty ( _filter ) && _staged . Count > _visibleStaged . Count && checkPassed < CommitCheckPassed . Filter )
18041803 {
1805- if ( ( autoStage && _count == 0 ) || ( ! autoStage && _staged . Count == 0 ) )
1804+ var msg = App . Text ( "WorkingCopy.ConfirmCommitWithFilter" , _staged . Count , _visibleStaged . Count , _staged . Count - _visibleStaged . Count ) ;
1805+ App . ShowWindow ( new ConfirmCommit ( msg , ( ) => DoCommit ( autoStage , autoPush , CommitCheckPassed . Filter ) ) , true ) ;
1806+ return ;
1807+ }
1808+
1809+ if ( checkPassed < CommitCheckPassed . FileCount && ! _useAmend )
1810+ {
1811+ if ( ( ! autoStage && _staged . Count == 0 ) || ( autoStage && _cached . Count == 0 ) )
18061812 {
1807- App . ShowWindow ( new ConfirmEmptyCommit ( _count > 0 , stageAll => DoCommit ( stageAll , autoPush , true , confirmWithFilter ) ) , true ) ;
1813+ App . ShowWindow ( new ConfirmEmptyCommit ( _cached . Count > 0 , stageAll => DoCommit ( stageAll , autoPush , CommitCheckPassed . FileCount ) ) , true ) ;
18081814 return ;
18091815 }
18101816 }
@@ -1871,6 +1877,14 @@ private bool IsChanged(List<Models.Change> old, List<Models.Change> cur)
18711877 return false ;
18721878 }
18731879
1880+ private enum CommitCheckPassed
1881+ {
1882+ None = 0 ,
1883+ DetachedHead ,
1884+ Filter ,
1885+ FileCount ,
1886+ }
1887+
18741888 private Repository _repo = null ;
18751889 private bool _isLoadingData = false ;
18761890 private bool _isStaging = false ;
@@ -1886,7 +1900,6 @@ private bool IsChanged(List<Models.Change> old, List<Models.Change> cur)
18861900 private List < Models . Change > _visibleStaged = [ ] ;
18871901 private List < Models . Change > _selectedUnstaged = [ ] ;
18881902 private List < Models . Change > _selectedStaged = [ ] ;
1889- private int _count = 0 ;
18901903 private object _detailContext = null ;
18911904 private string _filter = string . Empty ;
18921905 private string _commitMessage = string . Empty ;
0 commit comments