diff --git a/PBGitCommitController.m b/PBGitCommitController.m index 11b470d..9520056 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -19,6 +19,7 @@ - (void)commitStatusUpdated:(NSNotification *)notification; - (void)commitFinished:(NSNotification *)notification; - (void)commitFailed:(NSNotification *)notification; +- (void)amendCommit:(NSNotification *)notification; @end @implementation PBGitCommitController @@ -37,6 +38,7 @@ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitStatusUpdated:) name:PBGitIndexCommitStatus object:index]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFinished:) name:PBGitIndexFinishedCommit object:index]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFailed:) name:PBGitIndexCommitFailed object:index]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(amendCommit:) name:PBGitIndexAmendMessageAvailable object:index]; return self; } @@ -56,11 +58,13 @@ [cachedFilesController setSortDescriptors:[NSArray arrayWithObject: [[NSSortDescriptor alloc] initWithKey:@"path" ascending:true]]]; } + - (void) removeView { [webController closeView]; [super finalize]; } + - (NSResponder *)firstResponder; { return commitMessageView; @@ -151,5 +155,16 @@ [[repository windowController] showMessageSheet:@"Commit failed" infoText:reason]; } +- (void)amendCommit:(NSNotification *)notification +{ + // 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) + return; + + NSString *message = [[notification userInfo] objectForKey:@"message"]; + commitMessageView.string = message; +} + @end diff --git a/PBGitIndex.h b/PBGitIndex.h index f1fc8c9..cc4ae77 100644 --- a/PBGitIndex.h +++ b/PBGitIndex.h @@ -19,6 +19,7 @@ extern NSString *PBGitIndexCommitStatus; extern NSString *PBGitIndexCommitFailed; extern NSString *PBGitIndexFinishedCommit; +extern NSString *PBGitIndexAmendMessageAvailable; // Represents a git index for a given work tree. // As a single git repository can have multiple trees, // the tree has to be given explicitly, even though diff --git a/PBGitIndex.m b/PBGitIndex.m index 13c82a6..2b45988 100644 --- a/PBGitIndex.m +++ b/PBGitIndex.m @@ -21,6 +21,7 @@ NSString *PBGitIndexCommitStatus = @"PBGitIndexCommitStatus"; NSString *PBGitIndexCommitFailed = @"PBGitIndexCommitFailed"; NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit"; +NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable"; @interface PBGitIndex (IndexRefreshMethods) @@ -93,6 +94,16 @@ NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit"; [match objectAtIndex:2], @"GIT_AUTHOR_EMAIL", [match objectAtIndex:3], @"GIT_AUTHOR_DATE", nil]; + + // Find the commit message + NSRange r = [message rangeOfString:@"\n\n"]; + if (r.location != NSNotFound) { + NSString *commitMessage = [message substringFromIndex:r.location + 2]; + [[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexAmendMessageAvailable + object: self + userInfo:[NSDictionary dictionaryWithObject:commitMessage forKey:@"message"]]; + } + } - (void)refresh