Permalink
Browse files

Add support for removing refs

This is somewhat hackish, in that it reloads all commits after deleting
a ref, but at least it works
  • Loading branch information...
1 parent faef971 commit ea3cd7287ce217e1ef44467594dba586aa926567 @pieter committed Sep 22, 2008
Showing with 33 additions and 3 deletions.
  1. +2 −0 PBGitRepository.h
  2. +14 −0 PBGitRepository.m
  3. +17 −3 PBWebGitController.m
View
@@ -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;
View
@@ -307,4 +307,18 @@ - (NSString*) parseSymbolicReference:(NSString*) reference
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
View
@@ -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 @@ + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
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 @@ - (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary
// 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];
}

0 comments on commit ea3cd72

Please sign in to comment.