mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Show previous commit message when amending
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user