summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst/org')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
index b405f6ad74..6f6b1158eb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
@@ -61,6 +61,7 @@ import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.StoredConfig;
@@ -148,6 +149,57 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
}
@Test
+ public void testPullFastForwardDetachedHead() throws Exception {
+ Repository repository = source.getRepository();
+ writeToFile(sourceFile, "2nd commit");
+ source.add().addFilepattern("SomeFile.txt").call();
+ source.commit().setMessage("2nd commit").call();
+
+ try (RevWalk revWalk = new RevWalk(repository)) {
+ // git checkout HEAD^
+ String initialBranch = repository.getBranch();
+ Ref initialRef = repository.findRef(Constants.HEAD);
+ RevCommit initialCommit = revWalk
+ .parseCommit(initialRef.getObjectId());
+ assertEquals("this test need linear history", 1,
+ initialCommit.getParentCount());
+ source.checkout().setName(initialCommit.getParent(0).getName())
+ .call();
+ assertFalse("expected detached HEAD",
+ repository.getFullBranch().startsWith(Constants.R_HEADS));
+
+ // change and commit another file
+ File otherFile = new File(sourceFile.getParentFile(),
+ System.currentTimeMillis() + ".tst");
+ writeToFile(otherFile, "other 2nd commit");
+ source.add().addFilepattern(otherFile.getName()).call();
+ RevCommit newCommit = source.commit().setMessage("other 2nd commit")
+ .call();
+
+ // git pull --rebase initialBranch
+ source.pull().setRebase(true).setRemote(".")
+ .setRemoteBranchName(initialBranch)
+ .call();
+
+ assertEquals(RepositoryState.SAFE,
+ source.getRepository().getRepositoryState());
+ Ref head = source.getRepository().findRef(Constants.HEAD);
+ RevCommit headCommit = revWalk.parseCommit(head.getObjectId());
+
+ // HEAD^ == initialCommit, no merge commit
+ assertEquals(1, headCommit.getParentCount());
+ assertEquals(initialCommit, headCommit.getParent(0));
+
+ // both contributions for both commits are available
+ assertFileContentsEqual(sourceFile, "2nd commit");
+ assertFileContentsEqual(otherFile, "other 2nd commit");
+ // HEAD has same message as rebased commit
+ assertEquals(newCommit.getShortMessage(),
+ headCommit.getShortMessage());
+ }
+ }
+
+ @Test
public void testPullConflict() throws Exception {
PullResult res = target.pull().call();
// nothing to update since we don't have different data yet