From 57dc38f58786f194e4cfe990d6bd6be1e4565de9 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sun, 13 Sep 2009 02:57:48 +0200 Subject: [PATCH] GitIndex: Add support for applying patches --- PBGitIndex.h | 2 +- PBGitIndex.m | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/PBGitIndex.h b/PBGitIndex.h index 261b226..a358f5a 100644 --- a/PBGitIndex.h +++ b/PBGitIndex.h @@ -48,7 +48,7 @@ - (BOOL)unstageFiles:(NSArray *)unstageFiles; // Intra-file changes -//- (void)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse; +- (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse; - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines:(NSUInteger)context; @end diff --git a/PBGitIndex.m b/PBGitIndex.m index 5097158..717ceff 100644 --- a/PBGitIndex.m +++ b/PBGitIndex.m @@ -246,6 +246,31 @@ return YES; } +- (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse; +{ + NSMutableArray *array = [NSMutableArray arrayWithObjects:@"apply", nil]; + if (stage) + [array addObject:@"--cached"]; + if (reverse) + [array addObject:@"--reverse"]; + + int ret = 1; + NSString *error = [repository outputForArguments:array + inputString:hunk + retValue:&ret]; + + // FIXME: show this error, rather than just logging it + if (ret) { + NSLog(@"Error: %@", error); + return NO; + } + + // TODO: Try to be smarter about what to refresh + [self refresh]; + return YES; +} + + - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines:(NSUInteger)context { NSString *parameter = [NSString stringWithFormat:@"-U%u", context];