diff options
author | Andrey Loskutov <loskutov@gmx.de> | 2015-07-14 00:05:49 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-07-21 00:47:28 +0200 |
commit | 08641ea413d64baed4ae8d017988fa15e52179ad (patch) | |
tree | 8dc6811638ea06135c56157f6ce445010c850d1c /org.eclipse.jgit/src/org/eclipse/jgit/ignore | |
parent | 1d295cb7fbd48b659b9a1a37e51dfbb8c3f97675 (diff) | |
download | jgit-08641ea413d64baed4ae8d017988fa15e52179ad.tar.gz jgit-08641ea413d64baed4ae8d017988fa15e52179ad.zip |
Allow leading literal '#' and '!' in ignore rules if they are escaped
According to [1] backslash can escape leading special characters '#' and
'!' in ignore rules, so that they are treated literally.
[1] https://www.kernel.org/pub/software/scm/git/docs/gitignore.html
Bug: 463581
Change-Id: I4c02927413a9c63ea5dbf2954877080d902ec1b2
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/ignore')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java index 2303ffd6d6..16a36baf08 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java @@ -98,24 +98,31 @@ public class FastIgnoreRule { if (pattern.charAt(0) == '#') { this.matcher = NO_MATCH; dirOnly = false; - } else { - dirOnly = pattern.charAt(pattern.length() - 1) == PATH_SEPARATOR; - if (dirOnly) { - pattern = stripTrailing(pattern, PATH_SEPARATOR); - if (pattern.length() == 0) { - this.matcher = NO_MATCH; - return; - } + return; + } + if (pattern.charAt(0) == '\\' && pattern.length() > 1) { + char next = pattern.charAt(1); + if (next == '!' || next == '#') { + // remove backslash escaping first special characters + pattern = pattern.substring(1); } - IMatcher m; - try { - m = PathMatcher.createPathMatcher(pattern, - Character.valueOf(PATH_SEPARATOR), dirOnly); - } catch (InvalidPatternException e) { - m = NO_MATCH; + } + dirOnly = pattern.charAt(pattern.length() - 1) == PATH_SEPARATOR; + if (dirOnly) { + pattern = stripTrailing(pattern, PATH_SEPARATOR); + if (pattern.length() == 0) { + this.matcher = NO_MATCH; + return; } - this.matcher = m; } + IMatcher m; + try { + m = PathMatcher.createPathMatcher(pattern, + Character.valueOf(PATH_SEPARATOR), dirOnly); + } catch (InvalidPatternException e) { + m = NO_MATCH; + } + this.matcher = m; } /** |