From 1eae309723be301a4f2fc12a3e07e7e7c9f30782 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Tue, 7 Jan 2014 10:15:14 +0100 Subject: Allow programmatic remote configuration for PullCommand Also imply remoteBranchName to match current branch name if it wasn't configured in branch configuration. Bug: 424812 Change-Id: Id852cedaefb2a537b6aa3c330b9861efad052f11 Signed-off-by: Matthias Sohn --- .../tst/org/eclipse/jgit/api/PullCommandTest.java | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'org.eclipse.jgit.test/tst') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java index c03ced563f..245219d884 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java @@ -232,6 +232,71 @@ public class PullCommandTest extends RepositoryTestCase { Git.wrap(empty).pull().call(); } + @Test + public void testPullMergeProgrammaticConfiguration() throws Exception { + // create another commit on another branch in source + source.checkout().setCreateBranch(true).setName("other").call(); + sourceFile = new File(db.getWorkTree(), "file2.txt"); + writeToFile(sourceFile, "content"); + source.add().addFilepattern("file2.txt").call(); + RevCommit sourceCommit = source.commit() + .setMessage("source commit on branch other").call(); + + File targetFile2 = new File(dbTarget.getWorkTree(), "OtherFile.txt"); + writeToFile(targetFile2, "Unconflicting change"); + target.add().addFilepattern("OtherFile.txt").call(); + RevCommit targetCommit = target.commit() + .setMessage("Unconflicting change in local").call(); + + PullResult res = target.pull().setRemote("origin") + .setRemoteBranchName("other") + .setRebase(false).call(); + + MergeResult mergeResult = res.getMergeResult(); + ObjectId[] mergedCommits = mergeResult.getMergedCommits(); + assertEquals(targetCommit.getId(), mergedCommits[0]); + assertEquals(sourceCommit.getId(), mergedCommits[1]); + RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult + .getNewHead()); + String message = "Merge branch 'other' of " + + db.getWorkTree().getAbsolutePath(); + assertEquals(message, mergeCommit.getShortMessage()); + } + + @Test + public void testPullMergeProgrammaticConfigurationImpliedTargetBranch() + throws Exception { + // create another commit on another branch in source + source.checkout().setCreateBranch(true).setName("other").call(); + sourceFile = new File(db.getWorkTree(), "file2.txt"); + writeToFile(sourceFile, "content"); + source.add().addFilepattern("file2.txt").call(); + RevCommit sourceCommit = source.commit() + .setMessage("source commit on branch other").call(); + + target.checkout().setCreateBranch(true).setName("other").call(); + File targetFile2 = new File(dbTarget.getWorkTree(), "OtherFile.txt"); + writeToFile(targetFile2, "Unconflicting change"); + target.add().addFilepattern("OtherFile.txt").call(); + RevCommit targetCommit = target.commit() + .setMessage("Unconflicting change in local").call(); + + // the source branch "other" matching the target branch should be + // implied + PullResult res = target.pull().setRemote("origin").setRebase(false) + .call(); + + MergeResult mergeResult = res.getMergeResult(); + ObjectId[] mergedCommits = mergeResult.getMergedCommits(); + assertEquals(targetCommit.getId(), mergedCommits[0]); + assertEquals(sourceCommit.getId(), mergedCommits[1]); + RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult + .getNewHead()); + String message = "Merge branch 'other' of " + + db.getWorkTree().getAbsolutePath() + " into other"; + assertEquals(message, mergeCommit.getShortMessage()); + } + @Override @Before public void setUp() throws Exception { -- cgit v1.2.3