Skip to content

Added check for _lastHEADBranch to be not NSNull. #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions GitUp/Application/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#import <GitUpKit/GitUpKit.h>
#import "Document.h"

@interface AppDelegate : NSObject <NSApplicationDelegate, GCRepositoryDelegate>
@property(nonatomic, strong) IBOutlet NSWindow* preferencesWindow;
Expand Down Expand Up @@ -48,4 +49,7 @@
- (void)repository:(GCRepository*)repository didFinishTransferWithURL:(NSURL*)url success:(BOOL)success;

- (void)handleDocumentCountChanged;
- (void)openRepositoryWithURL:(NSURL*)url withCloneMode:(CloneMode)cloneMode windowModeID:(WindowModeID)windowModeID;
- (void)cloneWithURL:(NSURL *)url;

@end
108 changes: 70 additions & 38 deletions GitUp/Application/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,36 @@ @interface WelcomeWindow : NSWindow

@implementation WelcomeWindow

- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
return menuItem.action == @selector(performClose:) ? YES : [super validateMenuItem:menuItem];
- (void)awakeFromNib {
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSURLPboardType, NSStringPboardType, nil]];
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
return NSDragOperationCopy;
}

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSPasteboard *pboard;
NSURL* url;
AppDelegate* ad = [AppDelegate sharedDelegate];
pboard = [sender draggingPasteboard];
NSArray* types = [pboard types];
NSLog(@"types: %@", types);

if ([types containsObject:@"public.file-url"]) {
url = [NSURL URLFromPasteboard:pboard];
NSLog(@"url: %@", url);
[ad openRepositoryWithURL:url withCloneMode:kCloneMode_None windowModeID:NSNotFound];
} else if ([types containsObject:@"NSStringPboardType"]) {
NSString *text = [pboard stringForType:NSStringPboardType];
url = [NSURL URLWithString:text];
NSString* ext = [url pathExtension];
NSLog(@"url: %@ ext: %@", url, ext);
if ([ext isEqualToString:@"git"]) {
[ad cloneWithURL:url];
}
}
return YES;
}

- (void)performClose:(id)sender {
Expand Down Expand Up @@ -202,7 +230,7 @@ - (void)_setDocumentWindowModeID:(NSArray*)arguments {
[(Document*)arguments[0] setWindowModeID:[arguments[1] unsignedIntegerValue]];
}

- (void)_openRepositoryWithURL:(NSURL*)url withCloneMode:(CloneMode)cloneMode windowModeID:(WindowModeID)windowModeID {
- (void)openRepositoryWithURL:(NSURL*)url withCloneMode:(CloneMode)cloneMode windowModeID:(WindowModeID)windowModeID {
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url
display:YES
completionHandler:^(NSDocument* document, BOOL documentWasAlreadyOpen, NSError* openError) {
Expand All @@ -227,7 +255,7 @@ - (void)_openRepositoryWithURL:(NSURL*)url withCloneMode:(CloneMode)cloneMode wi
}

- (void)_openDocument:(NSMenuItem*)sender {
[self _openRepositoryWithURL:sender.representedObject withCloneMode:kCloneMode_None windowModeID:NSNotFound];
[self openRepositoryWithURL:sender.representedObject withCloneMode:kCloneMode_None windowModeID:NSNotFound];
}

- (void)_willShowRecentPopUpMenu:(NSNotification*)notification {
Expand Down Expand Up @@ -462,13 +490,13 @@ - (NSDictionary*)_processToolCommand:(NSDictionary*)input {
return @{kToolDictionaryKey_Error: @"Invalid command"};
}
if ([command isEqualToString:@kToolCommand_Open]) {
[self _openRepositoryWithURL:[NSURL fileURLWithPath:repository] withCloneMode:kCloneMode_None windowModeID:NSNotFound];
[self openRepositoryWithURL:[NSURL fileURLWithPath:repository] withCloneMode:kCloneMode_None windowModeID:NSNotFound];
} else if ([command isEqualToString:@kToolCommand_Map]) {
[self _openRepositoryWithURL:[NSURL fileURLWithPath:repository] withCloneMode:kCloneMode_None windowModeID:kWindowModeID_Map];
[self openRepositoryWithURL:[NSURL fileURLWithPath:repository] withCloneMode:kCloneMode_None windowModeID:kWindowModeID_Map];
} else if ([command isEqualToString:@kToolCommand_Commit]) {
[self _openRepositoryWithURL:[NSURL fileURLWithPath:repository] withCloneMode:kCloneMode_None windowModeID:kWindowModeID_Commit];
[self openRepositoryWithURL:[NSURL fileURLWithPath:repository] withCloneMode:kCloneMode_None windowModeID:kWindowModeID_Commit];
} else if ([command isEqualToString:@kToolCommand_Stash]) {
[self _openRepositoryWithURL:[NSURL fileURLWithPath:repository] withCloneMode:kCloneMode_None windowModeID:kWindowModeID_Stashes];
[self openRepositoryWithURL:[NSURL fileURLWithPath:repository] withCloneMode:kCloneMode_None windowModeID:kWindowModeID_Stashes];
} else {
return @{kToolDictionaryKey_Error: [NSString stringWithFormat:@"Unknown command '%@'", command]};
}
Expand Down Expand Up @@ -563,7 +591,7 @@ - (IBAction)newRepository:(id)sender {
if (![[NSFileManager defaultManager] fileExistsAtPath:path] || [[NSFileManager defaultManager] moveItemAtPathToTrash:path error:&error]) {
GCRepository* repository = [[GCRepository alloc] initWithNewLocalRepository:path bare:NO error:&error];
if (repository) {
[self _openRepositoryWithURL:[NSURL fileURLWithPath:repository.workingDirectoryPath] withCloneMode:kCloneMode_None windowModeID:NSNotFound];
[self openRepositoryWithURL:[NSURL fileURLWithPath:repository.workingDirectoryPath] withCloneMode:kCloneMode_None windowModeID:NSNotFound];
} else {
[NSApp presentError:error];
}
Expand All @@ -573,43 +601,47 @@ - (IBAction)newRepository:(id)sender {
}
}

- (IBAction)cloneRepository:(id)sender {
_cloneURLTextField.stringValue = @"";
_cloneRecursiveButton.state = NSOnState;
if ([NSApp runModalForWindow:_cloneWindow] && _cloneURLTextField.stringValue.length) {
NSURL* url = GCURLFromGitURL(_cloneURLTextField.stringValue);
if (url) {
NSString* name = [url.path.lastPathComponent stringByDeletingPathExtension];
NSSavePanel* savePanel = [NSSavePanel savePanel];
savePanel.title = NSLocalizedString(@"Clone Repository", nil);
savePanel.prompt = NSLocalizedString(@"Clone", nil);
savePanel.nameFieldLabel = NSLocalizedString(@"Name:", nil);
savePanel.nameFieldStringValue = name ? name : @"";
if ([savePanel respondsToSelector:@selector(setShowsTagField:)]) {
[savePanel setShowsTagField:NO];
}
if ([savePanel runModal] == NSFileHandlingPanelOKButton) {
NSString* path = savePanel.URL.path;
NSError* error;
if (![[NSFileManager defaultManager] fileExistsAtPath:path] || [[NSFileManager defaultManager] moveItemAtPathToTrash:path error:&error]) {
GCRepository* repository = [[GCRepository alloc] initWithNewLocalRepository:path bare:NO error:&error];
if (repository) {
if ([repository addRemoteWithName:@"origin" url:url error:&error]) {
[self _openRepositoryWithURL:[NSURL fileURLWithPath:repository.workingDirectoryPath] withCloneMode:(_cloneRecursiveButton.state ? kCloneMode_Recursive : kCloneMode_Default) windowModeID:NSNotFound];
} else {
[NSApp presentError:error];
[[NSFileManager defaultManager] removeItemAtPath:path error:NULL]; // Ignore errors
}
- (void)cloneWithURL:(NSURL *)url {
if (url) {
NSString* name = [url.path.lastPathComponent stringByDeletingPathExtension];
NSSavePanel* savePanel = [NSSavePanel savePanel];
savePanel.title = NSLocalizedString(@"Clone Repository", nil);
savePanel.prompt = NSLocalizedString(@"Clone", nil);
savePanel.nameFieldLabel = NSLocalizedString(@"Name:", nil);
savePanel.nameFieldStringValue = name ? name : @"";
if ([savePanel respondsToSelector:@selector(setShowsTagField:)]) {
[savePanel setShowsTagField:NO];
}
if ([savePanel runModal] == NSFileHandlingPanelOKButton) {
NSString* path = savePanel.URL.path;
NSError* error;
if (![[NSFileManager defaultManager] fileExistsAtPath:path] || [[NSFileManager defaultManager] moveItemAtPathToTrash:path error:&error]) {
GCRepository* repository = [[GCRepository alloc] initWithNewLocalRepository:path bare:NO error:&error];
if (repository) {
if ([repository addRemoteWithName:@"origin" url:url error:&error]) {
[self openRepositoryWithURL:[NSURL fileURLWithPath:repository.workingDirectoryPath] withCloneMode:(_cloneRecursiveButton.state ? kCloneMode_Recursive : kCloneMode_Default) windowModeID:NSNotFound];
} else {
[NSApp presentError:error];
[[NSFileManager defaultManager] removeItemAtPath:path error:NULL]; // Ignore errors
}
} else {
[NSApp presentError:error];
}
} else {
[NSApp presentError:error];
}
} else {
[NSApp presentError:MAKE_ERROR(@"Invalid Git repository URL")];
}
} else {
[NSApp presentError:MAKE_ERROR(@"Invalid Git repository URL")];
}
}

- (IBAction)cloneRepository:(id)sender {
_cloneURLTextField.stringValue = @"";
_cloneRecursiveButton.state = NSOnState;
if ([NSApp runModalForWindow:_cloneWindow] && _cloneURLTextField.stringValue.length) {
NSURL* url = GCURLFromGitURL(_cloneURLTextField.stringValue);
[self cloneWithURL:url];
}
}

Expand Down
2 changes: 2 additions & 0 deletions GitUp/Application/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@ typedef NS_ENUM(NSUInteger, WindowModeID) {

- (BOOL)setWindowModeID:(WindowModeID)modeID;
- (BOOL)shouldCloseDocument;
- (BOOL)readFromURL:(NSURL*)url ofType:(NSString*)typeName error:(NSError**)outError;

@end
12 changes: 9 additions & 3 deletions GitUp/Application/Document.m
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ - (void)mapViewControllerDidReloadGraph:(GIMapViewController*)controller {
}

id headBranch = _repository.history.HEADBranch;
if (_lastHEADBranch) {
if (_lastHEADBranch && _lastHEADBranch != (id)[NSNull null]) {
if (![headBranch isEqualToBranch:_lastHEADBranch]) {
if (!_helpHEADDisabled) {
if ([headBranch isKindOfClass:[GCHistoryLocalBranch class]]) {
Expand Down Expand Up @@ -2054,9 +2054,15 @@ - (IBAction)openInFinder:(id)sender {
}

- (IBAction)openInTerminal:(id)sender {
NSString* script = [NSString stringWithFormat:@"tell application \"Terminal\" to do script \"cd \\\"%@\\\"\"", _repository.workingDirectoryPath];
NSString* script = @"";
NSString* identifier = [[NSUserDefaults standardUserDefaults] stringForKey:GIViewController_TerminalTool];
if ([identifier isEqualToString:GIViewControllerTool_Terminal]) {
script = [NSString stringWithFormat:@"tell application \"Terminal\" to do script \"cd \\\"%@\\\"\"", _repository.workingDirectoryPath];
} else { // must be iTerm
script = [NSString stringWithFormat:@"tell application \"%@\" to write current session of current window text \"cd \\\"%@\\\"\"", identifier, _repository.workingDirectoryPath];
}
[[[NSAppleScript alloc] initWithSource:script] executeAndReturnError:NULL];
[[NSWorkspace sharedWorkspace] launchApplication:@"Terminal"];
[[NSWorkspace sharedWorkspace] launchApplication: identifier];
}

- (IBAction)dismissHelp:(id)sender {
Expand Down
Loading