mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
PBGitCommitController: retain author information of previous commit
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
// And decrease it after you have finished.
|
||||
int busy;
|
||||
BOOL amend;
|
||||
NSDictionary *amendEnvironment;
|
||||
|
||||
}
|
||||
|
||||
|
||||
+25
-8
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user