From 4c4203a7cec04e9e8f04a42b5a1d2feb71af6f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Berg?= Date: Sat, 7 Nov 2009 01:02:22 +0100 Subject: [PATCH] Update PBGitErrors to include some error messages dealing with missing remote tracking branches. This is especially useful for the new button functionality. --- GitX.xcodeproj/project.pbxproj | 2 +- PBGitXErrors.h | 3 ++ PBGitXErrors.m | 8 +++- PBRefController.h | 2 + PBRefController.m | 87 +++++++++++++++++++++++----------- 5 files changed, 72 insertions(+), 30 deletions(-) diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj index 3991d7b..91b6ff2 100644 --- a/GitX.xcodeproj/project.pbxproj +++ b/GitX.xcodeproj/project.pbxproj @@ -268,7 +268,7 @@ F56CC7310E65E0E5004307B4 /* PBGraphCellInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGraphCellInfo.m; sourceTree = ""; }; F57240BA0E9678EA00D8EE66 /* deleted_file.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = deleted_file.png; path = Images/deleted_file.png; sourceTree = ""; }; F574A2830EAE2EAC003F2CB1 /* PBRefController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBRefController.h; sourceTree = ""; }; - F574A2840EAE2EAC003F2CB1 /* PBRefController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBRefController.m; sourceTree = ""; }; + F574A2840EAE2EAC003F2CB1 /* PBRefController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = PBRefController.m; sourceTree = ""; tabWidth = 4; usesTabs = 0; }; F57CC38F0E05DDF2000472E2 /* PBEasyPipe.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBEasyPipe.h; sourceTree = ""; }; F57CC3900E05DDF2000472E2 /* PBEasyPipe.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBEasyPipe.m; sourceTree = ""; }; F57CC43F0E05E496000472E2 /* PBGitWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitWindowController.h; sourceTree = ""; }; diff --git a/PBGitXErrors.h b/PBGitXErrors.h index 05b4bf2..c3c45b2 100644 --- a/PBGitXErrors.h +++ b/PBGitXErrors.h @@ -22,6 +22,9 @@ OBJC_EXTERN NSString * const PBGitXErrorDomain; OBJC_EXTERN NSString * const PBCLIProxyErrorDomain; +OBJC_EXTERN NSString * const PBInvalidBranchErrMsg; +OBJC_EXTERN NSString * const PBMissingRemoteErrMsg; + OBJC_EXTERN const NSInteger PBFileReadingUnsupportedErrorCode; /* @"Reading files is not supported." */ OBJC_EXTERN const NSInteger PBNotAGitRepositoryErrorCode; /* @"%@ does not appear to be a git repository." */ OBJC_EXTERN const NSInteger PBGitBinaryNotFoundErrorCode; \ No newline at end of file diff --git a/PBGitXErrors.m b/PBGitXErrors.m index 29385cf..4dbfc83 100644 --- a/PBGitXErrors.m +++ b/PBGitXErrors.m @@ -19,9 +19,13 @@ #import "PBGitXErrors.h" -NSString * const PBGitXErrorDomain = @"GitXErrorDomain"; -NSString * const PBCLIProxyErrorDomain = @"CLIProxyErrorDomain"; +NSString * const PBGitXErrorDomain = @"GitXErrorDomain"; +NSString * const PBCLIProxyErrorDomain = @"CLIProxyErrorDomain"; +NSString * const PBInvalidBranchErrMsg = @"Please select a local branch from the branch popup menu, which has a corresponding remote tracking branch set up.\n\n" + @"You can also use the context menu to choose a branch by right clicking on its label in the history view."; + +NSString * const PBMissingRemoteErrMsg = @"This branch does not appear to have a remote tracking branch associated in its config file section."; const NSInteger PBNotAGitRepositoryErrorCode = 1; const NSInteger PBFileReadingUnsupportedErrorCode = 2; diff --git a/PBRefController.h b/PBRefController.h index 78f623b..c2f2f7d 100644 --- a/PBRefController.h +++ b/PBRefController.h @@ -45,6 +45,8 @@ - (BOOL) rebaseImpl:(NSString *)refName; - (BOOL) fetchImpl:(NSString *)refName; +- (void) showMessageSheet:(NSString *)title message:(NSString *)msg; + @end @interface NSString (PBRefSpecAdditions) diff --git a/PBRefController.m b/PBRefController.m index db8b629..6d96ddb 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -104,9 +104,13 @@ - (BOOL) pushImpl:(NSString *)refName { int ret = 1; - BOOL success = NO; + BOOL success = NO; NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]]; NSString *rval = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"push", remote, refName, nil] retValue: &ret]; + if (!remote) { + [self showMessageSheet:@"Push to Remote" message:PBMissingRemoteErrMsg]; + return success; + } if (ret) { NSString *info = [NSString stringWithFormat:@"There was an error pushing the branch to the remote repository.\n\n%d\n%@", ret, rval]; [[historyController.repository windowController] showMessageSheet:@"Pushing branch failed" infoText:info]; @@ -123,6 +127,10 @@ int ret = 1; BOOL success = NO; NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]]; + if (!remote) { + [self showMessageSheet:@"Pull from Remote" message:PBMissingRemoteErrMsg]; + return success; + } NSString *rval = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"pull", remote, refName, nil] retValue: &ret]; if (ret) { NSString *info = [NSString stringWithFormat:@"There was an error pulling from the remote repository.\n\n%d\n%@", ret, rval]; @@ -140,6 +148,10 @@ int ret = 1; BOOL success = NO; NSString *remote = [[[historyController repository] config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]]; + if (!remote) { + [self showMessageSheet:@"Pull Rebase from Remote" message:PBMissingRemoteErrMsg]; + return success; + } NSString *rval = [[historyController repository] outputInWorkdirForArguments:[NSArray arrayWithObjects:@"pull", @"--rebase", remote, refName, nil] retValue: &ret]; if (ret) { NSString *info = [NSString stringWithFormat:@"There was an error rebasing from the remote repository.\n\n%d\n%@", ret, rval]; @@ -254,52 +266,73 @@ # pragma mark Add ref methods -(void)addRef:(id)sender { - [errorMessage setStringValue:@""]; - [NSApp beginSheet:newBranchSheet - modalForWindow:[[historyController view] window] - modalDelegate:NULL - didEndSelector:NULL - contextInfo:NULL]; + [errorMessage setStringValue:@""]; + [NSApp beginSheet:newBranchSheet + modalForWindow:[[historyController view] window] + modalDelegate:NULL + didEndSelector:NULL + contextInfo:NULL]; +} + +- (void) showMessageSheet:(NSString *)title message:(NSString *)msg { + + [[NSAlert alertWithMessageText:title + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:msg] + beginSheetModalForWindow:[[historyController view] window] + modalDelegate:self + didEndSelector:nil + contextInfo:nil]; + + return; } -(void)rebaseButton:(id)sender { - [sender setEnabled:NO]; - NSString *refName = [[historyController.repository.currentBranch simpleRef] refForSpec]; - if (refName) + NSString *refName = [[[[historyController repository] currentBranch] simpleRef] refForSpec]; + if (refName) { [self rebaseImpl:refName]; - [sender setEnabled:YES]; -// NSLog([NSString stringWithFormat:@"Rebase hit for %@!", refName]); + } else { + [self showMessageSheet:@"Pull Rebase from Remote" message:PBInvalidBranchErrMsg]; + } + // NSLog([NSString stringWithFormat:@"Rebase hit for %@!", refName]); } -(void)pushButton:(id)sender { - [sender setEnabled:NO]; - NSString *refName = [[historyController.repository.currentBranch simpleRef] refForSpec]; - if (refName) + NSString *refName = [[[[historyController repository] currentBranch] simpleRef] refForSpec]; + if (refName) { [self pushImpl:refName]; - [sender setEnabled:YES]; -// NSLog([NSString stringWithFormat:@"Push hit for %@!", refName]); + } else { + [self showMessageSheet:@"Push to Remote" message:PBInvalidBranchErrMsg]; + } + // NSLog([NSString stringWithFormat:@"Push hit for %@!", refName]); } --(void)pullButton:(id)sender +- (void) pullButton:(id)sender { - [sender setEnabled:NO]; - NSString *refName = [[historyController.repository.currentBranch simpleRef] refForSpec]; - if (refName) + NSString * refName = [[[[historyController repository] currentBranch] simpleRef] refForSpec]; + if (refName) { [self pullImpl:refName]; - [sender setEnabled:YES]; + } else { + [sender setEnabled:YES]; + [self showMessageSheet:@"Pull from Remote" message:PBInvalidBranchErrMsg]; + } // NSLog([NSString stringWithFormat:@"Pull hit for %@!", refName]); } -(void)fetchButton:(id)sender { - [sender setEnabled:NO]; - NSString *refName = [[historyController.repository.currentBranch simpleRef] refForSpec]; - if (refName) + NSString *refName = [[[[historyController repository] currentBranch] simpleRef] refForSpec]; + if (refName) { [self fetchImpl:refName]; - [sender setEnabled:YES]; -// NSLog([NSString stringWithFormat:@"Fetch hit for %@!", refName]); + } else { + [sender setEnabled:YES]; + [self showMessageSheet:@"Fetch from Remote" message:PBInvalidBranchErrMsg]; + } + // NSLog([NSString stringWithFormat:@"Fetch hit for %@!", refName]); } -(void)saveSheet:(id) sender