summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJens Baumgart2010-11-08 10:18:57 (EST)
committer Shawn O. Pearce2010-11-08 18:32:03 (EST)
commit2dc2dd8b1b4c98b255b3f2dec655a3f0b197ce07 (patch)
tree1fb683765e3327731e989b5066f8e02ae660ebd1
parenta28f33fa8cf93e82b113fb303dfb4955a92b8956 (diff)
downloadjgit-2dc2dd8b1b4c98b255b3f2dec655a3f0b197ce07.zip
jgit-2dc2dd8b1b4c98b255b3f2dec655a3f0b197ce07.tar.gz
jgit-2dc2dd8b1b4c98b255b3f2dec655a3f0b197ce07.tar.bz2
IndexDiff: support state [removed, untracked]refs/changes/67/1867/2
IndexDiff was extended to detect files which are both removed from the index and untracked. Before this change these files were only added to the removed collection. Change-Id: I971d8261d2e8932039fce462b59c12e143f79f90 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java31
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java3
2 files changed, 34 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
index 3d19576..c73764a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
@@ -48,6 +48,9 @@ package org.eclipse.jgit.lib;
import java.io.File;
import java.io.IOException;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.treewalk.FileTreeIterator;
public class IndexDiffTest extends RepositoryTestCase {
@@ -210,4 +213,32 @@ public class IndexDiffTest extends RepositoryTestCase {
oi.release();
}
}
+
+ /**
+ * A file is removed from the index but stays in the working directory. It
+ * is checked if IndexDiff detects this file as removed and untracked.
+ *
+ * @throws Exception
+ */
+ public void testRemovedUntracked() throws Exception{
+ Git git = new Git(db);
+ String path = "file";
+ writeTrashFile(path, "content");
+ git.add().addFilepattern(path).call();
+ git.commit().setMessage("commit").call();
+ removeFromIndex(path);
+ FileTreeIterator iterator = new FileTreeIterator(db);
+ IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
+ diff.diff();
+ assertTrue(diff.getRemoved().contains(path));
+ assertTrue(diff.getUntracked().contains(path));
+ }
+
+ private void removeFromIndex(String path) throws IOException {
+ final DirCache dirc = db.lockDirCache();
+ final DirCacheEditor edit = dirc.editor();
+ edit.add(new DirCacheEditor.DeletePath(path));
+ if (!edit.commit())
+ throw new IOException("could not commit");
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
index 4319fed..f5aaa5e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
@@ -203,6 +203,9 @@ public class IndexDiff {
if (!fileModeTree.equals(FileMode.TYPE_TREE)) {
removed.add(treeIterator.getEntryPathString());
changesExist = true;
+ if (workingTreeIterator != null)
+ untracked.add(workingTreeIterator
+ .getEntryPathString());
}
}
} else {