Skip to content

gitignore, re-inclusion fix

Nguyễn Thái Ngọc Duy git 3 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 1 replyIn review
  2. v22 patches 2 repliesSuperseded
  3. v12 patches 2 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2dir.c: make last_exclude_matching_from_list() run til the enddir.c+10 -50 replies
2/2dir.c: don't exclude whole dir prematurely if neg pattern may matchDocumentation/gitignore.txt dir.c t/t3001-ls-files-others-exclude.sh+118 -60 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

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

Changes since v2

-- 8< --

Documentation/gitignore.txt +11 -5
index 889a72a..79a1948 100644
@@ -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)
t/t3001-ls-files-others-exclude.sh +5 -0
index 9de49a6..da257c0 100755
@@ -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(-)
Signature · 1 line
2.3.0.rc1.137.g477eb31