Skip to content

Commit 6f49819

Browse files
committed
Add menu items for Fetch “Remotename” and Fetch All
* adds Fetch All option * adds Fetch to the menu
1 parent 850fa5c commit 6f49819

File tree

6 files changed

+64
-13
lines changed

6 files changed

+64
-13
lines changed

Classes/Controllers/PBGitSidebarController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
4343

4444
@property(readonly) NSMutableArray *items;
45+
@property(readonly) NSOutlineView *sourceView;
4546
@property(readonly) NSView *sourceListControlsView;
4647
@property(readonly) PBGitHistoryController *historyViewController;
4748
@property(readonly) PBGitCommitController *commitViewController;

Classes/Controllers/PBGitSidebarController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ - (void) updateRemoteControls;
3131

3232
@implementation PBGitSidebarController
3333
@synthesize items;
34+
@synthesize sourceView;
3435
@synthesize sourceListControlsView;
3536
@synthesize historyViewController;
3637
@synthesize commitViewController;
@@ -480,5 +481,4 @@ - (IBAction) fetchPullPushAction:(id)sender
480481
}
481482
}
482483

483-
484484
@end

Classes/Controllers/PBGitWindowController.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@
4545
- (IBAction) revealInFinder:(id)sender;
4646
- (IBAction) openInTerminal:(id)sender;
4747
- (IBAction) refresh:(id)sender;
48+
4849
- (IBAction) showAddRemoteSheet:(id)sender;
50+
51+
- (IBAction) fetchRemote:(id)sender;
52+
- (IBAction) fetchAllRemotes:(id)sender;
53+
4954
- (IBAction) stashSave:(id) sender;
5055
- (IBAction) stashSaveWithKeepIndex:(id) sender;
5156
- (IBAction) stashPop:(id) sender;

Classes/Controllers/PBGitWindowController.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#import "PBGitSidebarController.h"
1616
#import "RJModalRepoSheet.h"
1717
#import "PBAddRemoteSheet.h"
18+
#import "PBSourceViewItem.h"
19+
#import "PBGitRevSpecifier.h"
20+
#import "PBGitRef.h"
1821

1922
@interface PBGitWindowController ()
2023

@@ -64,7 +67,17 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
6467
} else if ([menuItem action] == @selector(showHistoryView:)) {
6568
[menuItem setState:(contentController != sidebarController.commitViewController) ? YES : NO];
6669
return ![repository isBareRepository];
70+
} else if (menuItem.action == @selector(fetchRemote:)) {
71+
NSOutlineView *sourceView = sidebarController.sourceView;
72+
PBSourceViewItem *item = [sourceView itemAtRow:sourceView.selectedRow];
73+
if (item.ref.isRemote) {
74+
menuItem.title = [NSString stringWithFormat:NSLocalizedString(@"Fetch “%@", @"Fetch ”Remote Name“"), item.ref.remoteName];
75+
return YES;
76+
}
77+
menuItem.title = NSLocalizedString(@"Fetch", @"Fetch (without Remote Name for inactive menu item)");
78+
return NO;
6779
}
80+
6881
return YES;
6982
}
7083

@@ -246,6 +259,17 @@ - (IBAction) showAddRemoteSheet:(id)sender
246259
[[[PBAddRemoteSheet alloc] initWithRepository:self.repository] show];
247260
}
248261

262+
263+
- (IBAction) fetchRemote:(id)sender {
264+
NSOutlineView *sourceView = sidebarController.sourceView;
265+
PBSourceViewItem *item = [sourceView itemAtRow:sourceView.selectedRow];
266+
[repository beginFetchFromRemoteForRef:item.ref];
267+
}
268+
269+
- (IBAction) fetchAllRemotes:(id)sender {
270+
[repository beginFetchFromRemoteForRef:nil];
271+
}
272+
249273
- (IBAction) stashSave:(id) sender
250274
{
251275
[repository stashSaveWithKeepIndex:NO];
@@ -269,6 +293,7 @@ - (void)flagsChanged:(NSEvent *)theEvent {
269293
}
270294

271295

296+
272297
#pragma mark -
273298
#pragma mark SplitView Delegates
274299

Classes/git/PBGitRepository.m

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -690,20 +690,27 @@ - (void) beginFetchFromRemoteForRef:(PBGitRef *)ref
690690
{
691691
NSMutableArray *arguments = [NSMutableArray arrayWithObject:@"fetch"];
692692

693-
if (![ref isRemote]) {
694-
NSError *error = nil;
695-
ref = [self remoteRefForBranch:ref error:&error];
696-
if (!ref) {
697-
if (error)
698-
[self.windowController showErrorSheet:error];
699-
return;
693+
NSString * remoteName;
694+
if (ref != nil) {
695+
if (![ref isRemote]) {
696+
NSError *error = nil;
697+
ref = [self remoteRefForBranch:ref error:&error];
698+
if (!ref) {
699+
if (error)
700+
[self.windowController showErrorSheet:error];
701+
return;
702+
}
700703
}
704+
remoteName = [ref remoteName];
705+
[arguments addObject:remoteName];
701706
}
702-
NSString *remoteName = [ref remoteName];
703-
[arguments addObject:remoteName];
704-
705-
NSString *description = [NSString stringWithFormat:@"Fetching all tracking branches from %@", remoteName];
706-
NSString *title = @"Fetching from remote";
707+
else {
708+
remoteName = @"all remotes";
709+
[arguments addObject:@"--all"];
710+
}
711+
712+
NSString *description = [NSString stringWithFormat:@"Fetching all tracking branches for %@", remoteName];
713+
NSString *title = @"Fetching…";
707714
[PBRemoteProgressSheet beginRemoteProgressSheetForArguments:arguments title:title description:description inRepository:self];
708715
}
709716

English.lproj/MainMenu.xib

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,19 @@
389389
</connections>
390390
</menuItem>
391391
<menuItem isSeparatorItem="YES" id="943"/>
392+
<menuItem title="Fetch" id="hAa-UP-Llb">
393+
<modifierMask key="keyEquivalentModifierMask"/>
394+
<connections>
395+
<action selector="fetchRemote:" target="-1" id="zxl-J9-UiW"/>
396+
</connections>
397+
</menuItem>
398+
<menuItem title="Fetch All" id="OAK-L4-wE7">
399+
<modifierMask key="keyEquivalentModifierMask"/>
400+
<connections>
401+
<action selector="fetchAllRemotes:" target="-1" id="gQf-4H-0cg"/>
402+
</connections>
403+
</menuItem>
404+
<menuItem isSeparatorItem="YES" id="bMk-cx-k5H"/>
392405
<menuItem title="Stash Save" keyEquivalent="y" id="Zqy-z5-0Jz">
393406
<connections>
394407
<action selector="stashSave:" target="-1" id="VkG-km-8Nw"/>

0 commit comments

Comments
 (0)