mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
GitIndex: add commit notifications
This commit is contained in:
+24
-4
@@ -16,6 +16,8 @@
|
||||
|
||||
@interface PBGitCommitController ()
|
||||
- (void)refreshFinished:(NSNotification *)notification;
|
||||
- (void)commitStatusUpdated:(NSNotification *)notification;
|
||||
- (void)commitFinished:(NSNotification *)notification;
|
||||
@end
|
||||
|
||||
@implementation PBGitCommitController
|
||||
@@ -29,7 +31,11 @@
|
||||
|
||||
index = [[PBGitIndex alloc] initWithRepository:theRepository workingDirectory:[NSURL fileURLWithPath:[theRepository workingDirectory]]];
|
||||
[index refresh];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshFinished:) name:PBGitIndexFinishedIndexRefresh object:index];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitStatusUpdated:) name:PBGitIndexCommitStatus object:index];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFinished:) name:PBGitIndexFinishedCommit object:index];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -118,11 +124,10 @@
|
||||
[cachedFilesController setSelectionIndexes:[NSIndexSet indexSet]];
|
||||
[unstagedFilesController setSelectionIndexes:[NSIndexSet indexSet]];
|
||||
|
||||
self.busy = YES;
|
||||
|
||||
[index commitWithMessage:commitMessage];
|
||||
|
||||
[webController setStateMessage:[NSString stringWithFormat:@"Successfully created commit"]];
|
||||
|
||||
[commitMessageView setString:@""];
|
||||
[commitMessageView setEditable:NO];
|
||||
}
|
||||
|
||||
|
||||
@@ -131,4 +136,19 @@
|
||||
self.busy = NO;
|
||||
self.status = @"Index refresh finished";
|
||||
}
|
||||
|
||||
- (void)commitStatusUpdated:(NSNotification *)notification
|
||||
{
|
||||
self.status = [[notification userInfo] objectForKey:@"description"];
|
||||
}
|
||||
|
||||
- (void)commitFinished:(NSNotification *)notification
|
||||
{
|
||||
[webController setStateMessage:[NSString stringWithFormat:[[notification userInfo] objectForKey:@"description"]]];
|
||||
|
||||
BOOL success = [[[notification userInfo] objectForKey:@"success"] boolValue];
|
||||
if (success)
|
||||
[commitMessageView setString:@""];
|
||||
[commitMessageView setEditable:YES];
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
extern NSString *PBGitIndexIndexRefreshStatus;
|
||||
extern NSString *PBGitIndexIndexRefreshFailed;
|
||||
extern NSString *PBGitIndexFinishedIndexRefresh;
|
||||
|
||||
extern NSString *PBGitIndexCommitStatus;
|
||||
extern NSString *PBGitIndexCommitFailed;
|
||||
extern NSString *PBGitIndexFinishedCommit;
|
||||
|
||||
|
||||
+33
-6
@@ -16,6 +16,8 @@
|
||||
NSString *PBGitIndexIndexRefreshStatus = @"PBGitIndexIndexRefreshStatus";
|
||||
NSString *PBGitIndexIndexRefreshFailed = @"PBGitIndexIndexRefreshFailed";
|
||||
NSString *PBGitIndexFinishedIndexRefresh = @"PBGitIndexFinishedIndexRefresh";
|
||||
|
||||
NSString *PBGitIndexCommitStatus = @"PBGitIndexCommitStatus";
|
||||
NSString *PBGitIndexCommitFailed = @"PBGitIndexCommitFailed";
|
||||
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
|
||||
|
||||
@@ -40,6 +42,7 @@ NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
|
||||
// Returns the tree to compare the index to, based
|
||||
// on whether amend is set or not.
|
||||
- (NSString *) parentTree;
|
||||
- (void)postCommitUpdate:(NSString *)update;
|
||||
|
||||
@end
|
||||
|
||||
@@ -138,8 +141,9 @@ NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
|
||||
commitMessageFile = [repository.fileURL.path stringByAppendingPathComponent:@"COMMIT_EDITMSG"];
|
||||
|
||||
[commitMessage writeToFile:commitMessageFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
||||
|
||||
|
||||
// TODO: Notification: @"Creating tree..";
|
||||
[self postCommitUpdate:@"Creating tree"];
|
||||
NSString *tree = [repository outputForCommand:@"write-tree"];
|
||||
if ([tree length] != 40)
|
||||
return; //TODO: commitFailedBecause:@"Could not create a tree";
|
||||
@@ -152,6 +156,7 @@ NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
|
||||
[arguments addObject:parent];
|
||||
}
|
||||
|
||||
[self postCommitUpdate:@"Creating commit"];
|
||||
int ret = 1;
|
||||
NSString *commit = [repository outputForArguments:arguments
|
||||
inputString:commitMessage
|
||||
@@ -161,23 +166,38 @@ NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
|
||||
if (ret || [commit length] != 40)
|
||||
return; // TODO: [self commitFailedBecause:@"Could not create a commit object"];
|
||||
|
||||
[self postCommitUpdate:@"Running hooks"];
|
||||
if (![repository executeHook:@"pre-commit" output:nil])
|
||||
return; // TODO: [self commitFailedBecause:@"Pre-commit hook failed"];
|
||||
|
||||
if (![repository executeHook:@"commit-msg" withArgs:[NSArray arrayWithObject:commitMessageFile] output:nil])
|
||||
return; // TODO: [self commitFailedBecause:@"Commit-msg hook failed"];
|
||||
|
||||
[self postCommitUpdate:@"Updating HEAD"];
|
||||
[repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-m", commitSubject, @"HEAD", commit, nil]
|
||||
retValue: &ret];
|
||||
if (ret)
|
||||
return; // TODO: [self commitFailedBecause:@"Could not update HEAD"];
|
||||
|
||||
if (![repository executeHook:@"post-commit" output:nil])
|
||||
return; // [webController setStateMessage:[NSString stringWithFormat:@"Post-commit hook failed, however, successfully created commit %@", commit]];
|
||||
else
|
||||
//[webController setStateMessage:[NSString stringWithFormat:@"Successfully created commit %@", commit]];
|
||||
;
|
||||
[self postCommitUpdate:@"Running post-commit hook"];
|
||||
|
||||
BOOL success = [repository executeHook:@"post-commit" output:nil];
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:[NSNumber numberWithBool:success] forKey:@"success"];
|
||||
NSString *description;
|
||||
if (success)
|
||||
description = [NSString stringWithFormat:@"Successfull created commit %@", commit];
|
||||
else
|
||||
description = [NSString stringWithFormat:@"Post-commit hook failed, but successfully created commit %@", commit];
|
||||
|
||||
[userInfo setObject:description forKey:@"description"];
|
||||
[userInfo setObject:commit forKey:@"sha"];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexFinishedCommit
|
||||
object:self
|
||||
userInfo:userInfo];
|
||||
if (!success)
|
||||
return;
|
||||
|
||||
repository.hasChanged = YES;
|
||||
|
||||
amendEnvironment = nil;
|
||||
@@ -188,6 +208,13 @@ NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
|
||||
|
||||
}
|
||||
|
||||
- (void)postCommitUpdate:(NSString *)update
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexCommitStatus
|
||||
object:self
|
||||
userInfo:[NSDictionary dictionaryWithObject:update forKey:@"description"]];
|
||||
}
|
||||
|
||||
- (BOOL)stageFiles:(NSArray *)stageFiles
|
||||
{
|
||||
// Input string for update-index
|
||||
|
||||
Reference in New Issue
Block a user