From 41a906d7159d8154924cbc81725923974c54cbff Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 28 Oct 2008 23:52:34 +0100 Subject: [PATCH] PBGitRepository: Don't return a ref if we error out This fixes the -parseReference: method to return nil if there is an error in the git call. This also simplifies our commit controller. --- PBGitCommitController.m | 7 +------ PBGitRepository.m | 9 +++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/PBGitCommitController.m b/PBGitCommitController.m index 299821b..88f62c9 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -78,14 +78,9 @@ { NSString *parent = amend ? @"HEAD^" : @"HEAD"; - NSString *a = [repository parseReference:@"HEAD^"]; - - // TODO: parseReference should exit nil if it errors out. For - // now, compare to "HEAD" - if ([a isEqualToString:parent]) { + if (![repository parseReference:parent]) // We don't have a head ref. Return the empty tree. return @"4b825dc642cb6eb9a060e54bf8d69288fbee4904"; - } return parent; } diff --git a/PBGitRepository.m b/PBGitRepository.m index 51a89ac..23ac75d 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -368,9 +368,14 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; retValue: ret]; } -- (NSString*) parseReference:(NSString *)reference +- (NSString *)parseReference:(NSString *)reference { - return [self outputForArguments:[NSArray arrayWithObjects: @"rev-parse", reference, nil]]; + int ret = 1; + NSString *ref = [self outputForArguments:[NSArray arrayWithObjects: @"rev-parse", @"--verify", reference, nil] retValue: &ret]; + if (ret) + return nil; + + return ref; } - (NSString*) parseSymbolicReference:(NSString*) reference