From 770c733687d9f2f71f30822f9691427bf83b7577 Mon Sep 17 00:00:00 2001 From: Robin Stocker Date: Tue, 22 Mar 2011 19:39:39 +0100 Subject: [PATCH] PullCommand: Use short ref name in merge message Add a test case for PullCommand for the successful merge case and test that the short ref name is used. Change-Id: I16cbbc88595f73e5512f984e67f93f87ee0fe242 Signed-off-by: Robin Stocker --- .../org/eclipse/jgit/api/PullCommandTest.java | 38 ++++++++++++++++++- .../src/org/eclipse/jgit/api/PullCommand.java | 7 ++-- 2 files changed, 40 insertions(+), 5 deletions(-) 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 a25afc7c22..12b2f210e8 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 @@ -56,9 +56,12 @@ import java.io.IOException; import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode; import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.RepositoryState; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.FileRepository; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteConfig; @@ -107,6 +110,37 @@ public class PullCommandTest extends RepositoryTestCase { MergeStatus.ALREADY_UP_TO_DATE); } + @Test + public void testPullMerge() throws Exception { + PullResult res = target.pull().call(); + // nothing to update since we don't have different data yet + assertTrue(res.getFetchResult().getTrackingRefUpdates().isEmpty()); + assertTrue(res.getMergeResult().getMergeStatus() + .equals(MergeStatus.ALREADY_UP_TO_DATE)); + + writeToFile(sourceFile, "Source change"); + source.add().addFilepattern("SomeFile.txt"); + RevCommit sourceCommit = source.commit() + .setMessage("Source change in remote").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(); + + res = target.pull().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 'master' of " + db.getWorkTree(); + assertEquals(message, mergeCommit.getShortMessage()); + } + @Test public void testPullConflict() throws Exception { PullResult res = target.pull().call(); @@ -129,7 +163,7 @@ public class PullCommandTest extends RepositoryTestCase { res = target.pull().call(); - String sourceChangeString = "Source change\n>>>>>>> branch 'refs/heads/master' of " + String sourceChangeString = "Source change\n>>>>>>> branch 'master' of " + target.getRepository().getConfig().getString("remote", "origin", "url"); @@ -174,7 +208,7 @@ public class PullCommandTest extends RepositoryTestCase { res = target.pull().call(); - String sourceChangeString = "Master change\n>>>>>>> branch 'refs/heads/master' of local repository"; + String sourceChangeString = "Master change\n>>>>>>> branch 'master' of local repository"; assertNull(res.getFetchResult()); assertEquals(res.getMergeResult().getMergeStatus(), diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java index 1c86bd6638..8eae4027a1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java @@ -277,9 +277,10 @@ public class PullCommand extends GitCommand { } } else { MergeCommand merge = new MergeCommand(repo); - merge.include( - "branch \'" + remoteBranchName + "\' of " + remoteUri, - commitToMerge); + String name = "branch \'" + + Repository.shortenRefName(remoteBranchName) + "\' of " + + remoteUri; + merge.include(name, commitToMerge); MergeResult mergeRes; try { mergeRes = merge.call(); -- 2.39.5