Browse Source

Do not report ignored directories as untracked

Change-Id: I7e3f6b9fb1ac4b99d2cc9a78c63aad86f4fa5744
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-3.3
Matthias Sohn 12 years ago
parent
commit
75b31767c4
  1. 47
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
  2. 5
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java

47
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java

@ -467,6 +467,53 @@ public class IndexDiffTest extends RepositoryTestCase {
diff.getUntrackedFolders()); diff.getUntrackedFolders());
} }
/**
* Test that ignored folders aren't listed as untracked
*
* @throws Exception
*/
@Test
public void testUntrackedNotIgnoredFolders() throws Exception {
Git git = new Git(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db));
diff.diff();
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
writeTrashFile("readme", "");
writeTrashFile("sr/com/X.java", "");
writeTrashFile("src/com/A.java", "");
writeTrashFile("src/org/B.java", "");
writeTrashFile("srcs/org/Y.java", "");
writeTrashFile("target/com/A.java", "");
writeTrashFile("target/org/B.java", "");
writeTrashFile(".gitignore", "/target\n/sr");
git.add().addFilepattern("readme").addFilepattern(".gitignore")
.addFilepattern("srcs/").call();
git.commit().setMessage("initial").call();
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
diff.diff();
assertEquals(new HashSet<String>(Arrays.asList("src")),
diff.getUntrackedFolders());
git.add().addFilepattern("src").call();
writeTrashFile("sr/com/X1.java", "");
writeTrashFile("src/tst/A.java", "");
writeTrashFile("src/tst/B.java", "");
writeTrashFile("srcs/com/Y1.java", "");
deleteTrashFile(".gitignore");
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
diff.diff();
assertEquals(
new HashSet<String>(Arrays.asList("srcs/com", "sr", "src/tst",
"target")),
diff.getUntrackedFolders());
}
@Test @Test
public void testAssumeUnchanged() throws Exception { public void testAssumeUnchanged() throws Exception {
Git git = new Git(db); Git git = new Git(db);

5
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java

@ -132,6 +132,7 @@ public class IndexDiffFilter extends TreeFilter {
IncorrectObjectTypeException, IOException { IncorrectObjectTypeException, IOException {
final int cnt = tw.getTreeCount(); final int cnt = tw.getTreeCount();
final int wm = tw.getRawMode(workingTree); final int wm = tw.getRawMode(workingTree);
WorkingTreeIterator wi = workingTree(tw);
String path = tw.getPathString(); String path = tw.getPathString();
DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class); DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
@ -148,7 +149,8 @@ public class IndexDiffFilter extends TreeFilter {
// contain only untracked files and add it to // contain only untracked files and add it to
// untrackedParentFolders. If we later find tracked files we will // untrackedParentFolders. If we later find tracked files we will
// remove it from this list // remove it from this list
if (FileMode.TREE.equals(wm)) { if (FileMode.TREE.equals(wm)
&& !(honorIgnores && wi.isEntryIgnored())) {
// Clean untrackedParentFolders. This potentially moves entries // Clean untrackedParentFolders. This potentially moves entries
// from untrackedParentFolders to untrackedFolders // from untrackedParentFolders to untrackedFolders
copyUntrackedFolders(path); copyUntrackedFolders(path);
@ -179,7 +181,6 @@ public class IndexDiffFilter extends TreeFilter {
// we can avoid returning a result here, but only if its not in any // we can avoid returning a result here, but only if its not in any
// other tree. // other tree.
final int dm = tw.getRawMode(dirCache); final int dm = tw.getRawMode(dirCache);
WorkingTreeIterator wi = workingTree(tw);
if (dm == FileMode.TYPE_MISSING) { if (dm == FileMode.TYPE_MISSING) {
if (honorIgnores && wi.isEntryIgnored()) { if (honorIgnores && wi.isEntryIgnored()) {
ignoredPaths.add(wi.getEntryPathString()); ignoredPaths.add(wi.getEntryPathString());

Loading…
Cancel
Save