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

[PATCH v3 0/2] gitignore, re-inclusion fix

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 21, 2015, 09:56 UTC
Message-ID
<1442829375-1926-1-git-send-email-pclouds@gmail.com>
In-Reply-To
<1442106945-24080-1-git-send-email-pclouds@gmail.com>
Changes since v2
-- 8< --
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 889a72a..79a1948 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -82,9 +82,12 @@ 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.
+   included again.
+   Put a backslash ("`\`") in front of the first "`!`" for patterns
+   that begin with a literal "`!`", for example, "`\!important!.txt`".
+   It is possible to re-include a file if a parent directory of that
+   file is excluded if certain conditions are met. See section NOTES
+   for detail.
 
  - If the pattern ends with a slash, it is removed for the
    purpose of the following description, but it would only find
@@ -138,8 +141,11 @@ 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:
+To re-include files or directories when their parent directory is
+excluded, the following conditions must be met:
+
+ - The rules to exclude a directory and re-include a subset back must
+   be in the same .gitignore file.
 
  - The directory part in the re-include rules must be literal (i.e. no
    wildcards)
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index 9de49a6..da257c0 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -310,9 +310,14 @@ test_expect_success 'negative patterns' '
 	(
 		cd reinclude &&
 		cat >.gitignore <<-\EOF &&
+		/fooo
 		/foo
 		!foo/bar/bar
 		EOF
+		mkdir fooo &&
+		cat >fooo/.gitignore <<-\EOF &&
+		!/*
+		EOF
 		mkdir -p foo/bar &&
 		touch abc foo/def foo/bar/ghi foo/bar/bar &&
 		git ls-files -o --exclude-standard >../actual &&
-- 8< --

Nguyễn Thái Ngọc Duy (2):
  dir.c: make last_exclude_matching_from_list() run til the end
  dir.c: don't exclude whole dir prematurely if neg pattern may match

 Documentation/gitignore.txt        | 23 ++++++++--
 dir.c                              | 89 +++++++++++++++++++++++++++++++++++---
 t/t3001-ls-files-others-exclude.sh | 25 +++++++++++
 3 files changed, 127 insertions(+), 10 deletions(-)
-- 
2.3.0.rc1.137.g477eb31
Next: Nguyễn Thái Ngọc Duy
Message 1 of 4 in “gitignore, re-inclusion fix”
  1. 0/2 gitignore, re-inclusion fixNguyễn Thái Ngọc Duy, Sep 21, 2015
  2. 1/2 dir.c: make last_exclude_matching_from_list() run til the endNguyễn Thái Ngọc Duy, Sep 21, 2015
  3. 2/2 dir.c: don't exclude whole dir prematurely if neg pattern may matchNguyễn Thái Ngọc Duy, Sep 21, 2015
  4. Junio C HamanoSep 21, 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.