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

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

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Aug 18, 2010, 09:50 UTC
Message-ID
<vpq8w44mer6.fsf@bauges.imag.fr>
In-Reply-To
<1282123788-24055-1-git-send-email-gdb@mit.edu>
Greg Brockman <gdb@MIT.EDU> writes:
> 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.
Good :-).
> +test_expect_success 'git add with file in ignored directory' '

In the final version, you can make the tests test_expect_failure in the first patch, and turn them back into test_expect_success in the second (which fixes the issue). This makes it clear what your change to the code do, and makes sure the test suite passes for each commit.

> +	mkdir ignored-dir &&
> +	echo ignored-dir >> .gitignore &&
> +	touch ignored-dir/file &&

I think >ignored-dir/file is more portable than touch, and is recommanded in the testsuite. But a quick grep shows that touch is already used.

> +	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 &&

(so, this is the first thing you're fixing, shouldn't be controversial)

> +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

Currently, "git add 'dir/*'" will add the files under dir/ if dir/ isn't ignored, and require -f if dir is ignored.

I don't think you want to complain with "did not match any files" here.

> +	git add -f ignored-dir2/file && echo change > ignored-dir2/file &&
> +	git add 'ignored-dir2/*' >actual 2>&1 &&

Just making sure I'm reading correctly: this is the second thing that should be fixed, and that your earlier patch didn't.

You're not testing the case
  git add ignored-dir/

which gives another case where Git tries to add files not explicitely given on the command-line. But the correct behavior of this case may be more controversial, so maybe it's indeed better to focus on the other cases.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Greg BrockmanNext: Greg Brockman
Message 19 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.