Fix applying stash on other commit
Applying a stash on another commit failed because the merge base for the cherry-pick of the stashed index state was not corectly set. Bug: 422684 Change-Id: I9355352b2b9a7abefa3248ca3c17a9301177d0d6 Signed-off-by: Stefan Lay <stefan.lay@sap.com>
This commit is contained in:
parent
ec0d78d093
commit
dcd0dd4d9e
|
@ -408,6 +408,93 @@ public void stashedContentMerge() throws Exception {
|
||||||
read(PATH));
|
read(PATH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stashedApplyOnOtherBranch() throws Exception {
|
||||||
|
writeTrashFile(PATH, "content\nmore content\n");
|
||||||
|
git.add().addFilepattern(PATH).call();
|
||||||
|
git.commit().setMessage("more content").call();
|
||||||
|
String path2 = "file2.txt";
|
||||||
|
File file2 = writeTrashFile(path2, "content\nmore content\n");
|
||||||
|
git.add().addFilepattern(PATH).call();
|
||||||
|
git.add().addFilepattern(path2).call();
|
||||||
|
git.commit().setMessage("even content").call();
|
||||||
|
|
||||||
|
String otherBranch = "otherBranch";
|
||||||
|
git.branchCreate().setName(otherBranch).call();
|
||||||
|
|
||||||
|
writeTrashFile(PATH, "master content");
|
||||||
|
git.add().addFilepattern(PATH).call();
|
||||||
|
git.commit().setMessage("even content").call();
|
||||||
|
|
||||||
|
git.checkout().setName(otherBranch).call();
|
||||||
|
|
||||||
|
writeTrashFile(PATH, "otherBranch content");
|
||||||
|
git.add().addFilepattern(PATH).call();
|
||||||
|
git.commit().setMessage("even more content").call();
|
||||||
|
|
||||||
|
writeTrashFile(path2, "content\nstashed change\nmore content\n");
|
||||||
|
|
||||||
|
RevCommit stashed = git.stashCreate().call();
|
||||||
|
|
||||||
|
assertNotNull(stashed);
|
||||||
|
assertEquals("content\nmore content\n", read(file2));
|
||||||
|
assertEquals("otherBranch content",
|
||||||
|
read(committedFile));
|
||||||
|
assertTrue(git.status().call().isClean());
|
||||||
|
|
||||||
|
git.checkout().setName("master").call();
|
||||||
|
git.stashApply().call();
|
||||||
|
assertEquals("content\nstashed change\nmore content\n", read(file2));
|
||||||
|
assertEquals("master content",
|
||||||
|
read(committedFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stashedApplyOnOtherBranchWithStagedChange() throws Exception {
|
||||||
|
writeTrashFile(PATH, "content\nmore content\n");
|
||||||
|
git.add().addFilepattern(PATH).call();
|
||||||
|
git.commit().setMessage("more content").call();
|
||||||
|
String path2 = "file2.txt";
|
||||||
|
File file2 = writeTrashFile(path2, "content\nmore content\n");
|
||||||
|
git.add().addFilepattern(PATH).call();
|
||||||
|
git.add().addFilepattern(path2).call();
|
||||||
|
git.commit().setMessage("even content").call();
|
||||||
|
|
||||||
|
String otherBranch = "otherBranch";
|
||||||
|
git.branchCreate().setName(otherBranch).call();
|
||||||
|
|
||||||
|
writeTrashFile(PATH, "master content");
|
||||||
|
git.add().addFilepattern(PATH).call();
|
||||||
|
git.commit().setMessage("even content").call();
|
||||||
|
|
||||||
|
git.checkout().setName(otherBranch).call();
|
||||||
|
|
||||||
|
writeTrashFile(PATH, "otherBranch content");
|
||||||
|
git.add().addFilepattern(PATH).call();
|
||||||
|
git.commit().setMessage("even more content").call();
|
||||||
|
|
||||||
|
writeTrashFile(path2,
|
||||||
|
"content\nstashed change in index\nmore content\n");
|
||||||
|
git.add().addFilepattern(path2).call();
|
||||||
|
writeTrashFile(path2, "content\nstashed change\nmore content\n");
|
||||||
|
|
||||||
|
RevCommit stashed = git.stashCreate().call();
|
||||||
|
|
||||||
|
assertNotNull(stashed);
|
||||||
|
assertEquals("content\nmore content\n", read(file2));
|
||||||
|
assertEquals("otherBranch content", read(committedFile));
|
||||||
|
assertTrue(git.status().call().isClean());
|
||||||
|
|
||||||
|
git.checkout().setName("master").call();
|
||||||
|
git.stashApply().call();
|
||||||
|
assertEquals("content\nstashed change\nmore content\n", read(file2));
|
||||||
|
assertEquals(
|
||||||
|
"[file.txt, mode:100644, content:master content]"
|
||||||
|
+ "[file2.txt, mode:100644, content:content\nstashed change in index\nmore content\n]",
|
||||||
|
indexState(CONTENT));
|
||||||
|
assertEquals("master content", read(committedFile));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void workingDirectoryContentMerge() throws Exception {
|
public void workingDirectoryContentMerge() throws Exception {
|
||||||
writeTrashFile(PATH, "content\nmore content\n");
|
writeTrashFile(PATH, "content\nmore content\n");
|
||||||
|
|
|
@ -185,6 +185,7 @@ public ObjectId call() throws GitAPIException,
|
||||||
.newMerger(repo, true);
|
.newMerger(repo, true);
|
||||||
ixMerger.setCommitNames(new String[] { "stashed HEAD",
|
ixMerger.setCommitNames(new String[] { "stashed HEAD",
|
||||||
"HEAD", "stashed index" });
|
"HEAD", "stashed index" });
|
||||||
|
ixMerger.setBase(stashHeadCommit);
|
||||||
boolean ok = ixMerger.merge(headCommit, stashIndexCommit);
|
boolean ok = ixMerger.merge(headCommit, stashIndexCommit);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
resetIndex(revWalk
|
resetIndex(revWalk
|
||||||
|
|
Loading…
Reference in New Issue