Permalink
Browse files

Show previous commit message when amending

  • Loading branch information...
1 parent 2b317ee commit 249233114dbb4653fbac2821de68d066f2cbc09a @pieter committed Sep 13, 2009
Showing with 27 additions and 0 deletions.
  1. +15 −0 PBGitCommitController.m
  2. +1 −0 PBGitIndex.h
  3. +11 −0 PBGitIndex.m
View
@@ -19,6 +19,7 @@ - (void)refreshFinished:(NSNotification *)notification;
- (void)commitStatusUpdated:(NSNotification *)notification;
- (void)commitFinished:(NSNotification *)notification;
- (void)commitFailed:(NSNotification *)notification;
+- (void)amendCommit:(NSNotification *)notification;
@end
@implementation PBGitCommitController
@@ -37,6 +38,7 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
[[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 @@ - (void)awakeFromNib
[cachedFilesController setSortDescriptors:[NSArray arrayWithObject:
[[NSSortDescriptor alloc] initWithKey:@"path" ascending:true]]];
}
+
- (void) removeView
{
[webController closeView];
[super finalize];
}
+
- (NSResponder *)firstResponder;
{
return commitMessageView;
@@ -151,5 +155,16 @@ - (void)commitFailed:(NSNotification *)notification
[[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
View
@@ -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
View
@@ -21,6 +21,7 @@
NSString *PBGitIndexCommitFailed = @"PBGitIndexCommitFailed";
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
+NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
@interface PBGitIndex (IndexRefreshMethods)
@@ -93,6 +94,16 @@ - (void)setAmend:(BOOL)newAmend
[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

0 comments on commit 2492331

Please sign in to comment.