PBGitCommitController: retain author information of previous commit

This commit is contained in:
Pieter de Bie
2009-06-11 18:54:10 +01:00
parent e79c11b9a1
commit a14495052a
2 changed files with 26 additions and 8 deletions
+1
View File
@@ -30,6 +30,7 @@
// And decrease it after you have finished.
int busy;
BOOL amend;
NSDictionary *amendEnvironment;
}
+25 -8
View File
@@ -10,6 +10,7 @@
#import "NSFileHandleExt.h"
#import "PBChangedFile.h"
#import "PBWebChangesController.h"
#import "NSString_RegEx.h"
@interface PBGitCommitController (PrivateMethods)
@@ -51,20 +52,34 @@
{
if (newAmend == amend)
return;
amend = newAmend;
amendEnvironment = nil;
// Replace commit message with the old one if it's less than 3 characters long.
// This is just a random number.
if (amend && [[commitMessageView string] length] <= 3) {
// If we amend, we want to keep the author information for the previous commit
// We do this by reading in the previous commit, and storing the information
// in a dictionary. This dictionary will then later be read by [self commit:]
if (amend) {
NSString *message = [repository outputForCommand:@"cat-file commit HEAD"];
NSRange r = [message rangeOfString:@"\n\n"];
if (r.location != NSNotFound)
message = [message substringFromIndex:r.location + 2];
NSArray *match = [message substringsMatchingRegularExpression:@"\nauthor ([^\n]*) <([^\n>]*)> ([0-9]+[^\n]*)\n" count:3 options:0 ranges:nil error:nil];
if (match)
amendEnvironment = [NSDictionary dictionaryWithObjectsAndKeys:[match objectAtIndex:1], @"GIT_AUTHOR_NAME",
[match objectAtIndex:2], @"GIT_AUTHOR_EMAIL",
[match objectAtIndex:3], @"GIT_AUTHOR_DATE",
nil];
commitMessageView.string = message;
// Replace commit message with the old one if it's less than 3 characters long.
// This is just a random number.
if ([[commitMessageView string] length] <= 3) {
// Find the commit message
NSRange r = [message rangeOfString:@"\n\n"];
if (r.location != NSNotFound)
message = [message substringFromIndex:r.location + 2];
commitMessageView.string = message;
}
}
[self refresh:self];
}
@@ -336,6 +351,7 @@
NSString *commit = [repository outputForArguments:arguments
inputString:commitMessage
byExtendingEnvironment:amendEnvironment
retValue: &ret];
if (ret || [commit length] != 40)
@@ -361,6 +377,7 @@
self.busy--;
[commitMessageView setString:@""];
amend = NO;
amendEnvironment = nil;
[self refresh:self];
self.amend = NO;
}