Skip to content

Commit ec030f0

Browse files
authored
Fix two APIs (#1041)
* Fix checkoutFilesToWorkingDirectory deleting all files when empty path array is passed * Allow cherry-picking/reverting on top of nil parent
1 parent 9be3127 commit ec030f0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

GitUpKit/Core/GCIndex.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ - (BOOL)checkoutFileToWorkingDirectory:(NSString*)path fromIndex:(GCIndex*)index
536536
}
537537

538538
- (BOOL)checkoutFilesToWorkingDirectory:(NSArray<NSString*>*)paths fromIndex:(GCIndex*)index error:(NSError**)error {
539+
if ([paths count] == 0) {
540+
return YES;
541+
}
542+
539543
git_checkout_options options = GIT_CHECKOUT_OPTIONS_INIT;
540544
options.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_DONT_UPDATE_INDEX; // There's no reason to update the index
541545
options.paths.count = paths.count;

GitUpKit/Core/GCRepository+Bare.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ - (GCCommit*)_mergeTheirCommit:(git_commit*)theirCommit
7575
for (NSUInteger i = 0; i < count; ++i) {
7676
[array addObject:_CopyCommit(self, (git_commit*)parents[i])];
7777
}
78-
commit = handler([[GCIndex alloc] initWithRepository:nil index:index], _CopyCommit(self, ourCommit), _CopyCommit(self, theirCommit), array, message, error); // Doesn't make sense to specify a custom author on conflict anyway
78+
commit = handler([[GCIndex alloc] initWithRepository:nil index:index], ourCommit ? _CopyCommit(self, ourCommit) : nil, _CopyCommit(self, theirCommit), array, message, error); // Doesn't make sense to specify a custom author on conflict anyway
7979
index = NULL; // Ownership has been transferred to GCIndex instance
8080
} else {
8181
commit = [self createCommitFromIndex:index withParents:parents count:count author:author message:message error:error];
@@ -95,12 +95,12 @@ - (GCCommit*)cherryPickCommit:(GCCommit*)pickCommit
9595
message:(NSString*)message
9696
conflictHandler:(GCConflictHandler)handler
9797
error:(NSError**)error {
98-
const git_commit* parents[] = {againstCommit.private};
98+
const git_commit** parents = (againstCommit != nil) ? (git_commit*[]) {againstCommit.private} : (git_commit*[]) {};
9999
return [self _mergeTheirCommit:pickCommit.private
100100
intoOurCommit:againstCommit.private
101101
withAncestorCommit:ancestorCommit.private
102102
parents:parents
103-
count:1
103+
count:(againstCommit != nil) ? 1 : 0
104104
author:git_commit_author(pickCommit.private)
105105
message:message
106106
conflictHandler:handler
@@ -113,12 +113,12 @@ - (GCCommit*)revertCommit:(GCCommit*)revertCommit
113113
message:(NSString*)message
114114
conflictHandler:(GCConflictHandler)handler
115115
error:(NSError**)error {
116-
const git_commit* parents[] = {againstCommit.private};
116+
const git_commit** parents = (againstCommit != nil) ? (git_commit*[]) {againstCommit.private} : (git_commit*[]) {};
117117
return [self _mergeTheirCommit:ancestorCommit.private
118118
intoOurCommit:againstCommit.private
119119
withAncestorCommit:revertCommit.private
120120
parents:parents
121-
count:1
121+
count:(againstCommit != nil) ? 1 : 0
122122
author:NULL
123123
message:message
124124
conflictHandler:handler

0 commit comments

Comments
 (0)