Skip to content

Commit b3e13c1

Browse files
committed
Obey the branch config w.r.t preferred merge types
1 parent 6783c56 commit b3e13c1

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

ObjectiveGit/GTRepository+Merging.m

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,35 @@ - (BOOL)mergeBranchIntoCurrentBranch:(GTBranch *)branch withError:(NSError **)er
120120
return NO;
121121
}
122122

123+
GTAnnotatedCommit *remoteAnnotatedCommit = [GTAnnotatedCommit annotatedCommitFromReference:branch.reference error:error];
124+
if (!remoteAnnotatedCommit) {
125+
return NO;
126+
}
127+
123128
GTMergeAnalysis analysis = GTMergeAnalysisNone;
124-
BOOL success = [self analyzeMerge:&analysis fromBranch:branch error:error];
129+
GTMergePreference preference = GTMergePreferenceNone;
130+
BOOL success = [self analyzeMerge:&analysis preference:&preference fromAnnotatedCommits:@[remoteAnnotatedCommit] error:error];
125131
if (!success) {
126132
return NO;
127133
}
128134

129135
if (analysis & GTMergeAnalysisUpToDate) {
130136
// Nothing to do
131137
return YES;
132-
} else if (analysis & GTMergeAnalysisFastForward ||
133-
analysis & GTMergeAnalysisUnborn) {
138+
} else if (analysis & GTMergeAnalysisFastForward && preference == GTMergePreferenceNoFastForward) {
134139
// Fast-forward branch
140+
if (error != NULL) {
141+
*error = [NSError git_errorFor:GIT_ERROR description:@"Normal merge not possible for branch '%@'", branch.name];
142+
}
143+
return NO;
144+
} else if (analysis & GTMergeAnalysisNormal && preference == GTMergePreferenceFastForwardOnly) {
145+
if (error != NULL) {
146+
*error = [NSError git_errorFor:GIT_ERROR description:@"Fast-forward not possible for branch '%@'", branch.name];
147+
}
148+
return NO;
149+
}
150+
151+
if (analysis & GTMergeAnalysisFastForward) {
135152
NSString *message = [NSString stringWithFormat:@"merge %@: Fast-forward", branch.name];
136153
GTReference *reference = [localBranch.reference referenceByUpdatingTarget:remoteCommit.SHA message:message error:error];
137154
BOOL checkoutSuccess = [self checkoutReference:reference options:[GTCheckoutOptions checkoutOptionsWithStrategy:GTCheckoutStrategyForce] error:error];

0 commit comments

Comments
 (0)