Add Rebase to the contextual menu for commits and refs

This commit is contained in:
Nathan Kinsinger
2010-02-06 12:55:51 -07:00
parent e50ddbc503
commit 7eec230959
5 changed files with 47 additions and 0 deletions
+1
View File
@@ -33,6 +33,7 @@ extern NSString* PBGitRepositoryErrorDomain;
- (BOOL) checkoutFiles:(NSArray *)files fromRefish:(id <PBGitRefish>)ref;
- (BOOL) mergeWithRefish:(id <PBGitRefish>)ref;
- (BOOL) cherryPickRefish:(id <PBGitRefish>)ref;
- (BOOL) rebaseBranch:(id <PBGitRefish>)branch onRefish:(id <PBGitRefish>)upstream;
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref;
- (BOOL) createTag:(NSString *)tagName message:(NSString *)message atRefish:(id <PBGitRefish>)commitSHA;
- (BOOL) deleteRef:(PBGitRef *)ref;
+26
View File
@@ -515,6 +515,32 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
return YES;
}
- (BOOL) rebaseBranch:(id <PBGitRefish>)branch onRefish:(id <PBGitRefish>)upstream
{
if (!upstream)
return NO;
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"rebase", [upstream refishName], nil];
if (branch)
[arguments addObject:[branch refishName]];
int retValue = 1;
NSString *output = [self outputInWorkdirForArguments:arguments retValue:&retValue];
if (retValue) {
NSString *branchName = @"HEAD";
if (branch)
branchName = [NSString stringWithFormat:@"%@ '%@'", [branch refishType], [branch shortName]];
NSString *message = [NSString stringWithFormat:@"There was an error rebasing %@ with %@ '%@'.", branchName, [upstream refishType], [upstream shortName]];
[self.windowController showErrorSheetTitle:@"Rebase failed!" message:message arguments:arguments output:output];
return NO;
}
[self reloadRefs];
[self readCurrentBranch];
return YES;
}
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref
{
if (!branchName || !ref)
+1
View File
@@ -26,6 +26,7 @@
- (void) checkout:(PBRefMenuItem *)sender;
- (void) merge:(PBRefMenuItem *)sender;
- (void) cherryPick:(PBRefMenuItem *)sender;
- (void) rebaseHeadBranch:(PBRefMenuItem *)sender;
- (void) createBranch:(PBRefMenuItem *)sender;
- (void) copySHA:(PBRefMenuItem *)sender;
- (void) copyPatch:(PBRefMenuItem *)sender;
+11
View File
@@ -66,6 +66,17 @@
}
#pragma mark Rebase
- (void) rebaseHeadBranch:(PBRefMenuItem *)sender
{
id <PBGitRefish> refish = [sender refish];
PBGitRef *headRef = [[historyController.repository headRef] ref];
[historyController.repository rebaseBranch:headRef onRefish:refish];
}
#pragma mark Create Branch
- (void) createBranch:(PBRefMenuItem *)sender
+8
View File
@@ -66,6 +66,10 @@
NSString *mergeTitle = isOnHeadBranch ? @"Merge" : [NSString stringWithFormat:@"Merge %@ into %@", targetRefName, headRefName];
[items addObject:[PBRefMenuItem itemWithTitle:mergeTitle action:@selector(merge:) enabled:!isOnHeadBranch]];
// rebase
NSString *rebaseTitle = isOnHeadBranch ? @"Rebase" : [NSString stringWithFormat:@"Rebase %@ on %@", headRefName, targetRefName];
[items addObject:[PBRefMenuItem itemWithTitle:rebaseTitle action:@selector(rebaseHeadBranch:) enabled:!isOnHeadBranch]];
// delete ref
[items addObject:[PBRefMenuItem separatorItem]];
NSString *deleteTitle = [NSString stringWithFormat:@"Delete %@…", targetRefName];
@@ -106,6 +110,10 @@
NSString *cherryPickTitle = isOnHeadBranch ? @"Cherry pick commit" : [NSString stringWithFormat:@"Cherry pick commit to %@", headBranchName];
[items addObject:[PBRefMenuItem itemWithTitle:cherryPickTitle action:@selector(cherryPick:) enabled:!isOnHeadBranch]];
// rebase
NSString *rebaseTitle = isOnHeadBranch ? @"Rebase commit" : [NSString stringWithFormat:@"Rebase %@ on commit", headBranchName];
[items addObject:[PBRefMenuItem itemWithTitle:rebaseTitle action:@selector(rebaseHeadBranch:) enabled:!isOnHeadBranch]];
for (PBRefMenuItem *item in items) {
[item setTarget:target];
[item setRefish:commit];