Permalink
Browse files

CommitView: Add option to amend commits

  • Loading branch information...
1 parent 5010511 commit e659e63fc08ecd46cc1c26b6260126502ec656aa @pieter committed Oct 9, 2008
Showing with 121 additions and 257 deletions.
  1. +4 −2 PBChangedFile.h
  2. +9 −3 PBChangedFile.m
  3. +2 −0 PBGitCommitController.h
  4. +26 −7 PBGitCommitController.m
  5. +74 −244 PBGitCommitView.xib
  6. +5 −0 PBWebChangesController.m
  7. +1 −1 html/diff.html
View
@@ -29,9 +29,11 @@ typedef enum {
@property (assign) BOOL hasCachedChanges;
@property (assign) BOOL hasUnstagedChanges;
- (NSImage *)icon;
-- (NSString *)changes;
+- (NSString *)cachedChangesAmend:(BOOL)amend;
+- (NSString *)unstagedChanges;
+
- (void) stageChanges;
-- (void) unstageChanges;
+- (void) unstageChangesAmend:(BOOL)amend;
- (id) initWithPath:(NSString *)p andRepository:(PBGitRepository *)r;
@end
View
@@ -20,8 +20,11 @@ - (id) initWithPath:(NSString *)p andRepository:(PBGitRepository *)r
return self;
}
-- (NSString *) cachedChanges
+- (NSString *) cachedChangesAmend:(BOOL) amend
{
+ if (amend)
+ return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"HEAD^", @"--", path, nil]];
+
return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"--", path, nil]];
}
@@ -63,9 +66,12 @@ - (void) stageChanges
self.hasCachedChanges = YES;
}
-- (void) unstageChanges
+- (void) unstageChangesAmend:(BOOL) amend
{
- [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"--", path, nil]];
+ if (amend)
+ [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"HEAD^", @"--", path, nil]];
+ else
+ [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"--", path, nil]];
self.hasCachedChanges = NO;
self.hasUnstagedChanges = YES;
}
@@ -23,6 +23,7 @@
// You can increase it when your process start
// And decrease it after you have finished.
int busy;
+ BOOL amend;
IBOutlet PBIconAndTextCell* unstagedButtonCell;
IBOutlet PBIconAndTextCell* cachedButtonCell;
@@ -34,6 +35,7 @@
@property (retain) NSMutableArray *files;
@property (copy) NSString *status;
@property (assign) int busy;
+@property (assign) BOOL amend;
- (void) readCachedFiles:(NSNotification *)notification;
- (void) readOtherFiles:(NSNotification *)notification;
@@ -12,13 +12,15 @@
@implementation PBGitCommitController
-@synthesize files, status, busy;
+@synthesize files, status, busy, amend;
- (void)awakeFromNib
{
[super awakeFromNib];
self.busy = 0;
+ amend = NO;
+
[unstagedButtonCell setAction:@selector(rowClicked:)];
[cachedButtonCell setAction:@selector(rowClicked:)];
@@ -39,6 +41,18 @@ - (void)awakeFromNib
[[NSSortDescriptor alloc] initWithKey:@"path" ascending:true]]];
}
+- (void) setAmend:(BOOL)newAmend
+{
+ if (newAmend == amend)
+ return;
+ amend = newAmend;
+
+ if (amend && [[commitMessageView string] length] <= 3)
+ commitMessageView.string = [repository outputForCommand:@"log -1 --pretty=format:%s%n%n%b HEAD"];
+
+ [self refresh:self];
+}
+
- (NSArray *) linesFromNotification:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
@@ -60,16 +74,18 @@ - (NSArray *) linesFromNotification:(NSNotification *)notification
- (NSString *) parentTree
{
- id a = [repository parseReference:@"HEAD"];
+ NSString *parent = amend ? @"HEAD^" : @"HEAD";
+
+ NSString *a = [repository parseReference:@"HEAD^"];
// TODO: parseReference should exit nil if it errors out. For
// now, compare to "HEAD"
- if ([a isEqualToString:@"HEAD"]) {
+ if ([a isEqualToString:parent]) {
// We don't have a head ref. Return the empty tree.
return @"4b825dc642cb6eb9a060e54bf8d69288fbee4904";
}
- return @"HEAD";
+ return parent;
}
- (void) refresh:(id) sender
@@ -233,9 +249,10 @@ - (IBAction) commit:(id) sender
int ret;
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"commit-tree", tree, nil];
- if ([repository parseSymbolicReference:@"HEAD"]) {
+ NSString *parent = amend ? @"HEAD^" : @"HEAD";
+ if ([repository parseReference:parent]) {
[arguments addObject:@"-p"];
- [arguments addObject:@"HEAD"];
+ [arguments addObject:parent];
}
NSString *commit = [repository outputForArguments:arguments
@@ -259,7 +276,9 @@ - (IBAction) commit:(id) sender
repository.hasChanged = YES;
self.busy--;
[commitMessageView setString:@""];
+ amend = NO;
[self refresh:self];
+ self.amend = NO;
}
- (void) tableClicked:(NSTableView *) tableView
@@ -280,7 +299,7 @@ - (void) tableClicked:(NSTableView *) tableView
if ([tableView tag] == 0)
[selectedItem stageChanges];
else
- [selectedItem unstageChanges];
+ [selectedItem unstageChangesAmend:amend];
// Add the file to the other controller if it's not there yet
for (PBChangedFile *object in [otherController arrangedObjects])
Oops, something went wrong. Retry.

0 comments on commit e659e63

Please sign in to comment.