|
6 | 6 | // Copyright 2008 __MyCompanyName__. All rights reserved.
|
7 | 7 | //
|
8 | 8 |
|
| 9 | +#import <Quartz/Quartz.h> |
| 10 | + |
9 | 11 | #import "PBGitCommit.h"
|
10 | 12 | #import "PBGitTree.h"
|
11 | 13 | #import "PBGitRef.h"
|
|
30 | 32 | #import "GLFileView.h"
|
31 | 33 | #import "GitXCommitCopier.h"
|
32 | 34 | #import "NSSplitView+GitX.h"
|
33 |
| -#import <Quartz/Quartz.h> |
34 |
| - |
| 35 | +#import "PBRefMenuItem.h" |
35 | 36 |
|
36 | 37 | #define kHistorySelectedDetailIndexKey @"PBHistorySelectedDetailIndex"
|
37 | 38 | #define kHistoryDetailViewIndex 0
|
@@ -638,37 +639,130 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths
|
638 | 639 |
|
639 | 640 | #pragma mark Repository Methods
|
640 | 641 |
|
641 |
| -- (IBAction) merge:(id)sender |
| 642 | +- (id <PBGitRefish>)refishForSender:(id)sender |
| 643 | +{ |
| 644 | + return [self refishForSender:sender refishTypes:nil]; |
| 645 | +} |
| 646 | + |
| 647 | +- (id <PBGitRefish>)refishForSender:(id)sender refishTypes:(NSArray *)types |
| 648 | +{ |
| 649 | + if ([sender isKindOfClass:[PBRefMenuItem class]]) { |
| 650 | + id <PBGitRefish> refish = [[(PBRefMenuItem *)sender refishs] firstObject]; |
| 651 | + return refish; |
| 652 | + } |
| 653 | + |
| 654 | + if ([types indexOfObject:kGitXCommitType] == NSNotFound) |
| 655 | + return nil; |
| 656 | + |
| 657 | + return self.selectedCommits.firstObject; |
| 658 | +} |
| 659 | + |
| 660 | +- (IBAction)fetchRemote:(id)sender |
| 661 | +{ |
| 662 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]]; |
| 663 | + if (!refish) |
| 664 | + return; |
| 665 | + |
| 666 | + [self.windowController performFetchForRef:refish]; |
| 667 | +} |
| 668 | + |
| 669 | +- (IBAction)pullRemote:(id)sender |
| 670 | +{ |
| 671 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]]; |
| 672 | + if (!refish) |
| 673 | + return; |
| 674 | + |
| 675 | + [self.windowController performPullForBranch:refish remote:nil rebase:NO]; |
| 676 | +} |
| 677 | + |
| 678 | +- (IBAction)pushUpdatesToRemote:(id)sender |
| 679 | +{ |
| 680 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]]; |
| 681 | + if (!refish) |
| 682 | + return; |
| 683 | + |
| 684 | + PBGitRef *remoteRef = nil; // [(PBGitRef *)sender.refishs.firstObject remoteRef]; |
| 685 | + |
| 686 | + [self.windowController performPushForBranch:nil toRemote:remoteRef]; |
| 687 | +} |
| 688 | + |
| 689 | +- (IBAction)pushDefaultRemoteForRef:(id)sender |
| 690 | +{ |
| 691 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]]; |
| 692 | + if (!refish) |
| 693 | + return; |
| 694 | + |
| 695 | + PBGitRef *ref = nil; |
| 696 | + |
| 697 | + [self.windowController performPushForBranch:ref toRemote:nil]; |
| 698 | +} |
| 699 | + |
| 700 | +- (IBAction)pushToRemote:(id)sender |
| 701 | +{ |
| 702 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]]; |
| 703 | + if (!refish) |
| 704 | + return; |
| 705 | + |
| 706 | + PBGitRef *ref = nil; |
| 707 | + NSString *remoteName = [sender representedObject]; |
| 708 | + PBGitRef *remoteRef = [PBGitRef refFromString:[kGitXRemoteRefPrefix stringByAppendingString:remoteName]]; |
| 709 | + |
| 710 | + [self.windowController performPushForBranch:ref toRemote:remoteRef]; |
| 711 | +} |
| 712 | + |
| 713 | +- (IBAction)merge:(id)sender |
| 714 | +{ |
| 715 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType, kGitXCommitType, kGitXTagType]]; |
| 716 | + if (!refish) return; |
| 717 | + |
| 718 | + NSError *error = nil; |
| 719 | + BOOL success = [repository mergeWithRefish:refish error:&error]; |
| 720 | + if (!success) { |
| 721 | + [self.windowController showErrorSheet:error]; |
| 722 | + } |
| 723 | +} |
| 724 | + |
| 725 | +- (IBAction)checkout:(id)sender |
642 | 726 | {
|
643 |
| - PBGitCommit *selectedCommit = self.selectedCommits.firstObject; |
644 |
| - if (!selectedCommit) return; |
| 727 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType, kGitXCommitType, kGitXTagType]]; |
| 728 | + if (!selectedCommits) return; |
645 | 729 |
|
646 | 730 | NSError *error = nil;
|
647 |
| - BOOL success = [repository mergeWithRefish:selectedCommit error:&error]; |
| 731 | + BOOL success = [repository checkoutRefish:refish error:&error]; |
648 | 732 | if (!success) {
|
649 | 733 | [self.windowController showErrorSheet:error];
|
650 | 734 | }
|
651 | 735 | }
|
652 | 736 |
|
653 |
| -- (IBAction) cherryPick:(id)sender |
| 737 | +- (IBAction)cherryPick:(id)sender |
654 | 738 | {
|
655 |
| - PBGitCommit *selectedCommit = self.selectedCommits.firstObject; |
656 |
| - if (!selectedCommit) return; |
| 739 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXCommitType]]; |
| 740 | + if (!refish) return; |
657 | 741 |
|
658 | 742 | NSError *error = nil;
|
659 |
| - BOOL success = [repository cherryPickRefish:selectedCommit error:&error]; |
| 743 | + BOOL success = [repository cherryPickRefish:refish error:&error]; |
660 | 744 | if (!success) {
|
661 | 745 | [self.windowController showErrorSheet:error];
|
662 | 746 | }
|
663 | 747 | }
|
664 | 748 |
|
665 |
| -- (IBAction) rebase:(id)sender |
| 749 | +- (IBAction)rebase:(id)sender |
666 | 750 | {
|
667 |
| - PBGitCommit *selectedCommit = self.selectedCommits.firstObject; |
668 |
| - if (!selectedCommit) return; |
| 751 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]]; |
| 752 | + if (!refish) return; |
669 | 753 |
|
670 | 754 | NSError *error = nil;
|
671 |
| - BOOL success = [repository rebaseBranch:nil onRefish:selectedCommit error:&error]; |
| 755 | + BOOL success = [repository rebaseBranch:nil onRefish:refish error:&error]; |
| 756 | + if (!success) { |
| 757 | + [self.windowController showErrorSheet:error]; |
| 758 | + } |
| 759 | +} |
| 760 | + |
| 761 | +- (IBAction) rebaseHeadBranch:(id)sender |
| 762 | +{ |
| 763 | + id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]]; |
| 764 | + NSError *error = nil; |
| 765 | + BOOL success = [self.repository rebaseBranch:nil onRefish:refish error:&error]; |
672 | 766 | if (!success) {
|
673 | 767 | [self.windowController showErrorSheet:error];
|
674 | 768 | }
|
|
0 commit comments