Permalink
Browse files

CommitView: Allow rootless commits

This fixes the committing of rootless commits by not
requiring a HEAD parent if there isn't one.
  • Loading branch information...
1 parent e418878 commit d66a105a4be23920811cc8e4293e54af102e70f5 @pieter pieter committed Oct 8, 2008
Showing with 23 additions and 2 deletions.
  1. +23 −2 PBGitCommitController.m
@@ -58,6 +58,20 @@ - (NSArray *) linesFromNotification:(NSNotification *)notification
return lines;
}
+- (NSString *) parentTree
+{
+ id a = [repository parseReference:@"HEAD"];
+
+ // TODO: parseReference should exit nil if it errors out. For
+ // now, compare to "HEAD"
+ if ([a isEqualToString:@"HEAD"]) {
+ // We don't have a head ref. Return the empty tree.
+ return @"4b825dc642cb6eb9a060e54bf8d69288fbee4904";
+ }
+
+ return @"HEAD";
+}
+
- (void) refresh:(id) sender
{
self.status = @"Refreshing index…";
@@ -84,7 +98,7 @@ - (void) refresh:(id) sender
[handle readToEndOfFileInBackgroundAndNotify];
// Cached files
- handle = [repository handleInWorkDirForArguments:[NSArray arrayWithObjects:@"diff-index", @"--cached", @"-z", @"HEAD", nil]];
+ handle = [repository handleInWorkDirForArguments:[NSArray arrayWithObjects:@"diff-index", @"--cached", @"-z", [self parentTree], nil]];
[nc addObserver:self selector:@selector(readCachedFiles:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
self.busy++;
[handle readToEndOfFileInBackgroundAndNotify];
@@ -215,7 +229,14 @@ - (IBAction) commit:(id) sender
return [self commitFailedBecause:@"Could not create a tree"];
int ret;
- NSString *commit = [repository outputForArguments:[NSArray arrayWithObjects:@"commit-tree", tree, @"-p", @"HEAD", nil]
+
+ NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"commit-tree", tree, nil];
+ if ([repository parseSymbolicReference:@"HEAD"]) {
+ [arguments addObject:@"-p"];
+ [arguments addObject:@"HEAD"];
+ }
+
+ NSString *commit = [repository outputForArguments:arguments
inputString:commitMessage
retValue: &ret];

0 comments on commit d66a105

Please sign in to comment.