From 46e996f5c69684ddc84beb3c4c2f07dafa0aaea6 Mon Sep 17 00:00:00 2001 From: Nathan Kinsinger Date: Sat, 6 Feb 2010 19:45:36 -0700 Subject: [PATCH] Add Pull to the contextual menus for refs --- PBGitRepository.h | 1 + PBGitRepository.m | 39 +++++++++++++++++++++++++++++++++++++++ PBRefController.h | 1 + PBRefController.m | 9 +++++++++ PBRefMenuItem.m | 5 +++++ 5 files changed, 55 insertions(+) diff --git a/PBGitRepository.h b/PBGitRepository.h index 8433ff7..5423b24 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -30,6 +30,7 @@ extern NSString* PBGitRepositoryErrorDomain; } - (void) beginFetchFromRemoteForRef:(PBGitRef *)ref; +- (void) beginPullFromRemote:(PBGitRef *)remoteRef forRef:(PBGitRef *)ref; - (BOOL) checkoutRefish:(id )ref; - (BOOL) checkoutFiles:(NSArray *)files fromRefish:(id )ref; - (BOOL) mergeWithRefish:(id )ref; diff --git a/PBGitRepository.m b/PBGitRepository.m index 821b855..6e39bea 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -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 )ref { NSString *refName = nil; diff --git a/PBRefController.h b/PBRefController.h index c4eee08..444faf2 100644 --- a/PBRefController.h +++ b/PBRefController.h @@ -24,6 +24,7 @@ } - (void) fetchRemote:(PBRefMenuItem *)sender; +- (void) pullRemote:(PBRefMenuItem *)sender; - (void) checkout:(PBRefMenuItem *)sender; - (void) merge:(PBRefMenuItem *)sender; diff --git a/PBRefController.m b/PBRefController.m index cb25cb1..635f5c2 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -51,6 +51,15 @@ } +#pragma mark Pull + +- (void) pullRemote:(PBRefMenuItem *)sender +{ + id refish = [sender refish]; + [historyController.repository beginPullFromRemote:nil forRef:refish]; +} + + #pragma mark Merge - (void) merge:(PBRefMenuItem *)sender diff --git a/PBRefMenuItem.m b/PBRefMenuItem.m index ef3d6b1..b670b01 100644 --- a/PBRefMenuItem.m +++ b/PBRefMenuItem.m @@ -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];