Browse Source

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 <robin@nibor.org>
stable-0.12
Robin Stocker 14 years ago
parent
commit
770c733687
  1. 38
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java

38
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(),

7
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();

Loading…
Cancel
Save