@@ -112,15 +112,23 @@ - (BOOL)pullBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOptions:
112
112
NSMutableArray <NSString *>*files = [NSMutableArray array ];
113
113
[index enumerateConflictedFilesWithError: error usingBlock: ^(GTIndexEntry * _Nonnull ancestor, GTIndexEntry * _Nonnull ours, GTIndexEntry * _Nonnull theirs, BOOL * _Nonnull stop) {
114
114
[files addObject: ours.path];
115
-
116
- GTMergeFileResult *result = [index mergeIndexEntries: ancestor ours: ours theirs: theirs error: error];
117
- NSURL *oursFileURL = [self .fileURL URLByAppendingPathComponent: result.path];
118
- [result.contents writeToURL: oursFileURL atomically: YES encoding: NSUTF8StringEncoding error: error];
119
115
}];
116
+
120
117
if (error != NULL ) {
121
118
NSDictionary *userInfo = @{GTPullMergeConflictedFiles: files};
122
119
*error = [NSError git_errorFor: GIT_ECONFLICT description: @" Merge conflict, Pull aborted." userInfo: userInfo failureReason: nil ];
123
120
}
121
+
122
+ // Write conflicts
123
+ git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
124
+ git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
125
+ checkout_opts.checkout_strategy = GIT_CHECKOUT_ALLOW_CONFLICTS;
126
+
127
+ git_annotated_commit *annotatedCommit;
128
+ [self annotatedCommit: &annotatedCommit fromCommit: remoteCommit error: error];
129
+
130
+ git_merge (repo.git_repository , (const git_annotated_commit **)&annotatedCommit, 1 , &merge_opts, &checkout_opts);
131
+
124
132
return NO ;
125
133
}
126
134
@@ -146,6 +154,16 @@ - (BOOL)pullBranch:(GTBranch *)branch fromRemote:(GTRemote *)remote withOptions:
146
154
return NO ;
147
155
}
148
156
157
+ - (BOOL )annotatedCommit : (git_annotated_commit **)annotatedCommit fromCommit : (GTCommit *)fromCommit error : (NSError **)error {
158
+ int gitError = git_annotated_commit_lookup (annotatedCommit, self.git_repository , fromCommit.OID .git_oid );
159
+ if (gitError != GIT_OK) {
160
+ if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to lookup annotated commit for %@ " , fromCommit];
161
+ return NO ;
162
+ }
163
+
164
+ return YES ;
165
+ }
166
+
149
167
- (BOOL )analyzeMerge : (GTMergeAnalysis *)analysis fromBranch : (GTBranch *)fromBranch error : (NSError **)error {
150
168
NSParameterAssert (analysis != NULL );
151
169
NSParameterAssert (fromBranch != nil );
@@ -156,18 +174,13 @@ - (BOOL)analyzeMerge:(GTMergeAnalysis *)analysis fromBranch:(GTBranch *)fromBran
156
174
}
157
175
158
176
git_annotated_commit *annotatedCommit;
159
-
160
- int gitError = git_annotated_commit_lookup (&annotatedCommit, self.git_repository , fromCommit.OID .git_oid );
161
- if (gitError != GIT_OK) {
162
- if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to lookup annotated comit for %@ " , fromCommit];
163
- return NO ;
164
- }
177
+ [self annotatedCommit: &annotatedCommit fromCommit: fromCommit error: error];
165
178
166
179
// Allow fast-forward or normal merge
167
180
git_merge_preference_t preference = GIT_MERGE_PREFERENCE_NONE;
168
181
169
182
// Merge analysis
170
- gitError = git_merge_analysis ((git_merge_analysis_t *)analysis, &preference, self.git_repository , (const git_annotated_commit **) &annotatedCommit, 1 );
183
+ int gitError = git_merge_analysis ((git_merge_analysis_t *)analysis, &preference, self.git_repository , (const git_annotated_commit **) &annotatedCommit, 1 );
171
184
if (gitError != GIT_OK) {
172
185
if (error != NULL ) *error = [NSError git_errorFor: gitError description: @" Failed to analyze merge" ];
173
186
return NO ;
0 commit comments