Merge "Fix StashApplyCommand for stashes containing untracked changes."

This commit is contained in:
Christian Halstrick 2017-01-16 03:44:57 -05:00 committed by Gerrit Code Review @ Eclipse.org
commit 8a46b60371
2 changed files with 22 additions and 5 deletions

View File

@ -736,4 +736,21 @@ public void untrackedFileConflictsWithWorkingDirectory()
}
assertEquals("working-directory", read(path));
}
@Test
public void untrackedAndTrackedChanges() throws Exception {
writeTrashFile(PATH, "changed");
String path = "untracked.txt";
writeTrashFile(path, "untracked");
git.stashCreate().setIncludeUntracked(true).call();
assertTrue(PATH + " should exist", check(PATH));
assertEquals(PATH + " should have been reset", "content", read(PATH));
assertFalse(path + " should not exist", check(path));
git.stashApply().setStashRef("stash@{0}").call();
assertTrue(PATH + " should exist", check(PATH));
assertEquals(PATH + " should have new content", "changed", read(PATH));
assertTrue(path + " should exist", check(path));
assertEquals(path + " should have new content", "untracked",
read(path));
}
}

View File

@ -232,19 +232,19 @@ public ObjectId call() throws GitAPIException,
untrackedMerger.setBase(null);
boolean ok = untrackedMerger.merge(headCommit,
untrackedCommit);
if (ok)
if (ok) {
try {
RevTree untrackedTree = revWalk
.parseTree(untrackedMerger
.getResultTreeId());
.parseTree(untrackedCommit);
resetUntracked(untrackedTree);
} catch (CheckoutConflictException e) {
throw new StashApplyFailureException(
JGitText.get().stashApplyConflict);
JGitText.get().stashApplyConflict, e);
}
else
} else {
throw new StashApplyFailureException(
JGitText.get().stashApplyConflict);
}
}
} else {
throw new StashApplyFailureException(