return path;
}
+ public static File writeTrashFile(final FileRepository db,
+ final String subdir,
+ final String name, final String data) throws IOException {
+ File path = new File(db.getWorkTree() + "/" + subdir, name);
+ write(path, data);
+ return path;
+ }
+
/**
* Write a string as a UTF-8 file.
*
assertTrue(status.getModified().contains(PATH));
}
+ @Test
+ public void stashChangeInANewSubdirectory() throws Exception {
+ String subdir = "subdir";
+ String fname = "file2.txt";
+ String path = subdir + System.getProperty("file.separator") + fname;
+ String otherBranch = "otherbranch";
+
+ writeTrashFile(subdir, fname, "content2");
+
+ git.add().addFilepattern(path).call();
+ RevCommit stashed = git.stashCreate().call();
+ assertNotNull(stashed);
+ assertTrue(git.status().call().isClean());
+
+ git.branchCreate().setName(otherBranch).call();
+ git.checkout().setName(otherBranch).call();
+
+ ObjectId unstashed = git.stashApply().call();
+ assertEquals(stashed, unstashed);
+
+ Status status = git.status().call();
+ assertTrue(status.getChanged().isEmpty());
+ assertTrue(status.getConflicting().isEmpty());
+ assertTrue(status.getMissing().isEmpty());
+ assertTrue(status.getRemoved().isEmpty());
+ assertTrue(status.getModified().isEmpty());
+ assertTrue(status.getUntracked().isEmpty());
+
+ assertEquals(1, status.getAdded().size());
+ assertTrue(status.getAdded().contains(path));
+ }
+
@Test
public void unstashNonStashCommit() throws Exception {
try {
return JGitTestUtil.writeTrashFile(db, name, data);
}
+ protected File writeTrashFile(final String subdir, final String name,
+ final String data)
+ throws IOException {
+ return JGitTestUtil.writeTrashFile(db, subdir, name, data);
+ }
+
protected void deleteTrashFile(final String name) throws IOException {
JGitTestUtil.deleteTrashFile(db, name);
}
DirCacheEntry entry, ObjectReader or) throws IOException {
ObjectLoader ol = or.open(entry.getObjectId());
File parentDir = f.getParentFile();
+ parentDir.mkdirs();
File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir);
WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
FileOutputStream rawChannel = new FileOutputStream(tmpFile);