Skip to content

Commit

Permalink
[ATZGit] Check possible git executable paths
Browse files Browse the repository at this point in the history
This expands the check for command line tools to include /usr/local as
well as /usr, fixing new El Capitan installations
  • Loading branch information
kattrali committed Jan 25, 2016
1 parent 874f4d3 commit 9a0fe15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
1 change: 0 additions & 1 deletion Alcatraz/Helpers/ATZGit.h
Expand Up @@ -22,7 +22,6 @@

#import <Foundation/Foundation.h>

static NSString *const GIT = @"/usr/bin/git";
static NSString *const IGNORE_PUSH_CONFIG = @"-c push.default=matching";
static NSString *const CLONE = @"clone";
static NSString *const FETCH = @"fetch";
Expand Down
41 changes: 28 additions & 13 deletions Alcatraz/Helpers/ATZGit.m
Expand Up @@ -48,22 +48,37 @@ + (NSString *)parseRevisionFromDictionary:(NSDictionary *)dict {
}

+ (BOOL)areCommandLineToolsAvailable {
BOOL areAvailable = YES;
@try {
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/git" arguments:@[@"--version"]];
}
@catch (NSException *exception) {
areAvailable = NO;
}
return areAvailable;
return [self gitExecutablePath] != nil;
}

+ (NSString *)gitExecutablePath {
static dispatch_once_t onceToken;
static NSString *gitPath;
dispatch_once(&onceToken, ^{
NSArray *gitPathOptions = @[
@"/usr/bin/git",
@"/usr/local/bin/git"
];
for (NSString *path in gitPathOptions) {
@try {
[NSTask launchedTaskWithLaunchPath:path arguments:@[@"--version"]];
}
@catch (NSException *exception) {
continue;
}
gitPath = path;
break;
}
});
return gitPath;
}

#pragma mark - Private

+ (void)clone:(NSString *)remotePath to:(NSString *)localPath completion:(void (^)(NSString *, NSError *))completion {
ATZShell *shell = [ATZShell new];
[shell executeCommand:GIT withArguments:@[CLONE, remotePath, localPath, IGNORE_PUSH_CONFIG]

[shell executeCommand:[self gitExecutablePath] withArguments:@[CLONE, remotePath, localPath, IGNORE_PUSH_CONFIG]
completion:^(NSString *output, NSError *error) {

NSLog(@"Git Clone output: %@", output);
Expand All @@ -89,7 +104,7 @@ + (void)updateLocalProject:(NSString *)localPath revision:(NSString *)revision
+ (void)fetch:(NSString *)localPath completion:(void (^)(NSString *, NSError *))completion {

ATZShell *shell = [ATZShell new];
[shell executeCommand:GIT withArguments:@[FETCH, ORIGIN] inWorkingDirectory:localPath
[shell executeCommand:[self gitExecutablePath] withArguments:@[FETCH, ORIGIN] inWorkingDirectory:localPath
completion:^(NSString *output, NSError *error) {

NSLog(@"Git fetch output: %@", output);
Expand All @@ -102,8 +117,8 @@ + (void)resetHard:(NSString *)localPath revision:(NSString *)revision

ATZShell *shell = [ATZShell new];
NSArray *resetArguments = @[RESET, HARD, revision ?: ORIGIN_MASTER];
[shell executeCommand:GIT withArguments:resetArguments inWorkingDirectory:localPath

[shell executeCommand:[self gitExecutablePath] withArguments:resetArguments inWorkingDirectory:localPath
completion:^(NSString *output, NSError *error) {

NSLog(@"Git reset output: %@", output);
Expand Down

0 comments on commit 9a0fe15

Please sign in to comment.