[PATCH 2/4] Documentation: clarify effect of '/' in gitignore(5) patterns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The introduction of directory-only matches in v1.5.5-rc0~208^2~1
(gitignore(5): Allow "foo/" in ignore list to match directory "foo",
2008-01-31) was a small, incremental change to gitignore syntax that
did not affect the rest of the rules in any major way.  A '/' at the
end of a pattern means "match directories only" and does not otherwise
affect the pattern.  And that is how the gitignore(5) manpage explains
the syntax.

However, to a person parsing an unfamiliar gitignore entry like foo/,
it is too easy to notice the later (old) rule that describes how
patterns containing a slash are anchored and miss that the slash
should have been stripped off before considering whether the rule
applies.

Let's just explicitly say that patterns are only anchored if they
contain a slash that is not at the end of the pattern, avoiding this
confusion.  A more graceful presentation of this material may be
possible, but for now the goal is to get the facts clear --- we can
refactor the text to scan well without losing its meaning later.

(While at it, tweak the wording for clarity and add an example.)

Reported-by: Y.G. <yamomo1@xxxxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 Documentation/gitignore.txt |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 5b070bf0..c7c948dd 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -77,19 +77,21 @@ PATTERN FORMAT
    directory `foo` but will not match a regular file or a
    symbolic link `foo` (this is consistent with the way
    pathspecs work in general in git).
-+
-The trailing slash is removed before applying the remaining
-rules.
 
- - If the pattern does not contain a slash '/', git treats it as
-   a shell glob pattern and checks for a match against the
-   pathname relative to the location of the `.gitignore` file
-   (relative to the toplevel of the work tree if not from a
-   `.gitignore` file).
+ - If the pattern does not contain a slash '/' at the beginning
+   or in the middle, git treats it as a shell glob pattern and
+   matches the entire pathname including slashes, relative to the
+   location of the `.gitignore` file (or relative to the toplevel
+   of the work tree if the pattern is not from a `.gitignore`
+   file), against it.
+   For example, "{asterisk}.html" matches HTML files in the
+   directory containing the `.gitignore` file and in its
+   subdirectories.
 
- - Otherwise, git treats the pattern as a shell glob suitable
-   for consumption by fnmatch(3) with the FNM_PATHNAME flag:
-   wildcards in the pattern will not match a / in the pathname.
+ - If the pattern contains a slash '/' at the beginning or in the
+   middle, git imitates the behavior of fnmatch(3) with the
+   FNM_PATHNAME flag: wildcards in the pattern will not match a /
+   in the pathname.
    For example, "Documentation/{asterisk}.html" matches
    "Documentation/git.html" but not "Documentation/ppc/ppc.html"
    or "tools/perf/Documentation/perf.html".
-- 
1.7.8.rc0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]