aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2011-03-22 14:39:39 (EDT)
committerRobin Stocker2011-03-22 14:46:18 (EDT)
commit770c733687d9f2f71f30822f9691427bf83b7577 (patch)
treeb0f390fe4e5e68efa2eecc7f47a5091334e34057
parentdcf7bd9a8f7acafbd1461dc0414aded2db030983 (diff)
downloadjgit-770c733687d9f2f71f30822f9691427bf83b7577.zip
jgit-770c733687d9f2f71f30822f9691427bf83b7577.tar.gz
jgit-770c733687d9f2f71f30822f9691427bf83b7577.tar.bz2
PullCommand: Use short ref name in merge messagerefs/changes/86/2886/1
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 <robin@nibor.org>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java38
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java7
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 a25afc7..12b2f21 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;
@@ -108,6 +111,37 @@ public class PullCommandTest extends RepositoryTestCase {
}
@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();
// nothing to update since we don't have different data yet
@@ -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 1c86bd6..8eae402 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<PullResult> {
}
} 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();