mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Add Rebase to the contextual menu for commits and refs
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user