Skip to content

Commit 6783c56

Browse files
committed
Hoist normal-merge branch from if
This is a cosmetic-only change for diff clarity
1 parent aa7db65 commit 6783c56

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed

ObjectiveGit/GTRepository+Merging.m

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -136,65 +136,63 @@ - (BOOL)mergeBranchIntoCurrentBranch:(GTBranch *)branch withError:(NSError **)er
136136
GTReference *reference = [localBranch.reference referenceByUpdatingTarget:remoteCommit.SHA message:message error:error];
137137
BOOL checkoutSuccess = [self checkoutReference:reference options:[GTCheckoutOptions checkoutOptionsWithStrategy:GTCheckoutStrategyForce] error:error];
138138
return checkoutSuccess;
139-
} else if (analysis & GTMergeAnalysisNormal) {
140-
// Do normal merge
141-
GTTree *localTree = localCommit.tree;
142-
GTTree *remoteTree = remoteCommit.tree;
143-
144-
// TODO: Find common ancestor
145-
GTTree *ancestorTree = nil;
146-
147-
// Merge
148-
GTIndex *index = [localTree merge:remoteTree ancestor:ancestorTree error:error];
149-
if (!index) {
150-
return NO;
151-
}
152-
153-
// Check for conflict
154-
if (index.hasConflicts) {
155-
NSMutableArray <NSString *>*files = [NSMutableArray array];
156-
[index enumerateConflictedFilesWithError:error usingBlock:^(GTIndexEntry * _Nonnull ancestor, GTIndexEntry * _Nonnull ours, GTIndexEntry * _Nonnull theirs, BOOL * _Nonnull stop) {
157-
[files addObject:ours.path];
158-
}];
139+
}
159140

160-
if (error != NULL) {
161-
NSDictionary *userInfo = @{GTPullMergeConflictedFiles: files};
162-
*error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict" userInfo:userInfo failureReason:nil];
163-
}
141+
// Do normal merge
142+
GTTree *localTree = localCommit.tree;
143+
GTTree *remoteTree = remoteCommit.tree;
164144

165-
// Write conflicts
166-
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
167-
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
168-
checkout_opts.checkout_strategy = (GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS);
145+
// TODO: Find common ancestor
146+
GTTree *ancestorTree = nil;
169147

170-
git_annotated_commit *annotatedCommit;
171-
[self annotatedCommit:&annotatedCommit fromCommit:remoteCommit error:error];
148+
// Merge
149+
GTIndex *index = [localTree merge:remoteTree ancestor:ancestorTree error:error];
150+
if (!index) {
151+
return NO;
152+
}
172153

173-
git_merge(self.git_repository, (const git_annotated_commit **)&annotatedCommit, 1, &merge_opts, &checkout_opts);
154+
// Check for conflict
155+
if (index.hasConflicts) {
156+
NSMutableArray <NSString *>*files = [NSMutableArray array];
157+
[index enumerateConflictedFilesWithError:error usingBlock:^(GTIndexEntry * _Nonnull ancestor, GTIndexEntry * _Nonnull ours, GTIndexEntry * _Nonnull theirs, BOOL * _Nonnull stop) {
158+
[files addObject:ours.path];
159+
}];
174160

175-
return NO;
161+
if (error != NULL) {
162+
NSDictionary *userInfo = @{GTPullMergeConflictedFiles: files};
163+
*error = [NSError git_errorFor:GIT_ECONFLICT description:@"Merge conflict" userInfo:userInfo failureReason:nil];
176164
}
177165

178-
GTTree *newTree = [index writeTreeToRepository:self error:error];
179-
if (!newTree) {
180-
return NO;
181-
}
166+
// Write conflicts
167+
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
168+
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
169+
checkout_opts.checkout_strategy = (GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS);
182170

183-
// Create merge commit
184-
NSString *message = [NSString stringWithFormat:@"Merge branch '%@'", localBranch.shortName];
185-
NSArray *parents = @[ localCommit, remoteCommit ];
171+
git_annotated_commit *annotatedCommit;
172+
[self annotatedCommit:&annotatedCommit fromCommit:remoteCommit error:error];
186173

187-
// FIXME: This is stepping on the local tree
188-
GTCommit *mergeCommit = [self createCommitWithTree:newTree message:message parents:parents updatingReferenceNamed:localBranch.reference.name error:error];
189-
if (!mergeCommit) {
190-
return NO;
191-
}
174+
git_merge(self.git_repository, (const git_annotated_commit **)&annotatedCommit, 1, &merge_opts, &checkout_opts);
192175

193-
BOOL success = [self checkoutReference:localBranch.reference options:[GTCheckoutOptions checkoutOptionsWithStrategy:GTCheckoutStrategyForce] error:error];
194-
return success;
176+
return NO;
177+
}
178+
179+
GTTree *newTree = [index writeTreeToRepository:self error:error];
180+
if (!newTree) {
181+
return NO;
182+
}
183+
184+
// Create merge commit
185+
NSString *message = [NSString stringWithFormat:@"Merge branch '%@'", localBranch.shortName];
186+
NSArray *parents = @[ localCommit, remoteCommit ];
187+
188+
// FIXME: This is stepping on the local tree
189+
GTCommit *mergeCommit = [self createCommitWithTree:newTree message:message parents:parents updatingReferenceNamed:localBranch.reference.name error:error];
190+
if (!mergeCommit) {
191+
return NO;
195192
}
196193

197-
return NO;
194+
success = [self checkoutReference:localBranch.reference options:[GTCheckoutOptions checkoutOptionsWithStrategy:GTCheckoutStrategyForce] error:error];
195+
return success;
198196
}
199197

200198
- (NSString * _Nullable)contentsOfDiffWithAncestor:(GTIndexEntry *)ancestor ourSide:(GTIndexEntry *)ourSide theirSide:(GTIndexEntry *)theirSide error:(NSError **)error {

0 commit comments

Comments
 (0)