Merge "Check for FF_ONLY merges correctly"
This commit is contained in:
commit
83032e9f66
|
@ -52,6 +52,7 @@
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
|
||||||
import org.eclipse.jgit.api.MergeResult.MergeStatus;
|
import org.eclipse.jgit.api.MergeResult.MergeStatus;
|
||||||
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
|
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
@ -203,6 +204,28 @@ public void testMultipleHeads() throws Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeCannotDoRequiredFastForward() throws Exception {
|
||||||
|
Git git = new Git(db);
|
||||||
|
|
||||||
|
RevCommit first = git.commit().setMessage("first").call();
|
||||||
|
createBranch(first, "refs/heads/side");
|
||||||
|
|
||||||
|
writeTrashFile("a", "a");
|
||||||
|
git.add().addFilepattern("a").call();
|
||||||
|
git.commit().setMessage("second").call();
|
||||||
|
|
||||||
|
checkoutBranch("refs/heads/side");
|
||||||
|
writeTrashFile("b", "b");
|
||||||
|
git.add().addFilepattern("b").call();
|
||||||
|
git.commit().setMessage("third").call();
|
||||||
|
|
||||||
|
MergeResult result = git.merge().include(db.getRef(Constants.MASTER))
|
||||||
|
.setFastForward(FastForwardMode.NO_FF)
|
||||||
|
.call();
|
||||||
|
assertEquals(MergeStatus.ABORTED, result.getMergeStatus());
|
||||||
|
}
|
||||||
|
|
||||||
@Theory
|
@Theory
|
||||||
public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
|
public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
@ -1328,6 +1351,22 @@ public void testSquashMergeConflict() throws Exception {
|
||||||
assertEquals(StatusCommandTest.set("file2"), stat.getConflicting());
|
assertEquals(StatusCommandTest.set("file2"), stat.getConflicting());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFastForwardOnly() throws Exception {
|
||||||
|
Git git = new Git(db);
|
||||||
|
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
||||||
|
.call();
|
||||||
|
createBranch(initialCommit, "refs/heads/branch1");
|
||||||
|
git.commit().setMessage("second commit").call();
|
||||||
|
checkoutBranch("refs/heads/branch1");
|
||||||
|
|
||||||
|
MergeCommand merge = git.merge();
|
||||||
|
merge.setFastForward(FastForwardMode.FF_ONLY);
|
||||||
|
merge.include(db.getRef(Constants.MASTER));
|
||||||
|
MergeResult result = merge.call();
|
||||||
|
|
||||||
|
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
|
||||||
|
}
|
||||||
private static void setExecutable(Git git, String path, boolean executable) {
|
private static void setExecutable(Git git, String path, boolean executable) {
|
||||||
FS.DETECTED.setExecute(
|
FS.DETECTED.setExecute(
|
||||||
new File(git.getRepository().getWorkTree(), path), executable);
|
new File(git.getRepository().getWorkTree(), path), executable);
|
||||||
|
|
|
@ -269,7 +269,7 @@ public MergeResult call() throws GitAPIException, NoHeadException,
|
||||||
headCommit, srcCommit },
|
headCommit, srcCommit },
|
||||||
MergeStatus.ALREADY_UP_TO_DATE, mergeStrategy, null, null);
|
MergeStatus.ALREADY_UP_TO_DATE, mergeStrategy, null, null);
|
||||||
} else if (revWalk.isMergedInto(headCommit, srcCommit)
|
} else if (revWalk.isMergedInto(headCommit, srcCommit)
|
||||||
&& fastForwardMode == FastForwardMode.FF) {
|
&& fastForwardMode != FastForwardMode.NO_FF) {
|
||||||
// FAST_FORWARD detected: skip doing a real merge but only
|
// FAST_FORWARD detected: skip doing a real merge but only
|
||||||
// update HEAD
|
// update HEAD
|
||||||
refLogMessage.append(": " + MergeStatus.FAST_FORWARD); //$NON-NLS-1$
|
refLogMessage.append(": " + MergeStatus.FAST_FORWARD); //$NON-NLS-1$
|
||||||
|
@ -300,7 +300,7 @@ public MergeResult call() throws GitAPIException, NoHeadException,
|
||||||
headCommit, srcCommit }, mergeStatus, mergeStrategy,
|
headCommit, srcCommit }, mergeStatus, mergeStrategy,
|
||||||
null, msg);
|
null, msg);
|
||||||
} else {
|
} else {
|
||||||
if (fastForwardMode == FastForwardMode.FF_ONLY) {
|
if (fastForwardMode == FastForwardMode.NO_FF) {
|
||||||
return new MergeResult(headCommit, srcCommit,
|
return new MergeResult(headCommit, srcCommit,
|
||||||
new ObjectId[] { headCommit, srcCommit },
|
new ObjectId[] { headCommit, srcCommit },
|
||||||
MergeStatus.ABORTED, mergeStrategy, null, null);
|
MergeStatus.ABORTED, mergeStrategy, null, null);
|
||||||
|
|
Loading…
Reference in New Issue