Skip to content
Open
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
2 changes: 2 additions & 0 deletions GitUp/Application/Document.m
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ - (BOOL)readFromURL:(NSURL*)url ofType:(NSString*)typeName error:(NSError**)outE
}
#endif
_repository.delegate = self;
_repository.credentialHelperMode = kGCCredentialHelperMode_Interactive; // Consult the Git credential helpers (e.g. gh, osxkeychain, Git Credential Manager) before the Keychain and the login dialog
_repository.undoManager = self.undoManager;
_repository.snapshotsEnabled = YES;
if ([NSApp isActive]) {
Expand Down Expand Up @@ -1925,6 +1926,7 @@ - (IBAction)checkForChanges:(id)sender {
NSMutableDictionary* updatedReferences = [[NSMutableDictionary alloc] init];
GCRepository* repository = [[GCRepository alloc] initWithExistingLocalRepository:path error:NULL];
repository.delegate = (id<GCRepositoryDelegate>)self.class; // Don't use self as we don't want to show progress UI nor authentication prompts
repository.credentialHelperMode = kGCCredentialHelperMode_NonInteractive; // Same for Git credential helpers: they may not prompt during an automatic check
for (GCRemote* remote in [repository listRemotes:NULL]) {
@autoreleasepool {
NSDictionary* added;
Expand Down
13 changes: 3 additions & 10 deletions GitUpKit/Core/GCCommitSigning.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
return repository.workingDirectoryPath ?: repository.repositoryPath;
}

static NSError* _TaskFailureError(NSString* message, int status, NSData* stdoutData, NSData* stderrData) {
NSString* output = _StringFromTaskOutput(stderrData.length ? stderrData : stdoutData);
NSString* reason = output.length ? [NSString stringWithFormat:@": %@", output] : @"";
return GCNewError(kGCErrorCode_Generic, [NSString stringWithFormat:@"%@ exited with non-zero status (%i)%@", message, status, reason]);
}

static GCTask* _TaskWithPATH(GCRepository* repository, NSString* executablePath, NSString* path) {
GCTask* task = [[GCTask alloc] initWithExecutablePath:executablePath];
task.currentDirectoryPath = _RepositoryTaskDirectoryPath(repository);
Expand Down Expand Up @@ -87,8 +81,7 @@ static BOOL _ShouldSSHSignCommit(GCRepository* repository, BOOL* shouldSign, NSE
}

static NSString* _CommitSigningPATH(GCRepository* repository, NSError** error) {
NSString* shell = NSProcessInfo.processInfo.environment[@"SHELL"];
NSString* path = [repository getPATHUsingShell:shell error:error] ?: [repository getPATHUsingShell:@"/bin/sh" error:error];
NSString* path = [repository getUserPATH:error]; // Deliberately not cached: refreshed once per signing operation
XLOG_DEBUG_CHECK(path);
return path;
}
Expand All @@ -107,7 +100,7 @@ static BOOL _LooksLikeInlineSSHKey(NSString* key) {
}
if (status != 0) {
if (error) {
*error = _TaskFailureError(@"SSH signing default key command", status, stdoutData, stderrData);
*error = GCNewErrorFromTaskFailure(@"SSH signing default key command", status, stdoutData, stderrData);
}
return nil;
}
Expand Down Expand Up @@ -204,7 +197,7 @@ static BOOL _LooksLikeInlineSSHKey(NSString* key) {
}
if (status != 0) {
if (error) {
*error = _TaskFailureError(@"SSH commit signer", status, stdoutData, stderrData);
*error = GCNewErrorFromTaskFailure(@"SSH commit signer", status, stdoutData, stderrData);
}
return nil;
}
Expand Down
2 changes: 1 addition & 1 deletion GitUpKit/Core/GCLiveRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ - (void)performOperationInBackgroundWithReason:(NSString*)reason
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
GCRepository* repository = [[GCRepository alloc] initWithExistingLocalRepository:self.repositoryPath error:&error];
repository.delegate = self.delegate;
[repository inheritRemoteSettingsFromRepository:self];
__block BOOL success = repository && operationBlock(repository, &error);
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
Expand Down
4 changes: 4 additions & 0 deletions GitUpKit/Core/GCPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,16 @@ extern int git_submodule_foreach_block(git_repository* repo, int (^block)(git_su
@interface GCTask : NSObject
@property(nonatomic, readonly) NSString* executablePath;
@property(nonatomic) NSTimeInterval executionTimeOut; // Default is 0.0 i.e. no timeout
@property(nonatomic, readonly) BOOL timedOut; // Whether the last run was ended by the timeout
@property(nonatomic, copy) NSDictionary* additionalEnvironment;
@property(nonatomic, copy) NSString* currentDirectoryPath;
@property(nonatomic) BOOL fallBackToDefaultInterpreter;
- (instancetype)initWithExecutablePath:(NSString*)path;
- (BOOL)runWithArguments:(NSArray*)arguments stdin:(NSData*)stdin stdout:(NSData**)stdout stderr:(NSData**)stderr exitStatus:(int*)exitStatus error:(NSError**)error; // Returns NO if "exitStatus" is NULL and executable exits with a non-zero status
@end

extern NSError* GCNewErrorFromTaskFailure(NSString* message, int status, NSData* stdoutData, NSData* stderrData); // "{message} exited with non-zero status ({status}): {stderr or stdout}"

#endif

@interface GCObject () {
Expand Down Expand Up @@ -266,6 +269,7 @@ extern int git_submodule_foreach_block(git_repository* repo, int (^block)(git_su
- (BOOL)exportBlobWithOID:(const git_oid*)oid toPath:(NSString*)path error:(NSError**)error;
#if !TARGET_OS_IPHONE
- (NSString*)getPATHUsingShell:(NSString*)shell error:(NSError**)error;
- (NSString*)getUserPATH:(NSError**)error; // PATH from the user's login shell, falling back to /bin/sh - Not cached
#endif
@end

Expand Down
14 changes: 12 additions & 2 deletions GitUpKit/Core/GCPrivate.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

#if !TARGET_OS_IPHONE

NSError* GCNewErrorFromTaskFailure(NSString* message, int status, NSData* stdoutData, NSData* stderrData) {
NSString* output = [[[NSString alloc] initWithData:(stderrData.length ? stderrData : stdoutData) encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString* reason = output.length ? [NSString stringWithFormat:@": %@", output] : @"";
return GCNewError(kGCErrorCode_Generic, [NSString stringWithFormat:@"%@ exited with non-zero status (%i)%@", message, status, reason]);
}

@implementation GCTask {
NSFileHandle* _outFileHandle;
NSMutableData* _outData;
Expand All @@ -36,7 +42,8 @@ - (instancetype)initWithExecutablePath:(NSString*)path {
}

- (void)_timer:(NSTimer*)timer {
[(NSTask*)timer.userInfo terminate];
_timedOut = YES;
[(NSTask*)timer.userInfo terminate]; // This signals the whole process group i.e. also the processes started by the executable
[(NSTask*)timer.userInfo interrupt];
}

Expand Down Expand Up @@ -74,6 +81,7 @@ - (BOOL)_runWithDefaultInterpreter:(BOOL)useSH arguments:(NSArray*)arguments std
NSPipe* errorPipe = nil;
NSTimer* timer = nil;

_timedOut = NO;
NSTask* task = [[NSTask alloc] init];
task.launchPath = useSH ? @"/bin/sh" : _executablePath;
NSMutableDictionary* environment = [[NSMutableDictionary alloc] initWithDictionary:[[NSProcessInfo processInfo] environment]];
Expand Down Expand Up @@ -140,9 +148,11 @@ - (BOOL)_runWithDefaultInterpreter:(BOOL)useSH arguments:(NSArray*)arguments std
*stderr = _errorData;
}
[task waitUntilExit];
while (_outFileHandle || _errorFileHandle) {
while ((_outFileHandle || _errorFileHandle) && !_timedOut) { // After a timeout don't wait on the pipes: a process started by the executable that survived (signals ignored, or left the process group) may hold them open
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, true);
}
_outFileHandle = nil;
_errorFileHandle = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleDataAvailableNotification object:nil];
[timer invalidate];
if (exitStatus) {
Expand Down
Loading