Skip to content

Commit f3758ac

Browse files
committed
Wire PBGitBinarySupport to PBTask
1 parent d4192a4 commit f3758ac

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

Classes/git/PBGitIndex.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
290290

291291
[self postCommitUpdate:@"Creating tree"];
292292
NSString *tree = [self.repository outputForCommand:@"write-tree"];
293+
tree = [tree stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
293294
if ([tree length] != 40)
294295
return [self postCommitFailure:@"Creating tree failed"];
295296

@@ -337,7 +338,7 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
337338
inputString:commitMessage
338339
byExtendingEnvironment:self.amendEnvironment
339340
retValue: &ret];
340-
341+
commit = [commit stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
341342
if (ret || [commit length] != 40)
342343
return [self postCommitFailure:@"Could not create a commit object"];
343344

Classes/git/PBGitRepository_PBGitBinarySupport.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ NS_ASSUME_NONNULL_BEGIN
2323
@interface PBGitRepository (PBGitBinarySupportDeprecated)
2424
- (NSFileHandle*) handleForArguments:(NSArray*) args GITX_DEPRECATED;
2525
- (NSString*) outputForCommand:(NSString*) cmd GITX_DEPRECATED;
26-
- (NSString *)outputForCommand:(NSString *)str retValue:(int *)ret GITX_DEPRECATED;
27-
- (NSString *)outputForArguments:(NSArray *)arguments inputString:(NSString *)input retValue:(int *)ret GITX_DEPRECATED;
28-
- (NSString *)outputForArguments:(NSArray *)arguments inputString:(NSString *)input byExtendingEnvironment:(NSDictionary *)dict retValue:(int *)ret GITX_DEPRECATED;
26+
- (NSString *)outputForCommand:(NSString *)str retValue:(nullable int *)ret GITX_DEPRECATED;
27+
- (NSString *)outputForArguments:(NSArray *)arguments inputString:(nullable NSString *)input retValue:(nullable int *)ret GITX_DEPRECATED;
28+
- (NSString *)outputForArguments:(NSArray *)arguments inputString:(nullable NSString *)input byExtendingEnvironment:(nullable NSDictionary *)dict retValue:(nullable int *)ret GITX_DEPRECATED;
2929

3030

3131
- (NSString*) outputForArguments:(NSArray*) args GITX_DEPRECATED;
32-
- (NSString*) outputForArguments:(NSArray*) args retValue:(int *)ret GITX_DEPRECATED;
32+
- (NSString*) outputForArguments:(NSArray*) args retValue:(nullable int *)ret GITX_DEPRECATED;
3333
- (NSString *)outputInWorkdirForArguments:(NSArray*) arguments GITX_DEPRECATED;
34-
- (NSString *)outputInWorkdirForArguments:(NSArray*) arguments retValue:(int *)ret GITX_DEPRECATED;
34+
- (NSString *)outputInWorkdirForArguments:(NSArray*) arguments retValue:(nullable int *)ret GITX_DEPRECATED;
3535
@end
3636

3737
NS_ASSUME_NONNULL_END

Classes/git/PBGitRepository_PBGitBinarySupport.m

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,51 +71,63 @@ - (NSFileHandle*) handleForArguments:(NSArray *)args
7171
- (NSString*) outputForCommand:(NSString *)cmd
7272
{
7373
NSArray* arguments = [cmd componentsSeparatedByString:@" "];
74-
return [self outputForArguments: arguments];
74+
return [self outputForArguments:arguments inputString:nil byExtendingEnvironment:nil retValue:NULL];
7575
}
7676

7777
- (NSString*) outputForCommand:(NSString *)str retValue:(int *)ret;
7878
{
7979
NSArray* arguments = [str componentsSeparatedByString:@" "];
80-
return [self outputForArguments: arguments retValue: ret];
80+
return [self outputForArguments:arguments inputString:nil byExtendingEnvironment:nil retValue:ret];
8181
}
8282

8383
- (NSString*) outputForArguments:(NSArray*) arguments
8484
{
85-
return [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir: self.workingDirectory];
85+
return [self outputForArguments:arguments inputString:nil byExtendingEnvironment:nil retValue:NULL];
8686
}
8787

8888
- (NSString*) outputInWorkdirForArguments:(NSArray*) arguments
8989
{
90-
return [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:self.workingDirectory];
90+
return [self outputForArguments:arguments inputString:nil byExtendingEnvironment:nil retValue:NULL];
9191
}
9292

9393
- (NSString*) outputInWorkdirForArguments:(NSArray *)arguments retValue:(int *)ret
9494
{
95-
return [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:self.workingDirectory retValue: ret];
95+
return [self outputForArguments:arguments inputString:nil byExtendingEnvironment:nil retValue:ret];
9696
}
9797

9898
- (NSString*) outputForArguments:(NSArray *)arguments retValue:(int *)ret
9999
{
100-
return [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir: self.workingDirectory retValue: ret];
100+
return [self outputForArguments:arguments inputString:nil byExtendingEnvironment:nil retValue:ret];
101101
}
102102

103103
- (NSString*) outputForArguments:(NSArray *)arguments inputString:(NSString *)input retValue:(int *)ret
104104
{
105-
return [PBEasyPipe outputForCommand:[PBGitBinary path]
106-
withArgs:arguments
107-
inDir:self.workingDirectory
108-
inputString:input
109-
retValue: ret];
105+
return [self outputForArguments:arguments inputString:input byExtendingEnvironment:nil retValue:ret];
110106
}
111107

112108
- (NSString *)outputForArguments:(NSArray *)arguments inputString:(NSString *)input byExtendingEnvironment:(NSDictionary *)dict retValue:(int *)ret
113109
{
114-
return [PBEasyPipe outputForCommand:[PBGitBinary path]
115-
withArgs:arguments
116-
inDir:self.workingDirectory
117-
byExtendingEnvironment:dict
118-
inputString:input
119-
retValue: ret];
110+
PBTask *task = [self taskWithArguments:arguments];
111+
if (input)
112+
task.standardInputData = [input dataUsingEncoding:NSUTF8StringEncoding];
113+
if (dict)
114+
task.additionalEnvironment = dict;
115+
116+
NSError *error = nil;
117+
BOOL success = [task launchTask:&error];
118+
if (!success) {
119+
PBLogError(error);
120+
NSNumber *status;
121+
if (ret && (status = error.userInfo[PBTaskTerminationStatusKey])) {
122+
*ret = [status intValue];
123+
} else if (ret) {
124+
*ret = 1;
125+
}
126+
127+
return nil;
128+
}
129+
if (ret) *ret = 0;
130+
131+
return task.standardOutputString;
120132
}
121133
@end

0 commit comments

Comments
 (0)