threads / patch / 61471

patchgitignore.txt: fix slash-rules example

Subject: [PATCH] gitignore.txt: fix slash-rules example

## tl;dr

2 messages between May 14, 2024 and May 14, 2024. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Timofey Vasenin via GitGitGadget· May 14, 2024, 16:53 UTC · lore
From: Timofey Vasenin <timofey.vasenin@gmail.com>

Fix an apparent typo, introduced in: 1a58bad014 (gitignore.txt: make slash-rules more readable, 2019-06-04)

Reported-by: Andrey Strizhkin <astrizhkin@biarum.com>
Signed-off-by: Timofey Vasenin <timofey.vasenin@gmail.com>
---
    gitignore.txt: fix slash-rules example
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1720%2Ftvasenin%2Ftvasenin%2Fgitignore-slash-rules-example-fix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1720/tvasenin/tvasenin/gitignore-slash-rules-example-fix-v1
Pull-Request: https://github.com/git/git/pull/1720
 Documentation/gitignore.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to Documentation/gitignore.txt +1 −1
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 5e0964ef419..7142fa10acc 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -100,7 +100,7 @@ PATTERN FORMAT
    will only match directories, otherwise the pattern can match both
    files and directories.
 
- - For example, a pattern `doc/frotz/` matches `doc/frotz` directory,
+ - For example, a pattern `/doc/frotz/` matches `doc/frotz` directory,
    but not `a/doc/frotz` directory; however `frotz/` matches `frotz`
    and `a/frotz` that is a directory (all paths are relative from
    the `.gitignore` file).

base-commit: 3e4a232f6e3bd3b7dd920bb07b21cf1c8b4e1a7f
-- 
gitgitgadget
Junio C Hamano· May 14, 2024, 21:50 UTC · re: Timofey Vasenin via GitGitGadget · lore

Re: [PATCH] gitignore.txt: fix slash-rules example

"Timofey Vasenin via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 18 quoted lines
> From: Timofey Vasenin <timofey.vasenin@gmail.com>
>
> Fix an apparent typo, introduced in:
> 1a58bad014 (gitignore.txt: make slash-rules more readable, 2019-06-04)
> ...
> diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
> index 5e0964ef419..7142fa10acc 100644
> --- a/Documentation/gitignore.txt
> +++ b/Documentation/gitignore.txt
> @@ -100,7 +100,7 @@ PATTERN FORMAT
>     will only match directories, otherwise the pattern can match both
>     files and directories.
>  
> - - For example, a pattern `doc/frotz/` matches `doc/frotz` directory,
> + - For example, a pattern `/doc/frotz/` matches `doc/frotz` directory,
>     but not `a/doc/frotz` directory; however `frotz/` matches `frotz`
>     and `a/frotz` that is a directory (all paths are relative from
>     the `.gitignore` file).
Are you sure this is a typo?

The text added by the same commit (taken from "git show 1a58bad014") has this passage:

+ - The pattern `doc/frotz` and `/doc/frotz` have the same effect
+   in any `.gitignore` file. In other words, a leading slash
+   is not relevant  if there is already a middle slash in
+   the pattern.

So, if your updated /doc/frotz/ works as described (i.e. match doc/frotz but not a/doc/frotz), then the original doc/frotz/ should behave exactly the same way, no? If you have a good reason to believe that doc/frotz/ described there should be /doc/frotz/ instead, then you need to also update that "have the same effect" paragraph.

There should already be an existing test that checks it somewhere under t/; finding one is left as an exercise (or punishment) to readers ;-).

It is easy to construct a test case from scratch.
    $ mkdir -p doc/frotz/ a/doc/frotz/
    $ >doc/frotz/foo
    $ >a/doc/frotz/bar
    $ echo doc/frotz >.gitignore
    $ git check-ignore -v doc/frotz/foo a/doc/frotz/bar
    .gitignore:1:doc/frotz	doc/frotz/foo

It seems that doc/frotz seems to work exactly as described, matching with doc/frotz/foo but not with a/doc/frotz/bar, without a leading slash, thanks to a slash in the middle.

So...

← back to recent threads