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

[RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory

From
Greg Brockman <gdb@mit.edu>
Date
Aug 18, 2010, 09:29 UTC
Message-ID
<1282123788-24055-1-git-send-email-gdb@mit.edu>
In-Reply-To
<AANLkTiky+azVAnXEBFWR1q9_8NH8TX2TfuonXCpA_-ms@mail.gmail.com>
This test case attempts to match the behavior of 'git add ignore-file'
with 'git add ignore-dir/file' when .gitignore contains entries for
ignore-file and ignore-dir.
---
 t/t3700-add.sh |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

This patch is a follow-up to the thread '[RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files' at

  http://thread.gmane.org/gmane.comp.version-control.git/153194

In this patch, I propose the desired behavior of 'git add' for files contained in ignored directories. I have attempted to mirror the behavior of 'git add' for ignored files, but I may have gotten that wrong or that might not actually be what we want here. Comments on whether this is the desired behavior and whether these test-cases accurate capture that behavior would be appreciated.

Thank you,
Greg
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 7d7140d..97ba9e9 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -288,4 +288,34 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
 	test_cmp expect.err actual.err
 '
 
+cat >expect <<EOF
+The following paths are ignored by one of your .gitignore files:
+ignored-dir
+Use -f if you really want to add them.
+fatal: no files added
+EOF
+
+test_expect_success 'git add with file in ignored directory' '
+	mkdir ignored-dir &&
+	echo ignored-dir >> .gitignore &&
+	touch ignored-dir/file &&
+	test_must_fail git add ignored-dir/file >actual 2>&1 &&
+	test_cmp actual expect &&
+	git add -f ignored-dir/file &&
+	git add ignored-dir/file &&
+	echo change > ignored-dir/file &&
+	git add ignored-dir/file &&
+	! ( git ls-files -m ignored-dir/file | grep ignored-dir/file )
+'
+
+test_expect_success 'git add with ignored directory using git globs' "
+	mkdir ignored-dir2 && echo ignored-dir2 >> .gitignore && touch ignored-dir2/file &&
+	git add 'ignored-dir2/*' >actual 2>&1 &&
+	echo \"fatal: pathspec 'ignored-dir2/*' did not match any files\" | test_cmp - actual
+	git add -f ignored-dir2/file && echo change > ignored-dir2/file &&
+	git add 'ignored-dir2/*' >actual 2>&1 &&
+	echo '' | test_cmp - actual &&
+	git ls-files -m ignored-dir2/file | grep ignored-dir2/file
+"
+
 test_done
-- 
1.7.2.1.68.g1ba78
Previous: Greg BrockmanNext: Greg Brockman
Message 17 of 28 in “git-add: Don't exclude explicitly-specified tracked files”
  1. git-add: Don't exclude explicitly-specified tracked filesGreg Brockman, Aug 11, 2010
  2. Ævar Arnfjörð BjarmasonAug 11, 2010
  3. Jens LehmannAug 11, 2010
  4. Greg BrockmanAug 12, 2010
  5. Junio C HamanoAug 11, 2010
  6. Greg BrockmanAug 11, 2010
  7. Junio C HamanoAug 12, 2010
  8. Greg BrockmanAug 12, 2010
  9. Matthieu MoyAug 12, 2010
  10. Greg BrockmanAug 12, 2010
  11. Matthieu MoyAug 12, 2010
  12. Junio C HamanoAug 12, 2010
  13. Greg BrockmanAug 12, 2010
  14. Jonathan NiederAug 12, 2010
  15. Ævar Arnfjörð BjarmasonAug 12, 2010
  16. Greg BrockmanAug 18, 2010
  17. Add test case for dealing with a tracked file in an ignored directoryGreg Brockman, Aug 18, 2010
  18. Greg BrockmanAug 18, 2010
  19. Matthieu MoyAug 18, 2010
  20. Greg BrockmanAug 19, 2010
  21. Matthieu MoyAug 19, 2010
  22. Ævar Arnfjörð BjarmasonAug 18, 2010
  23. Matthieu MoyAug 18, 2010
  24. Ævar Arnfjörð BjarmasonAug 18, 2010
  25. Jonathan NiederAug 19, 2010
  26. Ævar Arnfjörð BjarmasonAug 19, 2010
  27. Jonathan NiederAug 25, 2010
  28. Ævar Arnfjörð BjarmasonAug 29, 2010

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.