@@ -606,19 +606,86 @@ public void ApplyCommitMessageTemplate(Models.CommitTemplate tmpl)
606606 CommitMessage = tmpl . Apply ( _repo . CurrentBranch , _staged ) ;
607607 }
608608
609- public void Commit ( )
609+ public async Task CommitAsync ( bool autoStage , bool autoPush , Models . CommitCheckPassed checkPassed = Models . CommitCheckPassed . None )
610610 {
611- DoCommit ( false , false ) ;
612- }
611+ if ( string . IsNullOrWhiteSpace ( _commitMessage ) )
612+ return ;
613613
614- public void CommitWithAutoStage ( )
615- {
616- DoCommit ( true , false ) ;
617- }
614+ if ( ! _repo . CanCreatePopup ( ) )
615+ {
616+ App . RaiseException ( _repo . FullPath , "Repository has an unfinished job! Please wait!" ) ;
617+ return ;
618+ }
618619
619- public void CommitWithPush ( )
620- {
621- DoCommit ( false , true ) ;
620+ if ( autoStage && HasUnsolvedConflicts )
621+ {
622+ App . RaiseException ( _repo . FullPath , "Repository has unsolved conflict(s). Auto-stage and commit is disabled!" ) ;
623+ return ;
624+ }
625+
626+ if ( _repo . CurrentBranch is { IsDetachedHead : true } && checkPassed < Models . CommitCheckPassed . DetachedHead )
627+ {
628+ var msg = App . Text ( "WorkingCopy.ConfirmCommitWithDetachedHead" ) ;
629+ var sure = await App . AskConfirmAsync ( msg ) ;
630+ if ( sure )
631+ await CommitAsync ( autoStage , autoPush , Models . CommitCheckPassed . DetachedHead ) ;
632+ return ;
633+ }
634+
635+ if ( ! string . IsNullOrEmpty ( _filter ) && _staged . Count > _visibleStaged . Count && checkPassed < Models . CommitCheckPassed . Filter )
636+ {
637+ var msg = App . Text ( "WorkingCopy.ConfirmCommitWithFilter" , _staged . Count , _visibleStaged . Count , _staged . Count - _visibleStaged . Count ) ;
638+ var sure = await App . AskConfirmAsync ( msg ) ;
639+ if ( sure )
640+ await CommitAsync ( autoStage , autoPush , Models . CommitCheckPassed . Filter ) ;
641+ return ;
642+ }
643+
644+ if ( checkPassed < Models . CommitCheckPassed . FileCount && ! _useAmend )
645+ {
646+ if ( ( ! autoStage && _staged . Count == 0 ) || ( autoStage && _cached . Count == 0 ) )
647+ {
648+ await App . ShowDialog ( new ConfirmEmptyCommit ( this , autoPush , _cached . Count ) ) ;
649+ return ;
650+ }
651+ }
652+
653+ IsCommitting = true ;
654+ _repo . Settings . PushCommitMessage ( _commitMessage ) ;
655+ _repo . SetWatcherEnabled ( false ) ;
656+
657+ var signOff = _repo . Settings . EnableSignOffForCommit ;
658+ var log = _repo . CreateLog ( "Commit" ) ;
659+ var succ = true ;
660+ if ( autoStage && _unstaged . Count > 0 )
661+ succ = await new Commands . Add ( _repo . FullPath , _repo . IncludeUntracked ) . Use ( log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
662+
663+ if ( succ )
664+ succ = await new Commands . Commit ( _repo . FullPath , _commitMessage , signOff , _useAmend , _resetAuthor ) . Use ( log ) . RunAsync ( ) . ConfigureAwait ( false ) ;
665+
666+ log . Complete ( ) ;
667+
668+ if ( succ )
669+ {
670+ CommitMessage = string . Empty ;
671+ UseAmend = false ;
672+ if ( autoPush && _repo . Remotes . Count > 0 )
673+ {
674+ Models . Branch pushBranch = null ;
675+ if ( _repo . CurrentBranch == null )
676+ {
677+ var currentBranchName = await new Commands . QueryCurrentBranch ( _repo . FullPath ) . GetResultAsync ( ) ;
678+ pushBranch = new Models . Branch ( ) { Name = currentBranchName } ;
679+ }
680+
681+ if ( _repo . CanCreatePopup ( ) )
682+ _repo . ShowAndStartPopup ( new Push ( _repo , pushBranch ) ) ;
683+ }
684+ }
685+
686+ _repo . MarkBranchesDirtyManually ( ) ;
687+ _repo . SetWatcherEnabled ( true ) ;
688+ IsCommitting = false ;
622689 }
623690
624691 private List < Models . Change > GetVisibleChanges ( List < Models . Change > changes )
@@ -745,102 +812,6 @@ private void SetDetail(Models.Change change, bool isUnstaged)
745812 DetailContext = new DiffContext ( _repo . FullPath , new Models . DiffOption ( change , isUnstaged ) , _detailContext as DiffContext ) ;
746813 }
747814
748- private void DoCommit ( bool autoStage , bool autoPush , CommitCheckPassed checkPassed = CommitCheckPassed . None )
749- {
750- if ( string . IsNullOrWhiteSpace ( _commitMessage ) )
751- return ;
752-
753- if ( ! _repo . CanCreatePopup ( ) )
754- {
755- App . RaiseException ( _repo . FullPath , "Repository has an unfinished job! Please wait!" ) ;
756- return ;
757- }
758-
759- if ( autoStage && HasUnsolvedConflicts )
760- {
761- App . RaiseException ( _repo . FullPath , "Repository has unsolved conflict(s). Auto-stage and commit is disabled!" ) ;
762- return ;
763- }
764-
765- if ( _repo . CurrentBranch is { IsDetachedHead : true } && checkPassed < CommitCheckPassed . DetachedHead )
766- {
767- var msg = App . Text ( "WorkingCopy.ConfirmCommitWithDetachedHead" ) ;
768- _ = App . AskConfirmAsync ( msg , ( ) => DoCommit ( autoStage , autoPush , CommitCheckPassed . DetachedHead ) ) ;
769- return ;
770- }
771-
772- if ( ! string . IsNullOrEmpty ( _filter ) && _staged . Count > _visibleStaged . Count && checkPassed < CommitCheckPassed . Filter )
773- {
774- var msg = App . Text ( "WorkingCopy.ConfirmCommitWithFilter" , _staged . Count , _visibleStaged . Count , _staged . Count - _visibleStaged . Count ) ;
775- _ = App . AskConfirmAsync ( msg , ( ) => DoCommit ( autoStage , autoPush , CommitCheckPassed . Filter ) ) ;
776- return ;
777- }
778-
779- if ( checkPassed < CommitCheckPassed . FileCount && ! _useAmend )
780- {
781- if ( ( ! autoStage && _staged . Count == 0 ) || ( autoStage && _cached . Count == 0 ) )
782- {
783- _ = App . ShowDialog ( new ConfirmEmptyCommit ( _cached . Count > 0 , stageAll => DoCommit ( stageAll , autoPush , CommitCheckPassed . FileCount ) ) ) ;
784- return ;
785- }
786- }
787-
788- IsCommitting = true ;
789- _repo . Settings . PushCommitMessage ( _commitMessage ) ;
790- _repo . SetWatcherEnabled ( false ) ;
791-
792- var signOff = _repo . Settings . EnableSignOffForCommit ;
793- var log = _repo . CreateLog ( "Commit" ) ;
794- Task . Run ( async ( ) =>
795- {
796- var succ = true ;
797- if ( autoStage && _unstaged . Count > 0 )
798- succ = await new Commands . Add ( _repo . FullPath , _repo . IncludeUntracked ) . Use ( log ) . ExecAsync ( ) . ConfigureAwait ( false ) ;
799-
800- if ( succ )
801- succ = await new Commands . Commit ( _repo . FullPath , _commitMessage , signOff , _useAmend , _resetAuthor ) . Use ( log ) . RunAsync ( ) . ConfigureAwait ( false ) ;
802-
803- log . Complete ( ) ;
804-
805- Dispatcher . UIThread . Post ( ( ) =>
806- {
807- if ( succ )
808- {
809- CommitMessage = string . Empty ;
810- UseAmend = false ;
811- if ( autoPush && _repo . Remotes . Count > 0 )
812- PushAfterCommit ( ) ;
813- }
814-
815- _repo . MarkBranchesDirtyManually ( ) ;
816- _repo . SetWatcherEnabled ( true ) ;
817- IsCommitting = false ;
818- } ) ;
819- } ) ;
820- }
821-
822- private void PushAfterCommit ( )
823- {
824- if ( _repo . CurrentBranch == null )
825- {
826- Task . Run ( async ( ) =>
827- {
828- var currentBranchName = await new Commands . QueryCurrentBranch ( _repo . FullPath ) . GetResultAsync ( ) ;
829- var tmp = new Models . Branch ( ) { Name = currentBranchName } ;
830-
831- Dispatcher . UIThread . Post ( ( ) =>
832- {
833- if ( _repo . CanCreatePopup ( ) )
834- _repo . ShowAndStartPopup ( new Push ( _repo , tmp ) ) ;
835- } ) ;
836- } ) ;
837- }
838- else if ( _repo . CanCreatePopup ( ) )
839- {
840- _repo . ShowAndStartPopup ( new Push ( _repo , null ) ) ;
841- }
842- }
843-
844815 private bool IsChanged ( List < Models . Change > old , List < Models . Change > cur )
845816 {
846817 if ( old . Count != cur . Count )
@@ -857,14 +828,6 @@ private bool IsChanged(List<Models.Change> old, List<Models.Change> cur)
857828 return false ;
858829 }
859830
860- private enum CommitCheckPassed
861- {
862- None = 0 ,
863- DetachedHead ,
864- Filter ,
865- FileCount ,
866- }
867-
868831 private Repository _repo = null ;
869832 private bool _isLoadingData = false ;
870833 private bool _isStaging = false ;
0 commit comments