Bug fix: Make new buttons actually work.

Mind you, these buttons cannot operate on the clicked branch like the context menu. 
Instead they always operate on the currently active branch (or its default remote).
This commit is contained in:
André Berg
2009-11-03 04:38:30 +01:00
parent 421d6fd9ed
commit 93a027cccd
4 changed files with 66 additions and 32 deletions
+8 -4
View File
@@ -40,9 +40,13 @@
- (void) selectCurrentBranch;
- (void) updateBranchMenu;
- (void) pullImpl:(NSString *)refName;
- (void) pushImpl:(NSString *)refName;
- (void) rebaseImpl:(NSString *)refName;
- (BOOL) pullImpl:(NSString *)refName;
- (BOOL) pushImpl:(NSString *)refName;
- (BOOL) rebaseImpl:(NSString *)refName;
- (BOOL) fetchImpl:(NSString *)refName;
@end
@interface NSString (PBRefSpecAdditions)
- (NSString *) refForSpec;
@end
+51 -21
View File
@@ -101,61 +101,73 @@
return [PBRefMenuItem defaultMenuItemsForRef:ref commit:commit target:self];
}
- (void) pushImpl:(NSString *)refName
- (BOOL) pushImpl:(NSString *)refName
{
int ret = 1;
BOOL success = NO;
NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
NSString *rval = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"push", remote, refName, nil] retValue: &ret];
if (ret) {
NSString *info = [NSString stringWithFormat:@"There was an error pushing the branch to the remote repository.\n\n%d\n%@", ret, rval];
[[historyController.repository windowController] showMessageSheet:@"Pushing branch failed" infoText:info];
return;
return success;
}
[historyController.repository reloadRefs];
[commitController rearrangeObjects];
success = YES;
return success;
}
- (void) pullImpl:(NSString *)refName
- (BOOL) pullImpl:(NSString *)refName
{
int ret = 1;
BOOL success = NO;
NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
NSString *rval = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"pull", remote, refName, nil] retValue: &ret];
if (ret) {
NSString *info = [NSString stringWithFormat:@"There was an error pulling from the remote repository.\n\n%d\n%@", ret, rval];
[[historyController.repository windowController] showMessageSheet:@"Pulling from remote failed" infoText:info];
return;
return success;
}
[historyController.repository reloadRefs];
[commitController rearrangeObjects];
success = YES;
return success;
}
- (void) rebaseImpl:(NSString *)refName
- (BOOL) rebaseImpl:(NSString *)refName
{
int ret = 1;
NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
NSString *rval = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"pull", @"--rebase", remote, refName, nil] retValue: &ret];
BOOL success = NO;
NSString *remote = [[[historyController repository] config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
NSString *rval = [[historyController repository] outputInWorkdirForArguments:[NSArray arrayWithObjects:@"pull", @"--rebase", remote, refName, nil] retValue: &ret];
if (ret) {
NSString *info = [NSString stringWithFormat:@"There was an error rebasing from the remote repository.\n\n%d\n%@", ret, rval];
[[historyController.repository windowController] showMessageSheet:@"Rebasing from remote failed" infoText:info];
return;
[[[historyController repository] windowController] showMessageSheet:@"Rebasing from remote failed" infoText:info];
return success;
}
[historyController.repository reloadRefs];
[[historyController repository] reloadRefs];
[commitController rearrangeObjects];
success = YES;
return success;
}
- (void) fetchImpl:(NSString *)refName
- (BOOL) fetchImpl:(NSString *)refName
{
int ret = 1;
BOOL success = NO;
NSString *remote = nil;
if(refName != nil) remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
NSString *rval = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"fetch", remote, refName, nil] retValue: &ret];
if (ret) {
NSString *info = [NSString stringWithFormat:@"There was an error fetching from the remote repository.\n\n%d\n%@", ret, rval];
[[historyController.repository windowController] showMessageSheet:@"Rebasing from remote failed" infoText:info];
return;
[[historyController.repository windowController] showMessageSheet:@"Fetching from remote failed" infoText:info];
return success;
}
[historyController.repository reloadRefs];
[commitController rearrangeObjects];
success = YES;
return success;
}
# pragma mark Tableview delegate methods
@@ -253,8 +265,9 @@
-(void)rebaseButton:(id)sender
{
[sender setEnabled:NO];
NSString *refName =[historyController.repository.currentBranch simpleRef];
[self rebaseImpl:refName];
NSString *refName = [[historyController.repository.currentBranch simpleRef] refForSpec];
if (refName)
[self rebaseImpl:refName];
[sender setEnabled:YES];
// NSLog([NSString stringWithFormat:@"Rebase hit for %@!", refName]);
}
@@ -262,8 +275,9 @@
-(void)pushButton:(id)sender
{
[sender setEnabled:NO];
NSString *refName =[historyController.repository.currentBranch simpleRef];
[self pushImpl:refName];
NSString *refName = [[historyController.repository.currentBranch simpleRef] refForSpec];
if (refName)
[self pushImpl:refName];
[sender setEnabled:YES];
// NSLog([NSString stringWithFormat:@"Push hit for %@!", refName]);
}
@@ -271,8 +285,9 @@
-(void)pullButton:(id)sender
{
[sender setEnabled:NO];
NSString *refName =[historyController.repository.currentBranch simpleRef];
[self pullImpl:refName];
NSString *refName = [[historyController.repository.currentBranch simpleRef] refForSpec];
if (refName)
[self pullImpl:refName];
[sender setEnabled:YES];
// NSLog([NSString stringWithFormat:@"Pull hit for %@!", refName]);
}
@@ -280,8 +295,9 @@
-(void)fetchButton:(id)sender
{
[sender setEnabled:NO];
NSString *refName =[historyController.repository.currentBranch simpleRef];
[self fetchImpl:refName];
NSString *refName = [[historyController.repository.currentBranch simpleRef] refForSpec];
if (refName)
[self fetchImpl:refName];
[sender setEnabled:YES];
// NSLog([NSString stringWithFormat:@"Fetch hit for %@!", refName]);
}
@@ -435,3 +451,17 @@
}
@end
@implementation NSString (PBRefSpecAdditions)
/* convenience method to get the last part of a simple refspec like refs/heads/master -> master*/
- (NSString *) refForSpec {
if ([self hasPrefix:@"refs/"]) {
NSArray * parts = [self componentsSeparatedByString:@"/"];
return [parts lastObject];
}
return self;
}
@end
+1 -1
View File
@@ -18,7 +18,7 @@
@property (retain) PBGitCommit *commit;
@property (retain) PBGitRef *ref;
+ (PBRefMenuItem *)addRemoteMethod:(bool)isRemote title:(NSString *)title action:(SEL)selector;
+ (PBRefMenuItem *)addRemoteMethod:(BOOL)isRemote title:(NSString *)title action:(SEL)selector;
+ (NSArray *)defaultMenuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit target:(id)target;
@end
+6 -6
View File
@@ -12,10 +12,10 @@
@implementation PBRefMenuItem
@synthesize ref, commit;
+ (PBRefMenuItem *)addRemoteMethod:(bool)isRemote title:(NSString *)title action:(SEL)selector
+ (PBRefMenuItem *)addRemoteMethod:(BOOL)hasRemote title:(NSString *)title action:(SEL)selector
{
PBRefMenuItem *item = [[PBRefMenuItem alloc] initWithTitle:title action:selector keyEquivalent:@""];
[item setEnabled:isRemote];
[item setEnabled:hasRemote];
return item;
}
@@ -29,12 +29,12 @@
type = @"branch";
NSString *remote = [[[commit repository] config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", [ref shortName]]];
bool has_remote = (remote != NULL) ? YES : NO;
BOOL hasRemote = (remote ? YES : NO);
if ([type isEqualToString:@"branch"]) {
[array addObject:[self addRemoteMethod:has_remote title:@"Push branch to remote" action:@selector(pushRef:)]];
[array addObject:[self addRemoteMethod:has_remote title:@"Pull down latest" action:@selector(pullRef:)]];
[array addObject:[self addRemoteMethod:has_remote title:@"Rebase local changes with latest" action:@selector(rebaseRef:)]];
[array addObject:[self addRemoteMethod:hasRemote title:@"Push branch to remote" action:@selector(pushRef:)]];
[array addObject:[self addRemoteMethod:hasRemote title:@"Pull down latest" action:@selector(pullRef:)]];
[array addObject:[self addRemoteMethod:hasRemote title:@"Rebase local changes with latest" action:@selector(rebaseRef:)]];
}
if ([type isEqualToString:@"branch"])