Add Pull to the contextual menus for refs

This commit is contained in:
Nathan Kinsinger
2010-02-06 19:45:36 -07:00
parent 4654dc105f
commit 46e996f5c6
5 changed files with 55 additions and 0 deletions
+1
View File
@@ -30,6 +30,7 @@ extern NSString* PBGitRepositoryErrorDomain;
}
- (void) beginFetchFromRemoteForRef:(PBGitRef *)ref;
- (void) beginPullFromRemote:(PBGitRef *)remoteRef forRef:(PBGitRef *)ref;
- (BOOL) checkoutRefish:(id <PBGitRefish>)ref;
- (BOOL) checkoutFiles:(NSArray *)files fromRefish:(id <PBGitRefish>)ref;
- (BOOL) mergeWithRefish:(id <PBGitRefish>)ref;
+39
View File
@@ -504,6 +504,45 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
[PBRemoteProgressSheet beginRemoteProgressSheetForArguments:arguments title:title description:description inRepository:self];
}
- (void) beginPullFromRemote:(PBGitRef *)remoteRef forRef:(PBGitRef *)ref
{
NSMutableArray *arguments = [NSMutableArray arrayWithObject:@"pull"];
// a nil remoteRef means lookup the ref's default remote
if (!remoteRef || ![remoteRef isRemote]) {
NSError *error = nil;
remoteRef = [self remoteRefForBranch:ref error:&error];
if (!remoteRef) {
if (error)
[self.windowController showErrorSheet:error];
return;
}
}
NSString *remoteName = [remoteRef remoteName];
[arguments addObject:remoteName];
NSString *branchName = nil;
NSString *refSpec = nil;
if ([ref isRemoteBranch]) {
branchName = [ref shortName];
refSpec = [ref remoteBranchName];
}
else if ([ref isRemote] || !ref) {
branchName = @"all tracking branches";
}
else {
branchName = [ref shortName];
refSpec = [NSString stringWithFormat:@"%@:%@", branchName, branchName];
}
if (refSpec)
[arguments addObject:refSpec];
NSString *headRefName = [[[self headRef] ref] shortName];
NSString *description = [NSString stringWithFormat:@"Pulling %@ from %@ and updating %@", branchName, remoteName, headRefName];
NSString *title = @"Pulling from remote";
[PBRemoteProgressSheet beginRemoteProgressSheetForArguments:arguments title:title description:description inRepository:self];
}
- (BOOL) checkoutRefish:(id <PBGitRefish>)ref
{
NSString *refName = nil;
+1
View File
@@ -24,6 +24,7 @@
}
- (void) fetchRemote:(PBRefMenuItem *)sender;
- (void) pullRemote:(PBRefMenuItem *)sender;
- (void) checkout:(PBRefMenuItem *)sender;
- (void) merge:(PBRefMenuItem *)sender;
+9
View File
@@ -51,6 +51,15 @@
}
#pragma mark Pull
- (void) pullRemote:(PBRefMenuItem *)sender
{
id <PBGitRefish> refish = [sender refish];
[historyController.repository beginPullFromRemote:nil forRef:refish];
}
#pragma mark Merge
- (void) merge:(PBRefMenuItem *)sender
+5
View File
@@ -83,6 +83,11 @@
NSString *fetchTitle = hasRemote ? [NSString stringWithFormat:@"Fetch %@", remoteName] : @"Fetch";
[items addObject:[PBRefMenuItem itemWithTitle:fetchTitle action:@selector(fetchRemote:) enabled:hasRemote]];
// pull
NSString *pullRemoteName = [ref isRemoteBranch] ? [ref shortName] : remoteName;
NSString *pullTitle = hasRemote ? [NSString stringWithFormat:@"Pull %@ and update %@", pullRemoteName, headRefName] : @"Pull";
[items addObject:[PBRefMenuItem itemWithTitle:pullTitle action:@selector(pullRemote:) enabled:hasRemote]];
// delete ref
[items addObject:[PBRefMenuItem separatorItem]];
NSString *deleteTitle = [NSString stringWithFormat:@"Delete %@…", targetRefName];