aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/treewalk
diff options
context:
space:
mode:
authorAndrey Loskutov <loskutov@gmx.de>2014-10-22 09:31:42 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2014-11-29 01:24:20 +0100
commit147e24a7b224fe6d643bb24100030ff70bfbca35 (patch)
treeed26ba3126b1792e7171ec552c60561ad9fe205d /org.eclipse.jgit/src/org/eclipse/jgit/treewalk
parent3886a4f68b2a85526196c09332843676de9461cd (diff)
downloadjgit-147e24a7b224fe6d643bb24100030ff70bfbca35.tar.gz
jgit-147e24a7b224fe6d643bb24100030ff70bfbca35.zip
Consider parent rules if ignore rule is negated
The change tries to make jgit behave more like native CLI git regarding the negation rules. According to [1] "... prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again." Negating the pattern should not automatically make the file *not ignored* - other pattern rules have to be considered too. The fix adds test cases for both bugs 448094 and 407475. [1] https://www.kernel.org/pub/software/scm/git/docs/gitignore.html Bug: 448094 Bug: 407475 Change-Id: I322954200dd3c683e3d8f4adc48506eb99e56ae1 Signed-off-by: Andrey Loskutov <loskutov@gmx.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/treewalk')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
index cc5ef18074..6311da6b68 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -573,6 +573,23 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
* a relevant ignore rule file exists but cannot be read.
*/
protected boolean isEntryIgnored(final int pLen) throws IOException {
+ return isEntryIgnored(pLen, false);
+ }
+
+ /**
+ * Determine if the entry path is ignored by an ignore rule. Consider
+ * possible rule negation from child iterator.
+ *
+ * @param pLen
+ * the length of the path in the path buffer.
+ * @param negatePrevious
+ * true if the previous matching iterator rule was negation
+ * @return true if the entry is ignored by an ignore rule.
+ * @throws IOException
+ * a relevant ignore rule file exists but cannot be read.
+ */
+ private boolean isEntryIgnored(final int pLen, boolean negatePrevious)
+ throws IOException {
IgnoreNode rules = getIgnoreNode();
if (rules != null) {
// The ignore code wants path to start with a '/' if possible.
@@ -583,17 +600,23 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
if (0 < pOff)
pOff--;
String p = TreeWalk.pathOf(path, pOff, pLen);
- switch (rules.isIgnored(p, FileMode.TREE.equals(mode))) {
+ switch (rules.isIgnored(p, FileMode.TREE.equals(mode),
+ negatePrevious)) {
case IGNORED:
return true;
case NOT_IGNORED:
return false;
case CHECK_PARENT:
+ negatePrevious = false;
+ break;
+ case CHECK_PARENT_NEGATE_FIRST_MATCH:
+ negatePrevious = true;
break;
}
}
if (parent instanceof WorkingTreeIterator)
- return ((WorkingTreeIterator) parent).isEntryIgnored(pLen);
+ return ((WorkingTreeIterator) parent).isEntryIgnored(pLen,
+ negatePrevious);
return false;
}