Skip to content

Commit 2492331

Browse files
committed
Show previous commit message when amending
1 parent 2b317ee commit 2492331

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

PBGitCommitController.m

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ - (void)refreshFinished:(NSNotification *)notification;
1919
- (void)commitStatusUpdated:(NSNotification *)notification;
2020
- (void)commitFinished:(NSNotification *)notification;
2121
- (void)commitFailed:(NSNotification *)notification;
22+
- (void)amendCommit:(NSNotification *)notification;
2223
@end
2324

2425
@implementation PBGitCommitController
@@ -37,6 +38,7 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
3738
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitStatusUpdated:) name:PBGitIndexCommitStatus object:index];
3839
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFinished:) name:PBGitIndexFinishedCommit object:index];
3940
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFailed:) name:PBGitIndexCommitFailed object:index];
41+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(amendCommit:) name:PBGitIndexAmendMessageAvailable object:index];
4042

4143
return self;
4244
}
@@ -56,11 +58,13 @@ - (void)awakeFromNib
5658
[cachedFilesController setSortDescriptors:[NSArray arrayWithObject:
5759
[[NSSortDescriptor alloc] initWithKey:@"path" ascending:true]]];
5860
}
61+
5962
- (void) removeView
6063
{
6164
[webController closeView];
6265
[super finalize];
6366
}
67+
6468
- (NSResponder *)firstResponder;
6569
{
6670
return commitMessageView;
@@ -151,5 +155,16 @@ - (void)commitFailed:(NSNotification *)notification
151155
[[repository windowController] showMessageSheet:@"Commit failed" infoText:reason];
152156
}
153157

158+
- (void)amendCommit:(NSNotification *)notification
159+
{
160+
// Replace commit message with the old one if it's less than 3 characters long.
161+
// This is just a random number.
162+
if ([[commitMessageView string] length] > 3)
163+
return;
164+
165+
NSString *message = [[notification userInfo] objectForKey:@"message"];
166+
commitMessageView.string = message;
167+
}
168+
154169

155170
@end

PBGitIndex.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern NSString *PBGitIndexCommitStatus;
1919
extern NSString *PBGitIndexCommitFailed;
2020
extern NSString *PBGitIndexFinishedCommit;
2121

22+
extern NSString *PBGitIndexAmendMessageAvailable;
2223
// Represents a git index for a given work tree.
2324
// As a single git repository can have multiple trees,
2425
// the tree has to be given explicitly, even though

PBGitIndex.m

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
NSString *PBGitIndexCommitFailed = @"PBGitIndexCommitFailed";
2222
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
2323

24+
NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
2425

2526
@interface PBGitIndex (IndexRefreshMethods)
2627

@@ -93,6 +94,16 @@ - (void)setAmend:(BOOL)newAmend
9394
[match objectAtIndex:2], @"GIT_AUTHOR_EMAIL",
9495
[match objectAtIndex:3], @"GIT_AUTHOR_DATE",
9596
nil];
97+
98+
// Find the commit message
99+
NSRange r = [message rangeOfString:@"\n\n"];
100+
if (r.location != NSNotFound) {
101+
NSString *commitMessage = [message substringFromIndex:r.location + 2];
102+
[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexAmendMessageAvailable
103+
object: self
104+
userInfo:[NSDictionary dictionaryWithObject:commitMessage forKey:@"message"]];
105+
}
106+
96107
}
97108

98109
- (void)refresh

0 commit comments

Comments
 (0)