Skip to content

Commit b4557eb

Browse files
author
David Catmull
committed
return a new commit object if it's not in the list
1 parent 6cc2e26 commit b4557eb

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

PBGitRepository.m

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,31 @@ - (PBGitCommit *)commitForSHA:(NSString *)sha
467467
if ([[commit sha] isEqual:sha])
468468
return commit;
469469

470-
return nil;
470+
// The commit has not been loaded, but it may exist anyway
471+
NSArray *args = [NSArray arrayWithObjects:
472+
@"show", sha,
473+
@"--pretty=format:"
474+
"%P%n" // parents
475+
"%aN <%aE>%n" // author name
476+
"%cN <%cE>%n" // committer name
477+
"%ct%n" // commit date
478+
"%s", // subject
479+
nil];
480+
int retValue = 1;
481+
NSString *output = [self outputInWorkdirForArguments:args retValue:&retValue];
482+
483+
if ((retValue != 0) || [output hasPrefix:@"fatal:"])
484+
return nil;
485+
486+
NSArray *lines = [output componentsSeparatedByString:@"\n"];
487+
PBGitCommit *commit = [PBGitCommit commitWithRepository:self andSha:sha];
488+
489+
commit.parents = [[lines objectAtIndex:0] componentsSeparatedByString:@" "];
490+
commit.author = [lines objectAtIndex:1];
491+
commit.committer = [lines objectAtIndex:2];
492+
commit.timestamp = [[lines objectAtIndex:3] intValue];
493+
commit.subject = [lines objectAtIndex:4];
494+
return commit;
471495
}
472496

473497
- (BOOL)isOnSameBranch:(NSString *)branchSHA asSHA:(NSString *)testSHA

0 commit comments

Comments
 (0)