diff --git a/PBGitRepository.h b/PBGitRepository.h index 7e4cd6f0e..0c0849318 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -128,6 +128,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) { - (BOOL) hasRemotes; - (PBGitRef *) remoteRefForBranch:(PBGitRef *)branch error:(NSError **)error; - (NSString *) infoForRemote:(NSString *)remoteName; +- (NSArray*) URLsForRemote:(NSString*)remoteName; - (void) readCurrentBranch; - (PBGitRevSpecifier*) addBranch: (PBGitRevSpecifier*) rev; diff --git a/PBGitRepository.m b/PBGitRepository.m index 69d840529..9569bb551 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -292,6 +292,41 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components [refs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha]; } +// Returns the remote's fetch and pull URLs as an array of two strings. +- (NSArray*) URLsForRemote:(NSString*)remoteName +{ + NSArray *arguments = [NSArray arrayWithObjects:@"remote", @"show", @"-n", remoteName, nil]; + NSString *output = [self outputForArguments:arguments]; + + NSArray *remoteLines = [output componentsSeparatedByString:@"\n"]; + NSString *fetchURL = [remoteLines objectAtIndex:1]; + NSString *pushURL = [remoteLines objectAtIndex:2]; + + if ([fetchURL hasPrefix:@" Fetch URL: "] && [pushURL hasPrefix:@" Push URL: "]) + return [NSArray arrayWithObjects: + [fetchURL substringFromIndex:13], + [pushURL substringFromIndex:13], + nil]; + return nil; +} + +// Extracts the text that should be shown in a help tag. +- (NSString*) helpTextForRef:(PBGitRef*)ref +{ + NSString *output = nil; + NSString *name = [ref shortName]; + NSArray *arguments = nil; + + if ([ref isTag]) { + arguments = [NSArray arrayWithObjects:@"tag", @"-ln", name, nil]; + output = [self outputForArguments:arguments]; + if (![output hasPrefix:name]) + return nil; + return [[output substringFromIndex:[name length]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + } + return nil; +} + - (void) reloadRefs { _headRef = nil; @@ -321,6 +356,7 @@ - (void) reloadRefs PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]]; PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef]; + [revSpec setHelpText:[self helpTextForRef:newRef]]; [self addBranch:revSpec]; [self addRef:newRef fromParameters:components]; [oldBranches removeObject:revSpec]; diff --git a/PBGitRevSpecifier.h b/PBGitRevSpecifier.h index 32e96c491..735627420 100644 --- a/PBGitRevSpecifier.h +++ b/PBGitRevSpecifier.h @@ -11,6 +11,7 @@ @interface PBGitRevSpecifier : NSObject { NSString *description; + NSString *helpText; NSArray *parameters; NSURL *workingDirectory; BOOL isSimpleRef; @@ -36,6 +37,7 @@ + (PBGitRevSpecifier *)localBranchesRevSpec; @property(retain) NSString *description; +@property(retain) NSString *helpText; @property(readonly) NSArray *parameters; @property(retain) NSURL *workingDirectory; @property(readonly) BOOL isSimpleRef; diff --git a/PBGitRevSpecifier.m b/PBGitRevSpecifier.m index 1adc9ed8c..f4c5e3825 100644 --- a/PBGitRevSpecifier.m +++ b/PBGitRevSpecifier.m @@ -11,7 +11,7 @@ @implementation PBGitRevSpecifier -@synthesize parameters, description, workingDirectory; +@synthesize parameters, description, helpText, workingDirectory; @synthesize isSimpleRef; @synthesize behind,ahead; diff --git a/PBGitSVRemoteItem.h b/PBGitSVRemoteItem.h index 8f27532f2..bbae55703 100644 --- a/PBGitSVRemoteItem.h +++ b/PBGitSVRemoteItem.h @@ -12,9 +12,11 @@ @interface PBGitSVRemoteItem : PBSourceViewItem { BOOL alert; + NSString *helpText; } @property (assign) BOOL alert; +@property (retain) NSString *helpText; + (id)remoteItemWithTitle:(NSString *)title; diff --git a/PBGitSVRemoteItem.m b/PBGitSVRemoteItem.m index 0947cfd01..7bf1bcb9f 100644 --- a/PBGitSVRemoteItem.m +++ b/PBGitSVRemoteItem.m @@ -13,6 +13,7 @@ @implementation PBGitSVRemoteItem @synthesize alert; +@synthesize helpText; + (id)remoteItemWithTitle:(NSString *)title { diff --git a/PBGitSidebarController.h b/PBGitSidebarController.h index 64fd60646..59b9b9dab 100644 --- a/PBGitSidebarController.h +++ b/PBGitSidebarController.h @@ -20,9 +20,9 @@ IBOutlet NSPopUpButton *actionButton; IBOutlet NSSegmentedControl *remoteControls; - IBOutlet NSButton* svnFetchButton; - IBOutlet NSButton* svnRebaseButton; - IBOutlet NSButton* svnDcommitButton; + IBOutlet NSButton* svnFetchButton; + IBOutlet NSButton* svnRebaseButton; + IBOutlet NSButton* svnDcommitButton; NSMutableArray *items; diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m index dad7de1b7..276fa758c 100644 --- a/PBGitSidebarController.m +++ b/PBGitSidebarController.m @@ -342,6 +342,11 @@ - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCe [cell setImage:[item icon]]; } +- (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation +{ + return [item helpText]; +} + - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item { return ![item isGroupItem]; @@ -360,6 +365,17 @@ - (BOOL) outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:( return ![item isUncollapsible]; } +- (NSString*) helpTextForRemoteURLs:(NSArray*)urls +{ + NSString *fetchURL = [urls objectAtIndex:0]; + NSString *pushURL = [urls objectAtIndex:1]; + + if ([fetchURL isEqual:pushURL]) + return fetchURL; + else // Down triangle for fetch, up triangle for push + return [NSString stringWithFormat:@"\u25bc %@\n\u25b2", fetchURL, pushURL]; +} + - (void)populateList { PBSourceViewItem *project = [PBSourceViewItem groupItemWithTitle:[repository projectName]]; @@ -379,6 +395,8 @@ - (void)populateList for (PBGitRevSpecifier *rev in repository.branches) [self addRevSpec:rev]; + for (PBGitSVRemoteItem *remote in remotes.children) + [remote setHelpText:[self helpTextForRemoteURLs:[[self repository] URLsForRemote:[remote title]]]]; [items addObject:project]; [items addObject:branches]; diff --git a/PBSourceViewItem.h b/PBSourceViewItem.h index 1547fd6c1..1199802d1 100644 --- a/PBSourceViewItem.h +++ b/PBSourceViewItem.h @@ -30,6 +30,7 @@ + (id)itemWithTitle:(NSString *)title; - (NSString *)badge; +- (NSString *)helpText; - (void)addChild:(PBSourceViewItem *)child; - (void)removeChild:(PBSourceViewItem *)child; diff --git a/PBSourceViewItem.m b/PBSourceViewItem.m index 8c810c0c2..530ece8b2 100644 --- a/PBSourceViewItem.m +++ b/PBSourceViewItem.m @@ -128,6 +128,11 @@ - (NSString *)title return [[revSpecifier description] lastPathComponent]; } +- (NSString *) helpText +{ + return [revSpecifier helpText]; +} + - (NSString *) stringValue { return self.title;