git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] Support "\" in non-wildcard exclusion entries

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 10, 2009, 14:27 UTC
Message-ID
<alpine.DEB.1.00.0902101525380.10279@pacific.mpi-cbg.de>
In-Reply-To
<20090210142017.GA16478@pvv.org>
Hi,
On Tue, 10 Feb 2009, Finn Arne Gangstad wrote:
Show 16 quoted lines
> "\" was treated differently in exclude rules depending on whether a
> wildcard match was done. For wildcard rules, "\" was de-escaped in
> fnmatch, but this was not done for other rules since they used strcmp
> instead.  A file named "#foo" would not be excluded by "\#foo", but would
> be excluded by "\#foo*".
> 
> We now treat all rules with "\" as wildcard rules.
> 
> Another solution could be to de-escape all non-wildcard rules as we
> read them, but we would have to do the de-escaping exactly as fnmatch
> does it to avoid inconsistencies.
> 
> Signed-off-by: Finn Arne Gangstad <finnag@pvv.org>
> ---
>  dir.c                                       |    2 +-
>  t/t3003-ls-files-others-escaped-excludes.sh |   37 +++++++++++++++++++++++++++
Thanks, much appreciated!
Show 20 quoted lines
> diff --git a/t/t3003-ls-files-others-escaped-excludes.sh b/t/t3003-ls-files-others-escaped-excludes.sh
> new file mode 100755
> index 0000000..bce8741
> --- /dev/null
> +++ b/t/t3003-ls-files-others-escaped-excludes.sh
> @@ -0,0 +1,37 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2009 Finn Arne Gangstad
> +#
> +
> +test_description='git ls-files --others with escaped excludes
> +
> +This test tests exclusion patterns with \ in them and makes sure they
> +are treated correctly and identically both for normal and wildcard rules.
> +'
> +
> +. ./test-lib.sh
> +
> +touch \#ignore1 &&

In other tests, we avoid 'touch' (IIRC it is not available everywhere or some such), and we write ': > \#ignore1' instead.

BTW we do not need the # in the name, it could be any letter, right? (Just for my understanding, not as a request to change it.)

Show 7 quoted lines
> +touch \#ignore2 &&
> +touch \#hidden &&
> +touch keep
> +
> +echo keep > expect
> +
> +cat >.gitignore <<EOF
You probably want to use \EOF here.
Show 16 quoted lines
> +.gitignore
> +expect
> +output
> +\#ignore1
> +\#ignore2*
> +\#hid*n
> +EOF
> +
> +test_expect_success \
> +    'git ls-files --others with escaped excludes.' \
> +    'git ls-files --others \
> +       --exclude-per-directory=.gitignore \
> +       >output &&
> +     test_cmp expect output'
> +
> +test_done

Thanks! Dscho

Previous: Finn Arne GangstadNext: Finn Arne Gangstad
Message 6 of 13 in “Support \ in non-wildcard .gitignore entries”
  1. Support \ in non-wildcard .gitignore entriesFinn Arne Gangstad, Feb 10, 2009
  2. Johannes SchindelinFeb 10, 2009
  3. Finn Arne GangstadFeb 10, 2009
  4. Johannes SchindelinFeb 10, 2009
  5. Support "\" in non-wildcard exclusion entriesFinn Arne Gangstad, Feb 10, 2009
  6. Johannes SchindelinFeb 10, 2009
  7. Finn Arne GangstadFeb 10, 2009
  8. Junio C HamanoFeb 10, 2009
  9. Junio C HamanoFeb 10, 2009
  10. Finn Arne GangstadFeb 10, 2009
  11. Support "\" in non-wildcard exclusion entriesFinn Arne Gangstad, Feb 12, 2009
  12. Johannes SchindelinFeb 12, 2009
  13. Junio C HamanoFeb 12, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.