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 ff7066e8b..a526fdaa7 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 @@ -58,6 +58,7 @@ import java.util.concurrent.Callable; import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode; import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.errors.NoHeadException; +import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -184,6 +185,40 @@ public class PullCommandTest extends RepositoryTestCase { .getRepositoryState()); } + @Test + public void testPullWithUntrackedStash() throws Exception { + target.pull().call(); + + // change the source file + writeToFile(sourceFile, "Source change"); + source.add().addFilepattern("SomeFile.txt").call(); + source.commit().setMessage("Source change in remote").call(); + + // write untracked file + writeToFile(new File(dbTarget.getWorkTree(), "untracked.txt"), + "untracked"); + RevCommit stash = target.stashCreate().setIndexMessage("message here") + .setIncludeUntracked(true).call(); + assertNotNull(stash); + assertTrue(target.status().call().isClean()); + + // pull from source + assertTrue(target.pull().call().isSuccessful()); + assertEquals("[SomeFile.txt, mode:100644, content:Source change]", + indexState(dbTarget, CONTENT)); + assertFalse(JGitTestUtil.check(dbTarget, "untracked.txt")); + assertEquals("Source change", + JGitTestUtil.read(dbTarget, "SomeFile.txt")); + + // apply the stash + target.stashApply().setStashRef(stash.getName()).call(); + assertEquals("[SomeFile.txt, mode:100644, content:Source change]", + indexState(dbTarget, CONTENT)); + assertEquals("untracked", JGitTestUtil.read(dbTarget, "untracked.txt")); + assertEquals("Source change", + JGitTestUtil.read(dbTarget, "SomeFile.txt")); + } + @Test public void testPullLocalConflict() throws Exception { target.branchCreate().setName("basedOnMaster").setStartPoint( @@ -576,4 +611,4 @@ public class PullCommandTest extends RepositoryTestCase { fis.close(); } } -} +} \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java index 1699b9f3d..b8ee1ec0b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java @@ -223,8 +223,13 @@ public class StashApplyCommand extends GitCommand { ResolveMerger untrackedMerger = (ResolveMerger) strategy .newMerger(repo, true); untrackedMerger.setCommitNames(new String[] { - "stashed HEAD", "HEAD", "untracked files" }); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - untrackedMerger.setBase(stashHeadCommit); + "null", "HEAD", "untracked files" }); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + // There is no common base for HEAD & untracked files + // because the commit for untracked files has no parent. If + // we use stashHeadCommit as common base (as in the other + // merges) we potentially report conflicts for files + // which are not even member of untracked files commit + untrackedMerger.setBase(null); boolean ok = untrackedMerger.merge(headCommit, untrackedCommit); if (ok)