aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJevgeni Zelenkov2012-08-06 02:59:28 (EDT)
committerMatthias Sohn2012-08-06 02:59:28 (EDT)
commit803debd7be76a2f18624254409228433c9c329f2 (patch)
treed44f7c61e69fd73d7301c6c56cd751d448b6bfb8
parentd08b35532a2403b0f1b2dbb68436cfa68d2b924a (diff)
downloadjgit-803debd7be76a2f18624254409228433c9c329f2.zip
jgit-803debd7be76a2f18624254409228433c9c329f2.tar.gz
jgit-803debd7be76a2f18624254409228433c9c329f2.tar.bz2
Ensure a directory exists before trying to create/merge a file into it.refs/changes/96/7096/5
Since git doesn't keep track of empty directories, they should be created first. Test case included demonstrates that using StashApplyCommand(). Bugfix is applied to the DirCacheCheckout class, because StashApplyCommand() uses it internally to apply a stash. Change-Id: Iac259229ef919f9e92e7e51a671d877172bb88a8 Signed-off-by: Jevgeni Zelenkov <jevgeni.zelenkov@gmail.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java32
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java1
4 files changed, 47 insertions, 0 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
index d3da09f..b3376a5 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
@@ -141,6 +141,14 @@ public abstract class JGitTestUtil {
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.
*
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
index bc11b7a..117ef88 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
@@ -422,6 +422,38 @@ public class StashApplyCommandTest extends RepositoryTestCase {
}
@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 {
git.stashApply().setStashRef(head.name()).call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
index c06322e..457fd1a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
@@ -102,6 +102,12 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
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);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
index f46869e..6e417b3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
@@ -962,6 +962,7 @@ public class DirCacheCheckout {
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);