@@ -459,6 +459,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
459459
460460 var menu = new ContextMenu ( ) ;
461461 var tags = new List < Models . Tag > ( ) ;
462+ var isHead = commit . IsCurrentHead ;
462463
463464 if ( commit . HasDecorators )
464465 {
@@ -525,32 +526,14 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
525526 {
526527 var target = commit . GetFriendlyName ( ) ;
527528
528- if ( current . Head != commit . SHA )
529- {
530- var reset = new MenuItem ( ) ;
531- reset . Header = App . Text ( "CommitCM.Reset" , current . Name , target ) ;
532- reset . Icon = App . CreateMenuIcon ( "Icons.Reset" ) ;
533- reset . Click += ( _ , e ) =>
534- {
535- if ( repo . CanCreatePopup ( ) )
536- repo . ShowPopup ( new ViewModels . Reset ( repo , current , commit ) ) ;
537- e . Handled = true ;
538- } ;
539- menu . Items . Add ( reset ) ;
540- }
541- else
529+ if ( isHead )
542530 {
543531 var reword = new MenuItem ( ) ;
544532 reword . Header = App . Text ( "CommitCM.Reword" ) ;
545533 reword . Icon = App . CreateMenuIcon ( "Icons.Edit" ) ;
546534 reword . Click += async ( _ , e ) =>
547535 {
548- if ( repo . CanCreatePopup ( ) )
549- {
550- var message = await new Commands . QueryCommitFullMessage ( repo . FullPath , commit . SHA ) . GetResultAsync ( ) ;
551- repo . ShowPopup ( new ViewModels . Reword ( repo , commit , message ) ) ;
552- }
553-
536+ await vm . RewordHeadAsync ( commit ) ;
554537 e . Handled = true ;
555538 } ;
556539 menu . Items . Add ( reword ) ;
@@ -561,18 +544,24 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
561544 squash . IsEnabled = commit . Parents . Count == 1 ;
562545 squash . Click += async ( _ , e ) =>
563546 {
564- if ( commit . Parents . Count == 1 )
565- {
566- var message = await new Commands . QueryCommitFullMessage ( repo . FullPath , commit . SHA ) . GetResultAsync ( ) ;
567- var parent = vm . Commits . Find ( x => x . SHA . Equals ( commit . Parents [ 0 ] ) ) ;
568- if ( parent != null && repo . CanCreatePopup ( ) )
569- repo . ShowPopup ( new ViewModels . Squash ( repo , parent , message ) ) ;
570- }
571-
547+ await vm . SquashHeadAsync ( commit ) ;
572548 e . Handled = true ;
573549 } ;
574550 menu . Items . Add ( squash ) ;
575551 }
552+ else
553+ {
554+ var reset = new MenuItem ( ) ;
555+ reset . Header = App . Text ( "CommitCM.Reset" , current . Name , target ) ;
556+ reset . Icon = App . CreateMenuIcon ( "Icons.Reset" ) ;
557+ reset . Click += ( _ , e ) =>
558+ {
559+ if ( repo . CanCreatePopup ( ) )
560+ repo . ShowPopup ( new ViewModels . Reset ( repo , current , commit ) ) ;
561+ e . Handled = true ;
562+ } ;
563+ menu . Items . Add ( reset ) ;
564+ }
576565
577566 if ( ! commit . IsMerged )
578567 {
@@ -607,29 +596,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
607596 cherryPick . Icon = App . CreateMenuIcon ( "Icons.CherryPick" ) ;
608597 cherryPick . Click += async ( _ , e ) =>
609598 {
610- if ( repo . CanCreatePopup ( ) )
611- {
612- if ( commit . Parents . Count <= 1 )
613- {
614- repo . ShowPopup ( new ViewModels . CherryPick ( repo , [ commit ] ) ) ;
615- }
616- else
617- {
618- var parents = new List < Models . Commit > ( ) ;
619- foreach ( var sha in commit . Parents )
620- {
621- var parent = vm . Commits . Find ( x => x . SHA == sha ) ;
622- if ( parent == null )
623- parent = await new Commands . QuerySingleCommit ( repo . FullPath , sha ) . GetResultAsync ( ) ;
624-
625- if ( parent != null )
626- parents . Add ( parent ) ;
627- }
628-
629- repo . ShowPopup ( new ViewModels . CherryPick ( repo , commit , parents ) ) ;
630- }
631- }
632-
599+ await vm . CherryPickAsync ( commit ) ;
633600 e . Handled = true ;
634601 } ;
635602 menu . Items . Add ( cherryPick ) ;
@@ -648,7 +615,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
648615 menu . Items . Add ( revert ) ;
649616 }
650617
651- if ( current . Head != commit . SHA )
618+ if ( ! isHead )
652619 {
653620 var checkoutCommit = new MenuItem ( ) ;
654621 checkoutCommit . Header = App . Text ( "CommitCM.Checkout" ) ;
@@ -679,57 +646,39 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
679646 reword . Header = App . Text ( "CommitCM.InteractiveRebase.Reword" ) ;
680647 reword . Click += async ( _ , e ) =>
681648 {
682- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Reword ) ;
683- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~") . GetResultAsync ( ) ;
684- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
649+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Reword ) ;
685650 e . Handled = true ;
686651 } ;
687652
688653 var edit = new MenuItem ( ) ;
689654 edit . Header = App . Text ( "CommitCM.InteractiveRebase.Edit" ) ;
690655 edit . Click += async ( _ , e ) =>
691656 {
692- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Edit ) ;
693- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~") . GetResultAsync ( ) ;
694- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
657+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Edit ) ;
695658 e . Handled = true ;
696659 } ;
697660
698661 var squash = new MenuItem ( ) ;
699662 squash . Header = App . Text ( "CommitCM.InteractiveRebase.Squash" ) ;
700663 squash . Click += async ( _ , e ) =>
701664 {
702- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Squash ) ;
703- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~~") . GetResultAsync ( ) ;
704- if ( on != null )
705- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
706- else
707- App . RaiseException ( repo . FullPath , $ "Can not squash current commit into parent!") ;
708-
665+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Squash ) ;
709666 e . Handled = true ;
710667 } ;
711668
712669 var fixup = new MenuItem ( ) ;
713670 fixup . Header = App . Text ( "CommitCM.InteractiveRebase.Fixup" ) ;
714671 fixup . Click += async ( _ , e ) =>
715672 {
716- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Fixup ) ;
717- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~~") . GetResultAsync ( ) ;
718- if ( on != null )
719- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
720- else
721- App . RaiseException ( repo . FullPath , $ "Can not fixup current commit into parent!") ;
722-
673+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Fixup ) ;
723674 e . Handled = true ;
724675 } ;
725676
726677 var drop = new MenuItem ( ) ;
727678 drop . Header = App . Text ( "CommitCM.InteractiveRebase.Drop" ) ;
728679 drop . Click += async ( _ , e ) =>
729680 {
730- var prefill = new ViewModels . InteractiveRebasePrefill ( commit . SHA , Models . InteractiveRebaseAction . Drop ) ;
731- var on = await new Commands . QuerySingleCommit ( repo . FullPath , $ "{ commit . SHA } ~") . GetResultAsync ( ) ;
732- await App . ShowDialog ( new ViewModels . InteractiveRebase ( repo , on , prefill ) ) ;
681+ await vm . InteractiveRebaseAsync ( commit , Models . InteractiveRebaseAction . Drop ) ;
733682 e . Handled = true ;
734683 } ;
735684
@@ -763,7 +712,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
763712 menu . Items . Add ( new MenuItem ( ) { Header = "-" } ) ;
764713 }
765714
766- if ( current . Head != commit . SHA )
715+ if ( ! isHead )
767716 {
768717 if ( current . TrackStatus . Ahead . Contains ( commit . SHA ) )
769718 {
@@ -786,18 +735,9 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
786735 compareWithHead . Icon = App . CreateMenuIcon ( "Icons.Compare" ) ;
787736 compareWithHead . Click += async ( _ , e ) =>
788737 {
789- var head = vm . Commits . Find ( x => x . SHA == current . Head ) ;
790- if ( head == null )
791- {
792- repo . SelectedSearchedCommit = null ;
793- head = await new Commands . QuerySingleCommit ( repo . FullPath , current . Head ) . GetResultAsync ( ) ;
794- if ( head != null )
795- vm . DetailContext = new ViewModels . RevisionCompare ( repo . FullPath , commit , head ) ;
796- }
797- else
798- {
738+ var head = await vm . CompareWithHeadAsync ( commit ) ;
739+ if ( head != null )
799740 CommitListContainer . SelectedItems . Add ( head ) ;
800- }
801741
802742 e . Handled = true ;
803743 } ;
@@ -810,7 +750,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
810750 compareWithWorktree . Icon = App . CreateMenuIcon ( "Icons.Compare" ) ;
811751 compareWithWorktree . Click += ( _ , e ) =>
812752 {
813- vm . DetailContext = new ViewModels . RevisionCompare ( repo . FullPath , commit , null ) ;
753+ vm . CompareWithWorktree ( commit ) ;
814754 e . Handled = true ;
815755 } ;
816756 menu . Items . Add ( compareWithWorktree ) ;
@@ -920,8 +860,7 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
920860 copyMessage . Icon = App . CreateMenuIcon ( "Icons.Info" ) ;
921861 copyMessage . Click += async ( _ , e ) =>
922862 {
923- var message = await new Commands . QueryCommitFullMessage ( repo . FullPath , commit . SHA ) . GetResultAsync ( ) ;
924- await App . CopyTextAsync ( message ) ;
863+ await vm . CopyCommitFullMessageAsync ( commit ) ;
925864 e . Handled = true ;
926865 } ;
927866
0 commit comments