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

Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Aug 12, 2010, 08:30 UTC
Message-ID
<vpqsk2kjks7.fsf@bauges.imag.fr>
In-Reply-To
<1281510236-8103-1-git-send-email-gdb@mit.edu>
Greg Brockman <gdb@MIT.EDU> writes:
> Currently, 'git add' will complain about excluded files, even if they
> are already tracked:
This is not exactly true:

$ echo '*.pdf' > .gitignore; touch foo.pdf; git add -f foo.pdf $ echo content >> foo.pdf; git add foo.pdf

Here, the second "git add" didn't need the -f flag.

So, your problem is not about already-tracked exclude files, but it is about already-tracked files in an excluded directory.

> This commit changes 'git add' to disregard excludes for tracked files
> whose paths are explicitly specified on the command-line.

I don't think you need this to solve the problem, and as Junio said, that would make "git add dir/*" add all the ignored files, which would make -f essentially useless.

After a quick look at the code, the issue seems close to (dir.c):
struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)
{
	if (!cache_name_is_other(pathname, len))
		return NULL;
	ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc);
	return dir->ignored[dir->ignored_nr++] = dir_entry_new(pathname, len);
}

I guess the "if (!cache_name_is_other(pathname, len))" test is the one allowing the behavior I got above, but here, in the case of "git add dir/file" with "dir" being ignored, "pathname" is just "dir", not "dir/file", hence your problem.

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