Skip to content

Commit

Permalink
modified commit such that only the selected files are committed rathe…
Browse files Browse the repository at this point in the history
…r than everything (unless of course, you've opted to commit and haven't selected anything).
  • Loading branch information
Brandon Sneed committed Jul 29, 2010
1 parent 47023f3 commit a10c910
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 19 deletions.
6 changes: 4 additions & 2 deletions python/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
if not os.path.exists(commitfile):raise Exception("Gitty Error: The tmp commitmsg file doesn't exist.")
signoff=False
if options.misc and len(options.misc)>0: signoff=True
if signoff: command="%s %s %s"%(options.git,"commit -s -F",commitfile)
else: command="%s %s %s"%(options.git,"commit -F",commitfile)
if signoff: command="%s %s %s"%(options.git,"commit -s -F ",commitfile)
else: command="%s %s %s"%(options.git,"commit -F ",commitfile)

if checkfiles(options): command+=" "+make_file_list_for_git(options.files)
rcode,stout,sterr=run_command(command)
rcode_for_git_exit(rcode,sterr)
exit(0)
Expand Down
2 changes: 2 additions & 0 deletions src/GTCommitMessageController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
IBOutlet NSButton * signoff;
NSString * commitMessageValue;
BOOL addBeforeCommit;
NSArray * fileSelection;
}

@property (readonly,nonatomic) NSString * commitMessageValue;
Expand All @@ -39,5 +40,6 @@
- (void) focus;
- (BOOL) shouldSignoff;
- (void) updateMessageFieldAttributes;
- (void) finishTwoStageCommit;

@end
17 changes: 13 additions & 4 deletions src/GTCommitMessageController.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,24 @@ - (void) onok:(id) sender {
commitMessageValue = [val copy];
if(target)
[target performSelector:action];
//[operations runCommitOperation];
//[self disposeNibs];
fileSelection = [[[gd activeBranchView] selectedFiles] copy];
if (addBeforeCommit)
[operations runAddFilesOperation];
else
{
[operations runCommitOperation];
[self disposeNibs];
[self finishTwoStageCommit];
}
}

- (void) finishTwoStageCommit {
if ([gd.gitd stagedFilesCount] >= 1)
[operations runCommitOperationWithFiles:fileSelection];
else
NSBeep();
self.addBeforeCommit = false;
[self disposeNibs];
}

- (BOOL) shouldSignoff {
return [signoff state];
}
Expand All @@ -130,6 +137,8 @@ - (void) loadNibs {
- (void) disposeNibs {
label=nil;
messageField=nil;
[fileSelection release];
fileSelection = nil;
GDRelease(commitMessageValue);
[super disposeNibs];
}
Expand Down
2 changes: 2 additions & 0 deletions src/GTOpCommit.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
@interface GTOpCommit : GTBasePythonTaskOperation {
}

- (id) initWithGD:(GittyDocument *) _gd andFiles:(NSArray *)files;

@end
25 changes: 24 additions & 1 deletion src/GTOpCommit.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,23 @@
#import "GTOpCommit.h"
#import "GittyDocument.h"

@interface GTOpCommit(internal)
- (void) setArgumentsAndFiles:(NSArray *)files;
@end

@implementation GTOpCommit

- (void) setArguments {
- (id) initWithGD:(GittyDocument *) _gd andFiles:(NSArray *)files {
if(self=[super initWithGD:_gd]) {
args=[[NSMutableArray alloc] init];
readsSTDERR=true;
[self initializeTask];
[self setArgumentsAndFiles:files];
}
return self;
}

- (void) setArgumentsAndFiles:(NSArray *)files {
if([self isCancelled]) return;
[self setArgumentsWithPythonScript:[GTPythonScripts commitScript] setArgsOnTask:false];
if([self isCancelled]) return;
Expand All @@ -31,7 +45,16 @@ - (void) setArguments {
[fileHandle writeData:commitMessage];
[fileHandle release];
if([[gd commit] shouldSignoff]) [args addObject:@"-m1"];
if (files && [files count] > 0) {
for (int i = 0; i < [files count]; i++) {
[args addObject:[@"-f " stringByAppendingString:[files objectAtIndex:i]]];
}
}
[task setArguments:args];
}

- (void) setArguments {
[self setArgumentsAndFiles:nil];
}

@end
1 change: 1 addition & 0 deletions src/GTOperationsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
- (void) runRefreshStatusOperation;
- (void) runAddFilesOperation;
- (void) runCommitOperation;
- (void) runCommitOperationWithFiles:(NSArray *)files;
- (void) runRemoveFilesOperation;
- (void) runDestageOperation;
- (void) runDiscardChangesOperation;
Expand Down
13 changes: 13 additions & 0 deletions src/GTOperationsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ - (void) runAddFilesOperation {
}];
}

- (void) runCommitOperationWithFiles:(NSArray *)files {
if(allCanceled) return;
if(isRunningCommit) return;
isRunningCommit=true;
[status showSpinner];
GTOpCommit * commit = [[[GTOpCommit alloc] initWithGD:gd andFiles:files] autorelease];
NSOperationQueue * q = [self createCancelableQueueWithOperation:commit];
[commit setCompletionBlock:^{
[self releaseAndRemoveQFromCancelables:q];
[self onCommitComplete];
}];
}

- (void) runCommitOperation {
if(allCanceled) return;
if(isRunningCommit) return;
Expand Down
13 changes: 1 addition & 12 deletions src/GittyDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -512,19 +512,8 @@ - (void) onRefreshOperationComplete {
[mainMenuHelper invalidate];
[contextMenus invalidate];
//[self adjustMinWindowSize];
/*if(commitAfterAdd) {
[commit focus];
commitAfterAdd=false;
}*/
if (commit.addBeforeCommit)
{
if([gitd stagedFilesCount] >= 1)
[operations runCommitOperation];
else
NSBeep();
commit.addBeforeCommit = false;
[commit disposeNibs];
}
[commit finishTwoStageCommit];
[sourceListView update];
// update the history...
[historyView invalidate];
Expand Down

0 comments on commit a10c910

Please sign in to comment.