{"thread":{"id":"51211","subject":"[PATCH] make slash-rules more readable","startedAt":"2019-05-31T18:16:25Z","lastAt":"2019-05-31T18:16:25Z","messageCount":1,"participants":["Dr. Adam Nielsen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"376494","messageId":"20190531181617.24190-1-admin@in-ici.net","threadId":"51211","inReplyTo":null,"subject":"[PATCH] make slash-rules more readable","fromName":"Dr. Adam Nielsen","fromEmail":"admin@in-ici.net","sentAt":"2019-05-31T18:16:17Z","receivedAt":"2019-05-31T18:16:25Z","isPatch":true,"sender":{"key":"admin@in-ici.net","avatar":"https://avatars.githubusercontent.com/u/1765602?v=4"},"body":"---\n Documentation/gitignore.txt | 75 ++++++++++++++++++++++++++-----------\n 1 file changed, 54 insertions(+), 21 deletions(-)\n\ndiff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt\nindex b5bc9dbff0..ce944779a5 100644\n--- a/Documentation/gitignore.txt\n+++ b/Documentation/gitignore.txt\n@@ -89,28 +89,36 @@ PATTERN FORMAT\n    Put a backslash (\"`\\`\") in front of the first \"`!`\" for patterns\n    that begin with a literal \"`!`\", for example, \"`\\!important!.txt`\".\n \n- - If the pattern ends with a slash, it is removed for the\n-   purpose of the following description, but it would only find\n+ - A slash `/` is used as a directory separator. A leading and trailing\n+   slash have special meaning and are explained in the following.\n+\n+ - If the pattern ends with a slash, it would only find\n    a match with a directory.  In other words, `foo/` will match a\n-   directory `foo` and paths underneath it, but will not match a\n-   regular file or a symbolic link `foo` (this is consistent\n-   with the way how pathspec works in general in Git).\n-\n- - If the pattern does not contain a slash '/', Git treats it as\n-   a shell glob pattern and checks for a match against the\n-   pathname relative to the location of the `.gitignore` file\n-   (relative to the toplevel of the work tree if not from a\n-   `.gitignore` file).\n-\n- - Otherwise, Git treats the pattern as a shell glob: \"`*`\" matches\n-   anything except \"`/`\", \"`?`\" matches any one character except \"`/`\"\n-   and \"`[]`\" matches one character in a selected range. See\n-   fnmatch(3) and the FNM_PATHNAME flag for a more detailed\n-   description.\n-\n- - A leading slash matches the beginning of the pathname.\n-   For example, \"/{asterisk}.c\" matches \"cat-file.c\" but not\n-   \"mozilla-sha1/sha1.c\".\n+   directory `foo`, but will not match a regular file or a\n+   symbolic link `foo` (this is consistent with the way how\n+   pathspec works in general in Git).\n+\n+ - If the pattern does not end with a slash, it would find a match\n+   with a file or directory.\n+\n+ - The pattern is matched relative to the location of\n+   the `.gitignore` file. Except if the pattern contains\n+   no slash (or no slash but a trailing slash), then the pattern is\n+   matched against all files and folders (recursively)\n+   from the location of the `.gitignore` file.\n+   For example, `doc/frotz/` matches `doc/frotz` directory, but not\n+   a/doc/frotz`; however `frotz/` matches `frotz` and `a/frotz` that\n+   is a directory (all paths are relative from the `.gitignore` file).\n+\n+ - A leading slash, if any, is implicitly removed before matching the\n+   pattern with the pathname, but the pattern still counts as having\n+   a non-trailing slash for the purpose of the above rule.\n+\n+ - An asterisk \"`*`\" matches anything except a slash.\n+   The character \"`?`\" matches any one character except \"`/`\".\n+   The range notation, e.g. `[a-zA-Z]`, can be used to match\n+   one of the characters in a range. See fnmatch(3) and the\n+   FNM_PATHNAME flag for a more detailed description.\n \n Two consecutive asterisks (\"`**`\") in patterns matched against\n full pathname may have special meaning:\n@@ -152,6 +160,31 @@ To stop tracking a file that is currently tracked, use\n EXAMPLES\n --------\n \n+ - The pattern `/bar` only matches the file or folder `bar`\n+   but not `a/bar`, whereas the pattern `bar` would match both\n+   (relative to the `.gitignore` file). That is because the\n+   pattern `/bar` contains a non-trailing slash and thus matches\n+   relative to the location of the `.gitignore` file.\n+   Since `bar` has no slash, it matches recursively.\n+\n+ - The pattern 'hello.*' is not sufficient for the following rule:\n+   \"ignore any file whose name begins with 'hello' and in this\n+   directory only, not in its subdirectories.\" because the pattern\n+   does not have any slash. To work around this limitation,\n+   you can prepend your pattern with a slash, i.e. '/hello.*';\n+   the pattern now matches 'hello.txt', 'hello.c' but not\n+   'a/hello.java'.\n+\n+ - The pattern `doc/frotz` and `/doc/frotz` have the same effect\n+   in any `.gitignore` file. Both pattern contain a non-trailing\n+   slash and thus match relative to the location of the\n+   `.gitignore` file.\n+\n+ - The pattern \"foo/*\", matches \"foo/test.json\"\n+   (a regular file), \"foo/bar\" (a diretory), but it does not match\n+   \"foo/bar/hello.c\" (a regular file), as the asterisk in the\n+   patter does not match \"bar/hello.c\" which has a slash in it.\n+\n --------------------------------------------------------------\n     $ git status\n     [...]\n-- \n2.17.1\n\n"}]}