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

Re: "git add $ignored_file" fail

From
Linus Torvalds <torvalds@osdl.org>
Date
May 17, 2006, 20:53 UTC
Message-ID
<Pine.LNX.4.64.0605171342370.10823@g5.osdl.org>
In-Reply-To
<e4g1f4$anv$1@sea.gmane.org>
On Wed, 17 May 2006, Jakub Narebski wrote:
Show 5 quoted lines
> 
> The changes in docummentation are nice and dandy, but it would be even nicer
> if "git add" told us about "git update-index --add" when it adds no files,
> as it is certainly the case when something is wrong (perhaps user
> expectations, but still...).

Well, with the new-and-improved builtin "git add", you could probably do something like the appended (on top of my most recent patch).

It says
	No added files - did you perhaps mean to do a 'git update-index'?

whenever it finds that "git add" has ignored a file and not actually added anything. That, btw, can happen either because it refused to see the file in the first place (ie it was ignored), or because all the files listed were already added.

In both cases the warning may or may not be sensible.
Anyway, I dunno. I don't have any strong opinions on this.
		Linus
---
diff --git a/builtin-add.c b/builtin-add.c
index 82e8f44..8641137 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -12,6 +12,8 @@ #include "dir.h"
 static const char builtin_add_usage[] =
 "git-add [-n] [-v] <filepattern>...";
 
+static int ignored;
+
 static int common_prefix(const char **pathspec)
 {
 	const char *path, *slash, *next;
@@ -123,8 +125,10 @@ static void prune_directory(struct dir_s
 
 		/* Existing file? We must have ignored it */
 		match = pathspec[i];
-		if (!lstat(match, &st))
+		if (!lstat(match, &st)) {
+			ignored = 1;
 			continue;
+		}
 		die("pathspec '%s' did not match any files", match);
 	}
 }
@@ -257,6 +261,9 @@ int cmd_add(int argc, const char **argv,
 	for (i = 0; i < dir.nr; i++)
 		add_file_to_index(dir.entries[i]->name, verbose);
 
+	if (ignored && !active_cache_changed)
+		fprintf(stderr, "No added files - did you perhaps mean to do a 'git update-index'?\n");
+
 	if (active_cache_changed) {
 		if (write_cache(newfd, active_cache, active_nr) ||
 		    commit_index_file(&cache_file))
Previous: Jakub NarebskiNext: Junio C Hamano
Message 16 of 18 in “"git add $ignored_file" fail”
  1. SantiMay 16, 2006
  2. Linus TorvaldsMay 16, 2006
  3. Jakub NarebskiMay 16, 2006
  4. SantiMay 16, 2006
  5. Johannes SchindelinMay 17, 2006
  6. SantiMay 17, 2006
  7. Jakub NarebskiMay 17, 2006
  8. Pavel RoskinMay 17, 2006
  9. SeanMay 17, 2006
  10. Jakub NarebskiMay 17, 2006
  11. Johannes SchindelinMay 17, 2006
  12. Linus TorvaldsMay 17, 2006
  13. Pavel RoskinMay 17, 2006
  14. Linus TorvaldsMay 17, 2006
  15. Jakub NarebskiMay 17, 2006
  16. Linus TorvaldsMay 17, 2006
  17. Junio C HamanoMay 17, 2006
  18. Linus TorvaldsMay 17, 2006

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.