Added a dialog for failing commit hooks

This enables the user to force a commit (i.e. --no-verify) when either pre-commit or
commit-msg hook fails.
This commit is contained in:
Sebastian Staudt
2010-09-13 09:16:25 +02:00
parent ed833164d9
commit 21d1f3989f
12 changed files with 1424 additions and 22 deletions
+10
View File
@@ -21,6 +21,8 @@
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
02B41A5E123E307200DFC531 /* PBCommitHookFailedSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = 02B41A5D123E307200DFC531 /* PBCommitHookFailedSheet.m */; };
02B41A60123E307F00DFC531 /* PBCommitHookFailedSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 02B41A5F123E307F00DFC531 /* PBCommitHookFailedSheet.xib */; };
056438B70ED0C40B00985397 /* DetailViewTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = 056438B60ED0C40B00985397 /* DetailViewTemplate.png */; };
3BC07F4C0ED5A5C5009A7768 /* HistoryViewTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = 3BC07F4A0ED5A5C5009A7768 /* HistoryViewTemplate.png */; };
3BC07F4D0ED5A5C5009A7768 /* CommitViewTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = 3BC07F4B0ED5A5C5009A7768 /* CommitViewTemplate.png */; };
@@ -237,6 +239,9 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
02B41A5C123E307200DFC531 /* PBCommitHookFailedSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCommitHookFailedSheet.h; sourceTree = "<group>"; };
02B41A5D123E307200DFC531 /* PBCommitHookFailedSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitHookFailedSheet.m; sourceTree = "<group>"; };
02B41A5F123E307F00DFC531 /* PBCommitHookFailedSheet.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PBCommitHookFailedSheet.xib; sourceTree = "<group>"; };
056438B60ED0C40B00985397 /* DetailViewTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = DetailViewTemplate.png; path = Images/DetailViewTemplate.png; sourceTree = "<group>"; };
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
@@ -620,6 +625,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
02B41A5F123E307F00DFC531 /* PBCommitHookFailedSheet.xib */,
F5F7D0641062E7940072C81C /* UpdateKey.pem */,
F50A41130EBB872D00208746 /* Widgets */,
47DBDB920E94F47200671A1E /* Preference Icons */,
@@ -691,6 +697,8 @@
D82F435F111B9C6D00A25A39 /* Sheets */ = {
isa = PBXGroup;
children = (
02B41A5C123E307200DFC531 /* PBCommitHookFailedSheet.h */,
02B41A5D123E307200DFC531 /* PBCommitHookFailedSheet.m */,
D854948410D5C01B0083B917 /* PBCreateBranchSheet.h */,
D854948510D5C01B0083B917 /* PBCreateBranchSheet.m */,
D8E3B34B10DCA958001096A3 /* PBCreateTagSheet.h */,
@@ -1172,6 +1180,7 @@
D8022FE811E124A0003C21F6 /* PBGitXMessageSheet.xib in Resources */,
D8F01C4B12182F19007F729F /* GitX.sdef in Resources */,
D8F4AB7912298CE200D6D53C /* rewindImage.pdf in Resources */,
02B41A60123E307F00DFC531 /* PBCommitHookFailedSheet.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1321,6 +1330,7 @@
D8F01D531218A164007F729F /* NSApplication+GitXScripting.m in Sources */,
D8B4DC571220D1E4004166D6 /* PBHistorySearchController.m in Sources */,
D8712A00122B14EC00012334 /* GitXTextFieldCell.m in Sources */,
02B41A5E123E307200DFC531 /* PBCommitHookFailedSheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+25
View File
@@ -0,0 +1,25 @@
//
// PBCommitHookFailedSheet.h
// GitX
//
// Created by Sebastian Staudt on 9/12/10.
// Copyright 2010 Sebastian Staudt. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "PBGitCommitController.h"
#import "PBGitXMessageSheet.h"
@interface PBCommitHookFailedSheet : PBGitXMessageSheet
{
PBGitCommitController *commitController;
}
+ (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info commitController:(PBGitCommitController *)controller;
- (id)initWithWindowNibName:(NSString *)windowNibName andController:(PBGitCommitController *)controller;
- (IBAction)forceCommit:(id)sender;
@end
+38
View File
@@ -0,0 +1,38 @@
//
// PBCommitHookFailedSheet.m
// GitX
//
// Created by Sebastian Staudt on 9/12/10.
// Copyright 2010 Sebastian Staudt. All rights reserved.
//
#import "PBCommitHookFailedSheet.h"
#import "PBGitWindowController.h"
@implementation PBCommitHookFailedSheet
#pragma mark -
#pragma mark PBCommitHookFailedSheet
+ (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info commitController:(PBGitCommitController *)controller
{
PBCommitHookFailedSheet *sheet = [[self alloc] initWithWindowNibName:@"PBCommitHookFailedSheet" andController:controller];
[sheet beginMessageSheetForWindow:parentWindow withMessageText:message infoText:info];
}
- (id)initWithWindowNibName:(NSString *)windowNibName andController:(PBGitCommitController *)controller;
{
self = [self initWithWindowNibName:windowNibName];
commitController = controller;
return self;
}
- (IBAction)forceCommit:(id)sender
{
[self closeMessageSheet:self];
[commitController forceCommit:sender];
}
@end
File diff suppressed because it is too large Load Diff
+1
View File
@@ -29,5 +29,6 @@
- (IBAction) refresh:(id) sender;
- (IBAction) commit:(id) sender;
- (IBAction) forceCommit:(id) sender;
- (IBAction)signOff:(id)sender;
@end
+23 -1
View File
@@ -14,9 +14,11 @@
@interface PBGitCommitController ()
- (void)refreshFinished:(NSNotification *)notification;
- (void)commitWithVerification:(BOOL) doVerify;
- (void)commitStatusUpdated:(NSNotification *)notification;
- (void)commitFinished:(NSNotification *)notification;
- (void)commitFailed:(NSNotification *)notification;
- (void)commitHookFailed:(NSNotification *)notification;
- (void)amendCommit:(NSNotification *)notification;
- (void)indexChanged:(NSNotification *)notification;
- (void)indexOperationFailed:(NSNotification *)notification;
@@ -38,6 +40,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(commitHookFailed:) name:PBGitIndexCommitHookFailed object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(amendCommit:) name:PBGitIndexAmendMessageAvailable object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(indexChanged:) name:PBGitIndexIndexUpdated object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(indexOperationFailed:) name:PBGitIndexOperationFailed object:index];
@@ -106,6 +109,16 @@
}
- (IBAction) commit:(id) sender
{
[self commitWithVerification:YES];
}
- (IBAction) forceCommit:(id) sender
{
[self commitWithVerification:NO];
}
- (void) commitWithVerification:(BOOL) doVerify
{
if ([[NSFileManager defaultManager] fileExistsAtPath:[repository.fileURL.path stringByAppendingPathComponent:@"MERGE_HEAD"]]) {
[[repository windowController] showMessageSheet:@"Cannot commit merges" infoText:@"GitX cannot commit merges yet. Please commit your changes from the command line."];
@@ -129,7 +142,7 @@
self.isBusy = YES;
[commitMessageView setEditable:NO];
[index commitWithMessage:commitMessage];
[index commitWithMessage:commitMessage andVerify:doVerify];
}
@@ -161,6 +174,15 @@
[[repository windowController] showMessageSheet:@"Commit failed" infoText:reason];
}
- (void)commitHookFailed:(NSNotification *)notification
{
self.isBusy = NO;
NSString *reason = [[notification userInfo] objectForKey:@"description"];
self.status = [@"Commit hook failed: " stringByAppendingString:reason];
[commitMessageView setEditable:YES];
[[repository windowController] showCommitHookFailedSheet:@"Commit hook failed" infoText:reason commitController:self];
}
- (void)amendCommit:(NSNotification *)notification
{
// Replace commit message with the old one if it's less than 3 characters long.
+2 -1
View File
@@ -26,6 +26,7 @@ extern NSString *PBGitIndexIndexUpdated;
// Committing files
extern NSString *PBGitIndexCommitStatus;
extern NSString *PBGitIndexCommitFailed;
extern NSString *PBGitIndexCommitHookFailed;
extern NSString *PBGitIndexFinishedCommit;
// Changing to amend
@@ -66,7 +67,7 @@ extern NSString *PBGitIndexOperationFailed;
// Refresh the index
- (void)refresh;
- (void)commitWithMessage:(NSString *)commitMessage;
- (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify;
// Inter-file changes:
- (BOOL)stageFiles:(NSArray *)stageFiles;
+28 -17
View File
@@ -21,6 +21,7 @@ NSString *PBGitIndexIndexUpdated = @"GBGitIndexIndexUpdated";
NSString *PBGitIndexCommitStatus = @"PBGitIndexCommitStatus";
NSString *PBGitIndexCommitFailed = @"PBGitIndexCommitFailed";
NSString *PBGitIndexCommitHookFailed = @"PBGitIndexCommitHookFailed";
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable";
@@ -48,6 +49,7 @@ NSString *PBGitIndexOperationFailed = @"PBGitIndexOperationFailed";
- (NSString *) parentTree;
- (void)postCommitUpdate:(NSString *)update;
- (void)postCommitFailure:(NSString *)reason;
- (void)postCommitHookFailure:(NSString *)reason;
- (void)postIndexChange;
- (void)postOperationFailed:(NSString *)description;
@end
@@ -145,7 +147,7 @@ NSString *PBGitIndexOperationFailed = @"PBGitIndexOperationFailed";
}
// TODO: make Asynchronous
- (void)commitWithMessage:(NSString *)commitMessage
- (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
{
NSMutableString *commitSubject = [@"commit: " mutableCopy];
NSRange newLine = [commitMessage rangeOfString:@"\n"];
@@ -176,23 +178,25 @@ NSString *PBGitIndexOperationFailed = @"PBGitIndexOperationFailed";
[self postCommitUpdate:@"Creating commit"];
int ret = 1;
[self postCommitUpdate:@"Running hooks"];
NSString *hookFailureMessage = nil;
NSString *hookOutput = nil;
if (![repository executeHook:@"pre-commit" output:&hookOutput]) {
hookFailureMessage = [NSString stringWithFormat:@"Pre-commit hook failed%@%@",
[hookOutput length] > 0 ? @":\n" : @"",
hookOutput];
}
if (![repository executeHook:@"commit-msg" withArgs:[NSArray arrayWithObject:commitMessageFile] output:nil]) {
hookFailureMessage = [NSString stringWithFormat:@"Commit-msg hook failed%@%@",
[hookOutput length] > 0 ? @":\n" : @"",
hookOutput];
}
if (doVerify) {
[self postCommitUpdate:@"Running hooks"];
NSString *hookFailureMessage = nil;
NSString *hookOutput = nil;
if (![repository executeHook:@"pre-commit" output:&hookOutput]) {
hookFailureMessage = [NSString stringWithFormat:@"Pre-commit hook failed%@%@",
[hookOutput length] > 0 ? @":\n" : @"",
hookOutput];
}
if (hookFailureMessage != nil) {
return [self postCommitFailure:hookFailureMessage];
if (![repository executeHook:@"commit-msg" withArgs:[NSArray arrayWithObject:commitMessageFile] output:nil]) {
hookFailureMessage = [NSString stringWithFormat:@"Commit-msg hook failed%@%@",
[hookOutput length] > 0 ? @":\n" : @"",
hookOutput];
}
if (hookFailureMessage != nil) {
return [self postCommitHookFailure:hookFailureMessage];
}
}
commitMessage = [NSString stringWithContentsOfFile:commitMessageFile encoding:NSUTF8StringEncoding error:nil];
@@ -254,6 +258,13 @@ NSString *PBGitIndexOperationFailed = @"PBGitIndexOperationFailed";
userInfo:[NSDictionary dictionaryWithObject:reason forKey:@"description"]];
}
- (void)postCommitHookFailure:(NSString *)reason
{
[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexCommitHookFailed
object:self
userInfo:[NSDictionary dictionaryWithObject:reason forKey:@"description"]];
}
- (void)postOperationFailed:(NSString *)description
{
[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexOperationFailed
+2 -1
View File
@@ -9,7 +9,7 @@
#import <Cocoa/Cocoa.h>
#import "PBGitRepository.h"
@class PBViewController, PBGitSidebarController;
@class PBViewController, PBGitSidebarController, PBGitCommitController;
@interface PBGitWindowController : NSWindowController {
__weak PBGitRepository* repository;
@@ -37,6 +37,7 @@
- (void)changeContentController:(PBViewController *)controller;
- (void)showCommitHookFailedSheet:(NSString *)messageText infoText:(NSString *)infoText commitController:(PBGitCommitController *)controller;
- (void)showMessageSheet:(NSString *)messageText infoText:(NSString *)infoText;
- (void)showErrorSheet:(NSError *)error;
- (void)showErrorSheetTitle:(NSString *)title message:(NSString *)message arguments:(NSArray *)arguments output:(NSString *)output;
+6
View File
@@ -11,6 +11,7 @@
#import "PBGitCommitController.h"
#import "Terminal.h"
#import "PBCloneRepsitoryToSheet.h"
#import "PBCommitHookFailedSheet.h"
#import "PBGitXMessageSheet.h"
#import "PBGitSidebarController.h"
@@ -109,6 +110,11 @@
[sidebarController selectCurrentBranch];
}
- (void)showCommitHookFailedSheet:(NSString *)messageText infoText:(NSString *)infoText commitController:(PBGitCommitController *)controller
{
[PBCommitHookFailedSheet beginMessageSheetForWindow:[self window] withMessageText:messageText infoText:infoText commitController:controller];
}
- (void)showMessageSheet:(NSString *)messageText infoText:(NSString *)infoText
{
[PBGitXMessageSheet beginMessageSheetForWindow:[self window] withMessageText:messageText infoText:infoText];
+1
View File
@@ -21,6 +21,7 @@
+ (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withError:(NSError *)error;
- (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info;
- (IBAction)closeMessageSheet:(id)sender;
-2
View File
@@ -14,8 +14,6 @@
@interface PBGitXMessageSheet ()
- (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info;
- (void)setInfoString:(NSString *)info;
- (void)resizeWindow;