From 21d1f3989fd8132251430bbe238de92dab502bf3 Mon Sep 17 00:00:00 2001 From: Sebastian Staudt Date: Mon, 13 Sep 2010 09:16:25 +0200 Subject: [PATCH] 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. --- GitX.xcodeproj/project.pbxproj | 10 + PBCommitHookFailedSheet.h | 25 + PBCommitHookFailedSheet.m | 38 + PBCommitHookFailedSheet.xib | 1288 ++++++++++++++++++++++++++++++++ PBGitCommitController.h | 1 + PBGitCommitController.m | 24 +- PBGitIndex.h | 3 +- PBGitIndex.m | 47 +- PBGitWindowController.h | 3 +- PBGitWindowController.m | 6 + PBGitXMessageSheet.h | 1 + PBGitXMessageSheet.m | 2 - 12 files changed, 1425 insertions(+), 23 deletions(-) create mode 100644 PBCommitHookFailedSheet.h create mode 100644 PBCommitHookFailedSheet.m create mode 100644 PBCommitHookFailedSheet.xib diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj index f95d9c457..71a441a53 100644 --- a/GitX.xcodeproj/project.pbxproj +++ b/GitX.xcodeproj/project.pbxproj @@ -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 = ""; }; + 02B41A5D123E307200DFC531 /* PBCommitHookFailedSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitHookFailedSheet.m; sourceTree = ""; }; + 02B41A5F123E307F00DFC531 /* PBCommitHookFailedSheet.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PBCommitHookFailedSheet.xib; sourceTree = ""; }; 056438B60ED0C40B00985397 /* DetailViewTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = DetailViewTemplate.png; path = Images/DetailViewTemplate.png; sourceTree = ""; }; 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; @@ -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; }; diff --git a/PBCommitHookFailedSheet.h b/PBCommitHookFailedSheet.h new file mode 100644 index 000000000..869d196ae --- /dev/null +++ b/PBCommitHookFailedSheet.h @@ -0,0 +1,25 @@ +// +// PBCommitHookFailedSheet.h +// GitX +// +// Created by Sebastian Staudt on 9/12/10. +// Copyright 2010 Sebastian Staudt. All rights reserved. +// + +#import + +#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 \ No newline at end of file diff --git a/PBCommitHookFailedSheet.m b/PBCommitHookFailedSheet.m new file mode 100644 index 000000000..907d85a2a --- /dev/null +++ b/PBCommitHookFailedSheet.m @@ -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 diff --git a/PBCommitHookFailedSheet.xib b/PBCommitHookFailedSheet.xib new file mode 100644 index 000000000..60e58b197 --- /dev/null +++ b/PBCommitHookFailedSheet.xib @@ -0,0 +1,1288 @@ + + + + 1050 + 10F569 + 788 + 1038.29 + 461.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 788 + + + YES + + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + YES + + + YES + + + + YES + + PBCommitHookFailedSheet + + + FirstResponder + + + NSApplication + + + 1 + 2 + {{196, 331}, {540, 179}} + 544736256 + Window + NSWindow + + {1.79769e+308, 1.79769e+308} + + + 256 + + YES + + + 289 + {{430, 12}, {96, 32}} + + YES + + 67239424 + 134217728 + OK + + LucidaGrande + 13 + 1044 + + + -2038284033 + 129 + + DQ + 200 + 25 + + + + + 268 + + YES + + YES + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + NSFilenamesPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT TIFF v4.0 pasteboard type + + + {{17, 98}, {64, 64}} + + YES + + 130560 + 33554432 + + NSImage + NSApplicationIcon + + 0 + 0 + 0 + NO + + YES + + + + 266 + {{99, 142}, {424, 17}} + + YES + + 67239424 + 272629760 + <message> + + LucidaGrande-Bold + 13 + 16 + + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + + + + 274 + + YES + + + 2304 + + YES + + + 2322 + {423, 14} + + + + + + PGluZm8+A + + + YES + + YES + NSFont + NSParagraphStyle + + + YES + + Helvetica + 12 + 16 + + + 4 + + + + + + + + YES + + + 134 + + + + 423 + 1 + + + 2049 + 0 + + + 3 + MQA + + + YES + + YES + NSBackgroundColor + NSColor + + + YES + + 6 + System + selectedTextBackgroundColor + + + + 6 + System + selectedTextColor + + + + + + + YES + + YES + NSColor + NSCursor + NSUnderline + + + YES + + 1 + MCAwIDEAA + + + {8, -8} + 13 + + + + + + + 6 + {423, 1e+07} + {223, 0} + + + + {422, 72} + + + + + + {4, -5} + 1 + + 2 + + + + -2147483392 + {{386, 1}, {15, 163}} + + + _doScroller: + 1 + 0.85256409645080566 + + + + -2147483392 + {{-100, -100}, {87, 18}} + + YES + 1 + + _doScroller: + 1 + 0.94565218687057495 + + + {{98, 60}, {422, 72}} + + + 656 + + + + + + + 289 + {{289, 12}, {129, 32}} + + YES + + 67239424 + 134217728 + Force Commit + + + -2038284033 + 129 + + DQ + 200 + 25 + + + + {540, 179} + + + {{0, 0}, {1680, 1028}} + {1.79769e+308, 1.79769e+308} + + + + + YES + + + iconView + + + + 15 + + + + infoView + + + + 16 + + + + messageField + + + + 17 + + + + window + + + + 18 + + + + closeMessageSheet: + + + + 19 + + + + scrollView + + + + 20 + + + + forceCommit: + + + + 24 + + + + + YES + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + YES + + + + + + 2 + + + YES + + + + + + + + + + 3 + + + YES + + + + + + 4 + + + + + 7 + + + YES + + + + + + 8 + + + + + 9 + + + YES + + + + + + 10 + + + + + 11 + + + YES + + + + + + + + 12 + + + + + 13 + + + + + 14 + + + + + 21 + + + YES + + + + + + 22 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 1.IBEditorWindowLastContentRect + 1.IBPluginDependency + 1.IBWindowTemplateEditedContentRect + 1.NSWindowTemplate.visibleAtLaunch + 1.WindowOrigin + 1.editorWindowContentRectSynchronizationRect + 10.IBPluginDependency + 11.IBPluginDependency + 12.IBPluginDependency + 13.IBPluginDependency + 14.IBPluginDependency + 2.IBPluginDependency + 2.IBUserGuides + 21.IBPluginDependency + 22.IBPluginDependency + 3.IBPluginDependency + 4.IBPluginDependency + 7.IBPluginDependency + 8.IBPluginDependency + 9.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{279, 244}, {540, 179}} + com.apple.InterfaceBuilder.CocoaPlugin + {{279, 244}, {540, 179}} + + {196, 240} + {{357, 418}, {480, 270}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + YES + + + 103 + 0 + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + YES + + + + + YES + + + YES + + + + 24 + + + + YES + + PBCommitHookFailedSheet + PBGitXMessageSheet + + forceCommit: + id + + + forceCommit: + + forceCommit: + id + + + + IBProjectSource + PBCommitHookFailedSheet.h + + + + PBGitXMessageSheet + NSWindowController + + closeMessageSheet: + id + + + closeMessageSheet: + + closeMessageSheet: + id + + + + YES + + YES + iconView + infoView + messageField + scrollView + + + YES + NSImageView + NSTextView + NSTextField + NSScrollView + + + + YES + + YES + iconView + infoView + messageField + scrollView + + + YES + + iconView + NSImageView + + + infoView + NSTextView + + + messageField + NSTextField + + + scrollView + NSScrollView + + + + + IBProjectSource + PBGitXMessageSheet.h + + + + + YES + + NSActionCell + NSCell + + IBFrameworkSource + AppKit.framework/Headers/NSActionCell.h + + + + NSApplication + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSApplication.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSApplicationScripting.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSColorPanel.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSHelpManager.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSPageLayout.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSUserInterfaceItemSearching.h + + + + NSButton + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSButton.h + + + + NSButtonCell + NSActionCell + + IBFrameworkSource + AppKit.framework/Headers/NSButtonCell.h + + + + NSCell + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSCell.h + + + + NSControl + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSControl.h + + + + NSFormatter + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFormatter.h + + + + NSImageCell + NSCell + + IBFrameworkSource + AppKit.framework/Headers/NSImageCell.h + + + + NSImageView + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSImageView.h + + + + NSMenu + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSMenu.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSAccessibility.h + + + + NSObject + + + + NSObject + + + + NSObject + + + + NSObject + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSDictionaryController.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSDragging.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSFontManager.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSFontPanel.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSKeyValueBinding.h + + + + NSObject + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSNibLoading.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSOutlineView.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSPasteboard.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSSavePanel.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSTableView.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSToolbarItem.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSView.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSClassDescription.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObjectScripting.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSPortCoder.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptClassDescription.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptObjectSpecifiers.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptWhoseTests.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLDownload.h + + + + NSObject + + IBFrameworkSource + Sparkle.framework/Headers/SUAppcast.h + + + + NSObject + + IBFrameworkSource + Sparkle.framework/Headers/SUUpdater.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebDownload.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebEditingDelegate.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebFrameLoadDelegate.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebJavaPlugIn.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebPlugin.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebPluginContainer.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebPolicyDelegate.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebResourceLoadDelegate.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebScriptObject.h + + + + NSObject + + IBFrameworkSource + WebKit.framework/Headers/WebUIDelegate.h + + + + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSInterfaceStyle.h + + + + NSResponder + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSResponder.h + + + + NSScrollView + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSScrollView.h + + + + NSScroller + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSScroller.h + + + + NSText + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSText.h + + + + NSTextField + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSTextField.h + + + + NSTextFieldCell + NSActionCell + + IBFrameworkSource + AppKit.framework/Headers/NSTextFieldCell.h + + + + NSTextView + NSText + + IBFrameworkSource + AppKit.framework/Headers/NSTextView.h + + + + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSClipView.h + + + + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSMenuItem.h + + + + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSRulerView.h + + + + NSView + NSResponder + + + + NSWindow + + IBFrameworkSource + AppKit.framework/Headers/NSDrawer.h + + + + NSWindow + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSWindow.h + + + + NSWindow + + IBFrameworkSource + AppKit.framework/Headers/NSWindowScripting.h + + + + NSWindowController + NSResponder + + showWindow: + id + + + showWindow: + + showWindow: + id + + + + IBFrameworkSource + AppKit.framework/Headers/NSWindowController.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + GitX.xcodeproj + 3 + + NSApplicationIcon + {128, 128} + + + diff --git a/PBGitCommitController.h b/PBGitCommitController.h index 0b39f05c9..ac852a3c9 100644 --- a/PBGitCommitController.h +++ b/PBGitCommitController.h @@ -29,5 +29,6 @@ - (IBAction) refresh:(id) sender; - (IBAction) commit:(id) sender; +- (IBAction) forceCommit:(id) sender; - (IBAction)signOff:(id)sender; @end diff --git a/PBGitCommitController.m b/PBGitCommitController.m index 02d74e182..9f0eca18a 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -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 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit [[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 @@ - (void) updateView } - (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 @@ - (IBAction) commit:(id) sender self.isBusy = YES; [commitMessageView setEditable:NO]; - [index commitWithMessage:commitMessage]; + [index commitWithMessage:commitMessage andVerify:doVerify]; } @@ -161,6 +174,15 @@ - (void)commitFailed:(NSNotification *)notification [[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. diff --git a/PBGitIndex.h b/PBGitIndex.h index 7ca1db78b..dee065123 100644 --- a/PBGitIndex.h +++ b/PBGitIndex.h @@ -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; diff --git a/PBGitIndex.m b/PBGitIndex.m index d39ce2598..e41e5e53b 100644 --- a/PBGitIndex.m +++ b/PBGitIndex.m @@ -21,6 +21,7 @@ NSString *PBGitIndexCommitStatus = @"PBGitIndexCommitStatus"; NSString *PBGitIndexCommitFailed = @"PBGitIndexCommitFailed"; +NSString *PBGitIndexCommitHookFailed = @"PBGitIndexCommitHookFailed"; NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit"; NSString *PBGitIndexAmendMessageAvailable = @"PBGitIndexAmendMessageAvailable"; @@ -48,6 +49,7 @@ @interface PBGitIndex () - (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 *) parentTree } // 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 @@ - (void)commitWithMessage:(NSString *)commitMessage [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 (hookFailureMessage != nil) { - return [self postCommitFailure:hookFailureMessage]; + 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 (![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 @@ - (void)postCommitFailure:(NSString *)reason 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 diff --git a/PBGitWindowController.h b/PBGitWindowController.h index 29f5245f0..0f38e223b 100644 --- a/PBGitWindowController.h +++ b/PBGitWindowController.h @@ -9,7 +9,7 @@ #import #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; diff --git a/PBGitWindowController.m b/PBGitWindowController.m index 1968c4800..9fb9c1381 100644 --- a/PBGitWindowController.m +++ b/PBGitWindowController.m @@ -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 @@ - (void) showHistoryView:(id)sender [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]; diff --git a/PBGitXMessageSheet.h b/PBGitXMessageSheet.h index 440cf01f4..60cd3c751 100644 --- a/PBGitXMessageSheet.h +++ b/PBGitXMessageSheet.h @@ -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; diff --git a/PBGitXMessageSheet.m b/PBGitXMessageSheet.m index 5c8441c5e..783cc9410 100644 --- a/PBGitXMessageSheet.m +++ b/PBGitXMessageSheet.m @@ -14,8 +14,6 @@ @interface PBGitXMessageSheet () -- (void)beginMessageSheetForWindow:(NSWindow *)parentWindow withMessageText:(NSString *)message infoText:(NSString *)info; - - (void)setInfoString:(NSString *)info; - (void)resizeWindow;