mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Add Merge in the contextual menus for commits and refs
This commit is contained in:
@@ -31,6 +31,7 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
|
||||
- (BOOL) checkoutRefish:(id <PBGitRefish>)ref;
|
||||
- (BOOL) checkoutFiles:(NSArray *)files fromRefish:(id <PBGitRefish>)ref;
|
||||
- (BOOL) mergeWithRefish:(id <PBGitRefish>)ref;
|
||||
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref;
|
||||
- (BOOL) createTag:(NSString *)tagName message:(NSString *)message atRefish:(id <PBGitRefish>)commitSHA;
|
||||
- (BOOL) deleteRef:(PBGitRef *)ref;
|
||||
|
||||
@@ -474,6 +474,26 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) mergeWithRefish:(id <PBGitRefish>)ref
|
||||
{
|
||||
NSString *refName = [ref refishName];
|
||||
|
||||
int retValue = 1;
|
||||
NSArray *arguments = [NSArray arrayWithObjects:@"merge", refName, nil];
|
||||
NSString *output = [self outputInWorkdirForArguments:arguments retValue:&retValue];
|
||||
if (retValue) {
|
||||
NSString *headName = [[[self headRef] ref] shortName];
|
||||
NSString *message = [NSString stringWithFormat:@"There was an error merging %@ into %@.", refName, headName];
|
||||
[self.windowController showErrorSheetTitle:@"Merge 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)
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
}
|
||||
|
||||
- (void) checkout:(PBRefMenuItem *)sender;
|
||||
- (void) merge:(PBRefMenuItem *)sender;
|
||||
- (void) createBranch:(PBRefMenuItem *)sender;
|
||||
- (void) copySHA:(PBRefMenuItem *)sender;
|
||||
- (void) copyPatch:(PBRefMenuItem *)sender;
|
||||
|
||||
@@ -39,6 +39,15 @@
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Merge
|
||||
|
||||
- (void) merge:(PBRefMenuItem *)sender
|
||||
{
|
||||
id <PBGitRefish> refish = [sender refish];
|
||||
[historyController.repository mergeWithRefish:refish];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Checkout
|
||||
|
||||
- (void) checkout:(PBRefMenuItem *)sender
|
||||
|
||||
@@ -39,8 +39,11 @@
|
||||
NSMutableArray *items = [NSMutableArray array];
|
||||
|
||||
NSString *targetRefName = [ref shortName];
|
||||
PBGitCommit *commit = [repo commitForRef:ref];
|
||||
BOOL isOnHeadBranch = [commit isOnHeadBranch];
|
||||
|
||||
PBGitRef *headRef = [[repo headRef] ref];
|
||||
NSString *headRefName = [headRef shortName];
|
||||
BOOL isHead = [ref isEqualToRef:headRef];
|
||||
|
||||
// checkout ref
|
||||
@@ -57,6 +60,11 @@
|
||||
// view tag info
|
||||
if ([ref isTag])
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:@"View tag info…" action:@selector(showTagInfoSheet:) enabled:YES]];
|
||||
[items addObject:[PBRefMenuItem separatorItem]];
|
||||
|
||||
// merge ref
|
||||
NSString *mergeTitle = isOnHeadBranch ? @"Merge" : [NSString stringWithFormat:@"Merge %@ into %@", targetRefName, headRefName];
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:mergeTitle action:@selector(merge:) enabled:!isOnHeadBranch]];
|
||||
|
||||
// delete ref
|
||||
[items addObject:[PBRefMenuItem separatorItem]];
|
||||
@@ -76,6 +84,9 @@
|
||||
{
|
||||
NSMutableArray *items = [NSMutableArray array];
|
||||
|
||||
NSString *headBranchName = [[[commit.repository headRef] ref] shortName];
|
||||
BOOL isOnHeadBranch = [commit isOnHeadBranch];
|
||||
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:@"Checkout Commit" action:@selector(checkout:) enabled:YES]];
|
||||
[items addObject:[PBRefMenuItem separatorItem]];
|
||||
|
||||
@@ -85,6 +96,11 @@
|
||||
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:@"Copy SHA" action:@selector(copySHA:) enabled:YES]];
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:@"Copy Patch" action:@selector(copyPatch:) enabled:YES]];
|
||||
[items addObject:[PBRefMenuItem separatorItem]];
|
||||
|
||||
// merge commit
|
||||
NSString *mergeTitle = isOnHeadBranch ? @"Merge commit" : [NSString stringWithFormat:@"Merge commit into %@", headBranchName];
|
||||
[items addObject:[PBRefMenuItem itemWithTitle:mergeTitle action:@selector(merge:) enabled:!isOnHeadBranch]];
|
||||
|
||||
for (PBRefMenuItem *item in items) {
|
||||
[item setTarget:target];
|
||||
|
||||
Reference in New Issue
Block a user