From ea3cd7287ce217e1ef44467594dba586aa926567 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Mon, 22 Sep 2008 21:12:26 +0200 Subject: [PATCH] Add support for removing refs This is somewhat hackish, in that it reloads all commits after deleting a ref, but at least it works --- PBGitRepository.h | 2 ++ PBGitRepository.m | 14 ++++++++++++++ PBWebGitController.m | 20 +++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/PBGitRepository.h b/PBGitRepository.h index 78d0712..1dd820b 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -28,6 +28,8 @@ extern NSString* PBGitRepositoryErrorDomain; - (BOOL) reloadRefs; - (void) addRef:(PBGitRef *)ref fromParameters:(NSArray *)params; +- (BOOL) removeRef:(NSString *)ref; + - (void) readCurrentBranch; - (PBGitRevSpecifier*) addBranch: (PBGitRevSpecifier*) rev; - (void) selectBranch: (PBGitRevSpecifier*) rev; diff --git a/PBGitRepository.m b/PBGitRepository.m index 03633fd..818edb3 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -307,4 +307,18 @@ static NSString* gitPath; return nil; } + +- (BOOL) removeRef:(NSString *)ref +{ + int i; + [self outputForArguments:[NSArray arrayWithObjects:@"branch", @"-D", ref, nil] retValue:&i]; + + if (i == 0) { + // Todo: We can do better than this! + [self reloadRefs]; + [revisionList reload]; + return YES; + } + return NO; +} @end diff --git a/PBWebGitController.m b/PBWebGitController.m index 7a4e8d1..14cc620 100644 --- a/PBWebGitController.m +++ b/PBWebGitController.m @@ -7,6 +7,15 @@ // #import "PBWebGitController.h" +@interface RefMenuItem : NSMenuItem +{ + NSString *ref; +} +@property (copy) NSString *ref; +@end +@implementation RefMenuItem +@synthesize ref; +@end @implementation PBWebGitController @@ -95,9 +104,13 @@ return NO; } -- (void) removeRef: (id) sender +- (void) removeRef:(RefMenuItem *)sender { - NSLog(@"Removing refs is not yet supported"); + NSLog(@"Removing ref: %@", [sender ref]); + if ([historyController.repository removeRef: [sender ref]]) + NSLog(@"Deletion succesful!"); + else + NSLog(@"Deletion failed!"); } - (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems { @@ -108,8 +121,9 @@ // Every ref has a class name of 'refs' and some other class. We check on that to see if we pressed on a ref. if ([[node className] hasPrefix:@"refs "]) { - NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Remove" action:@selector(removeRef:) keyEquivalent: @""]; + RefMenuItem *item = [[RefMenuItem alloc] initWithTitle:@"Remove" action:@selector(removeRef:) keyEquivalent: @""]; [item setTarget: self]; + [item setRef: [[[node childNodes] item:0] textContent]]; return [NSArray arrayWithObject: item]; }