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

Re: [PATCH v2 2/2] dir.c: don't exclude whole dir prematurely if neg pattern may match

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 14, 2015, 17:15 UTC
Message-ID
<xmqqd1xkylb4.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1442107141-24265-3-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 11 quoted lines
> diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
> index 473623d..889a72a 100644
> --- a/Documentation/gitignore.txt
> +++ b/Documentation/gitignore.txt
> @@ -82,12 +82,9 @@ PATTERN FORMAT
>  
>   - An optional prefix "`!`" which negates the pattern; any
>     matching file excluded by a previous pattern will become
> +   included again. It is possible to re-include a file if a parent
> +   directory of that file is excluded, with restrictions. See section
> +   NOTES for detail.
Sounds like a very useful thing.
Show 18 quoted lines
>   - If the pattern ends with a slash, it is removed for the
>     purpose of the following description, but it would only find
> @@ -141,6 +138,18 @@ not tracked by Git remain untracked.
>  To stop tracking a file that is currently tracked, use
>  'git rm --cached'.
>  
> +To re-include a file when its parent directory is excluded, the
> +following conditions must be met:
> +
> + - The directory part in the re-include rules must be literal (i.e. no
> +   wildcards)
> +
> + - The rules to exclude the parent directory must not end with a
> +   trailing slash.
> +
> + - The rules to exclude the parent directory must have at least one
> +   slash.
> +

In this bulletted list, don't the readers also need to be told that having "/abc" in .gitignore (but not "!/abc/anything" in .gitignore) and "!foo" in abc/.gitignore would not cause us to descend into "/abc" just to examine "abc/.gitignore" with pessimistic assumption that there might be some exclusion in there?

Show 27 quoted lines
> diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
> index 3fc484e..9de49a6 100755
> --- a/t/t3001-ls-files-others-exclude.sh
> +++ b/t/t3001-ls-files-others-exclude.sh
> @@ -305,4 +305,24 @@ test_expect_success 'ls-files with "**" patterns and no slashes' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'negative patterns' '
> +	git init reinclude &&
> +	(
> +		cd reinclude &&
> +		cat >.gitignore <<-\EOF &&
> +		/foo
> +		!foo/bar/bar
> +		EOF
> +		mkdir -p foo/bar &&
> +		touch abc foo/def foo/bar/ghi foo/bar/bar &&
> +		git ls-files -o --exclude-standard >../actual &&
> +		cat >../expected <<-\EOF &&
> +		.gitignore
> +		abc
> +		foo/bar/bar
> +		EOF
> +		test_cmp ../expected ../actual
> +	)
> +'

And another test here may want to explicitly ensure that we are not overly pessimising the ignore processing, so that later changes will not break it, I think. Or do we already have such a case covered by an existing test?

Thanks.
Previous: Nguyễn Thái Ngọc DuyNext: Duy Nguyen
Message 9 of 10 in “gitignore, re-inclusion fix”
  1. 0/2 gitignore, re-inclusion fixNguyễn Thái Ngọc Duy, Aug 23, 2015
  2. 1/2 dir.c: make last_exclude_matching_from_list() run til the endNguyễn Thái Ngọc Duy, Aug 23, 2015
  3. Junio C HamanoAug 25, 2015
  4. Duy NguyenAug 31, 2015
  5. 2/2 dir.c: don't exclude whole dir prematurely if neg pattern may matchNguyễn Thái Ngọc Duy, Aug 23, 2015
  6. 0/2 gitignore, re-inclusion fixNguyễn Thái Ngọc Duy, Sep 13, 2015
  7. 1/2 dir.c: make last_exclude_matching_from_list() run til the endNguyễn Thái Ngọc Duy, Sep 13, 2015
  8. 2/2 dir.c: don't exclude whole dir prematurely if neg pattern may matchNguyễn Thái Ngọc Duy, Sep 13, 2015
  9. Junio C HamanoSep 14, 2015
  10. Duy NguyenSep 17, 2015

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.