@@ -291,7 +291,7 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
291
291
ev . Handled = true ;
292
292
} ;
293
293
294
- var fullPath = Path . Combine ( _repo . FullPath , change . Path ) ;
294
+ var fullPath = Native . OS . GetAbsPath ( _repo . FullPath , change . Path ) ;
295
295
var explore = new MenuItem ( ) ;
296
296
explore . Header = App . Text ( "RevealFile" ) ;
297
297
explore . Icon = App . CreateMenuIcon ( "Icons.Explore" ) ;
@@ -362,35 +362,27 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
362
362
var resetToThisRevision = new MenuItem ( ) ;
363
363
resetToThisRevision . Header = App . Text ( "ChangeCM.CheckoutThisRevision" ) ;
364
364
resetToThisRevision . Icon = App . CreateMenuIcon ( "Icons.File.Checkout" ) ;
365
- resetToThisRevision . Click += ( _ , ev ) =>
365
+ resetToThisRevision . Click += async ( _ , ev ) =>
366
366
{
367
- var log = _repo . CreateLog ( $ "Reset File to '{ _commit . SHA } '") ;
368
- new Commands . Checkout ( _repo . FullPath ) . Use ( log ) . FileWithRevision ( change . Path , $ "{ _commit . SHA } ") ;
369
- log . Complete ( ) ;
367
+ await ResetToThisRevision ( change . Path ) ;
370
368
ev . Handled = true ;
371
369
} ;
372
370
373
371
var resetToFirstParent = new MenuItem ( ) ;
374
372
resetToFirstParent . Header = App . Text ( "ChangeCM.CheckoutFirstParentRevision" ) ;
375
373
resetToFirstParent . Icon = App . CreateMenuIcon ( "Icons.File.Checkout" ) ;
376
374
resetToFirstParent . IsEnabled = _commit . Parents . Count > 0 ;
377
- resetToFirstParent . Click += ( _ , ev ) =>
375
+ resetToFirstParent . Click += async ( _ , ev ) =>
378
376
{
379
- var log = _repo . CreateLog ( $ "Reset File to '{ _commit . SHA } ~1'") ;
380
- if ( change . Index == Models . ChangeState . Renamed )
381
- new Commands . Checkout ( _repo . FullPath ) . Use ( log ) . FileWithRevision ( change . OriginalPath , $ "{ _commit . SHA } ~1") ;
382
-
383
- new Commands . Checkout ( _repo . FullPath ) . Use ( log ) . FileWithRevision ( change . Path , $ "{ _commit . SHA } ~1") ;
384
- log . Complete ( ) ;
377
+ await ResetToParentRevision ( change ) ;
385
378
ev . Handled = true ;
386
379
} ;
387
380
388
381
menu . Items . Add ( resetToThisRevision ) ;
389
382
menu . Items . Add ( resetToFirstParent ) ;
390
383
menu . Items . Add ( new MenuItem { Header = "-" } ) ;
391
384
392
- if ( File . Exists ( Path . Combine ( fullPath ) ) )
393
- TryToAddContextMenuItemsForGitLFS ( menu , change . Path ) ;
385
+ TryToAddContextMenuItemsForGitLFS ( menu , fullPath , change . Path ) ;
394
386
}
395
387
396
388
var copyPath = new MenuItem ( ) ;
@@ -407,7 +399,7 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
407
399
copyFullPath . Icon = App . CreateMenuIcon ( "Icons.Copy" ) ;
408
400
copyFullPath . Click += ( _ , e ) =>
409
401
{
410
- App . CopyText ( Native . OS . GetAbsPath ( _repo . FullPath , change . Path ) ) ;
402
+ App . CopyText ( fullPath ) ;
411
403
e . Handled = true ;
412
404
} ;
413
405
@@ -419,7 +411,7 @@ public ContextMenu CreateChangeContextMenu(Models.Change change)
419
411
public ContextMenu CreateRevisionFileContextMenu ( Models . Object file )
420
412
{
421
413
var menu = new ContextMenu ( ) ;
422
- var fullPath = Path . Combine ( _repo . FullPath , file . Path ) ;
414
+ var fullPath = Native . OS . GetAbsPath ( _repo . FullPath , file . Path ) ;
423
415
var explore = new MenuItem ( ) ;
424
416
explore . Header = App . Text ( "RevealFile" ) ;
425
417
explore . Icon = App . CreateMenuIcon ( "Icons.Explore" ) ;
@@ -499,38 +491,34 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
499
491
menu . Items . Add ( blame ) ;
500
492
menu . Items . Add ( new MenuItem ( ) { Header = "-" } ) ;
501
493
502
- var resetToThisRevision = new MenuItem ( ) ;
503
- resetToThisRevision . Header = App . Text ( "ChangeCM.CheckoutThisRevision" ) ;
504
- resetToThisRevision . Icon = App . CreateMenuIcon ( "Icons.File.Checkout" ) ;
505
- resetToThisRevision . IsEnabled = File . Exists ( fullPath ) ;
506
- resetToThisRevision . Click += ( _ , ev ) =>
494
+ if ( ! _repo . IsBare )
507
495
{
508
- var log = _repo . CreateLog ( $ "Reset File to '{ _commit . SHA } '") ;
509
- new Commands . Checkout ( _repo . FullPath ) . Use ( log ) . FileWithRevision ( file . Path , $ "{ _commit . SHA } ") ;
510
- log . Complete ( ) ;
511
- ev . Handled = true ;
512
- } ;
496
+ var resetToThisRevision = new MenuItem ( ) ;
497
+ resetToThisRevision . Header = App . Text ( "ChangeCM.CheckoutThisRevision" ) ;
498
+ resetToThisRevision . Icon = App . CreateMenuIcon ( "Icons.File.Checkout" ) ;
499
+ resetToThisRevision . Click += async ( _ , ev ) =>
500
+ {
501
+ await ResetToThisRevision ( file . Path ) ;
502
+ ev . Handled = true ;
503
+ } ;
513
504
514
- var resetToFirstParent = new MenuItem ( ) ;
515
- resetToFirstParent . Header = App . Text ( "ChangeCM.CheckoutFirstParentRevision" ) ;
516
- resetToFirstParent . Icon = App . CreateMenuIcon ( "Icons.File.Checkout" ) ;
517
- var fileInChanges = _changes . Find ( x => x . Path == file . Path ) ;
518
- var fileIndex = fileInChanges ? . Index ;
519
- resetToFirstParent . IsEnabled = _commit . Parents . Count > 0 && fileIndex != Models . ChangeState . Renamed ;
520
- resetToFirstParent . Click += ( _ , ev ) =>
521
- {
522
- var log = _repo . CreateLog ( $ "Reset File to '{ _commit . SHA } ~1'") ;
523
- new Commands . Checkout ( _repo . FullPath ) . Use ( log ) . FileWithRevision ( file . Path , $ "{ _commit . SHA } ~1") ;
524
- log . Complete ( ) ;
525
- ev . Handled = true ;
526
- } ;
505
+ var change = _changes . Find ( x => x . Path == file . Path ) ?? new Models . Change ( ) { Index = Models . ChangeState . None , Path = file . Path } ;
506
+ var resetToFirstParent = new MenuItem ( ) ;
507
+ resetToFirstParent . Header = App . Text ( "ChangeCM.CheckoutFirstParentRevision" ) ;
508
+ resetToFirstParent . Icon = App . CreateMenuIcon ( "Icons.File.Checkout" ) ;
509
+ resetToFirstParent . IsEnabled = _commit . Parents . Count > 0 ;
510
+ resetToFirstParent . Click += async ( _ , ev ) =>
511
+ {
512
+ await ResetToParentRevision ( change ) ;
513
+ ev . Handled = true ;
514
+ } ;
527
515
528
- menu . Items . Add ( resetToThisRevision ) ;
529
- menu . Items . Add ( resetToFirstParent ) ;
530
- menu . Items . Add ( new MenuItem ( ) { Header = "-" } ) ;
516
+ menu . Items . Add ( resetToThisRevision ) ;
517
+ menu . Items . Add ( resetToFirstParent ) ;
518
+ menu . Items . Add ( new MenuItem ( ) { Header = "-" } ) ;
531
519
532
- if ( File . Exists ( Path . Combine ( fullPath ) ) )
533
- TryToAddContextMenuItemsForGitLFS ( menu , file . Path ) ;
520
+ TryToAddContextMenuItemsForGitLFS ( menu , fullPath , file . Path ) ;
521
+ }
534
522
535
523
var copyPath = new MenuItem ( ) ;
536
524
copyPath . Header = App . Text ( "CopyPath" ) ;
@@ -546,7 +534,7 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
546
534
copyFullPath . Icon = App . CreateMenuIcon ( "Icons.Copy" ) ;
547
535
copyFullPath . Click += ( _ , e ) =>
548
536
{
549
- App . CopyText ( Native . OS . GetAbsPath ( _repo . FullPath , file . Path ) ) ;
537
+ App . CopyText ( fullPath ) ;
550
538
e . Handled = true ;
551
539
} ;
552
540
@@ -725,8 +713,11 @@ private void RefreshVisibleChanges()
725
713
}
726
714
}
727
715
728
- private void TryToAddContextMenuItemsForGitLFS ( ContextMenu menu , string path )
716
+ private void TryToAddContextMenuItemsForGitLFS ( ContextMenu menu , string fullPath , string path )
729
717
{
718
+ if ( _repo . Remotes . Count == 0 || ! File . Exists ( fullPath ) )
719
+ return ;
720
+
730
721
var lfsEnabled = new Commands . LFS ( _repo . FullPath ) . IsEnabled ( ) ;
731
722
if ( ! lfsEnabled )
732
723
return ;
@@ -738,7 +729,6 @@ private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path)
738
729
var lfsLock = new MenuItem ( ) ;
739
730
lfsLock . Header = App . Text ( "GitLFS.Locks.Lock" ) ;
740
731
lfsLock . Icon = App . CreateMenuIcon ( "Icons.Lock" ) ;
741
- lfsLock . IsEnabled = _repo . Remotes . Count > 0 ;
742
732
if ( _repo . Remotes . Count == 1 )
743
733
{
744
734
lfsLock . Click += async ( _ , e ) =>
@@ -777,7 +767,6 @@ private void TryToAddContextMenuItemsForGitLFS(ContextMenu menu, string path)
777
767
var lfsUnlock = new MenuItem ( ) ;
778
768
lfsUnlock . Header = App . Text ( "GitLFS.Locks.Unlock" ) ;
779
769
lfsUnlock . Icon = App . CreateMenuIcon ( "Icons.Unlock" ) ;
780
- lfsUnlock . IsEnabled = _repo . Remotes . Count > 0 ;
781
770
if ( _repo . Remotes . Count == 1 )
782
771
{
783
772
lfsUnlock . Click += async ( _ , e ) =>
@@ -867,6 +856,31 @@ private void CalcRevisionFileSearchSuggestion()
867
856
RevisionFileSearchSuggestion = suggestion ;
868
857
}
869
858
859
+ private Task ResetToThisRevision ( string path )
860
+ {
861
+ var log = _repo . CreateLog ( $ "Reset File to '{ _commit . SHA } '") ;
862
+
863
+ return Task . Run ( ( ) =>
864
+ {
865
+ new Commands . Checkout ( _repo . FullPath ) . Use ( log ) . FileWithRevision ( path , $ "{ _commit . SHA } ") ;
866
+ log . Complete ( ) ;
867
+ } ) ;
868
+ }
869
+
870
+ private Task ResetToParentRevision ( Models . Change change )
871
+ {
872
+ var log = _repo . CreateLog ( $ "Reset File to '{ _commit . SHA } ~1'") ;
873
+
874
+ return Task . Run ( ( ) =>
875
+ {
876
+ if ( change . Index == Models . ChangeState . Renamed )
877
+ new Commands . Checkout ( _repo . FullPath ) . Use ( log ) . FileWithRevision ( change . OriginalPath , $ "{ _commit . SHA } ~1") ;
878
+
879
+ new Commands . Checkout ( _repo . FullPath ) . Use ( log ) . FileWithRevision ( change . Path , $ "{ _commit . SHA } ~1") ;
880
+ log . Complete ( ) ;
881
+ } ) ;
882
+ }
883
+
870
884
[ GeneratedRegex ( @"\b(https?://|ftp://)[\w\d\._/\-~%@()+:?&=#!]*[\w\d/]" ) ]
871
885
private static partial Regex REG_URL_FORMAT ( ) ;
872
886
0 commit comments