Skip to content
This repository has been archived by the owner on Sep 4, 2018. It is now read-only.

Commit

Permalink
Merge pull request #420 from alcatraz/kattrali/check-git-paths
Browse files Browse the repository at this point in the history
[ATZGit] Check possible git executable paths
  • Loading branch information
kattrali committed Jan 29, 2016
2 parents 874f4d3 + 9a0fe15 commit a414a89
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 a414a89

Please sign in to comment.