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

Re: Do "git add" as a builtin

From
Linus Torvalds <torvalds@osdl.org>
Date
May 18, 2006, 16:25 UTC
Message-ID
<Pine.LNX.4.64.0605180917060.10823@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0605180807060.10823@g5.osdl.org>
On Thu, 18 May 2006, Linus Torvalds wrote:
> 
> But if people are ok with changing it from a "print a warning and ignore" 
> into an _error_, we could just move it into "add_cache_entry()".
This is the incremental patch to do that instead, if you prefer it.

Putting it into add_cache_entry() definitely has advantages, in that it should make it much harder for this bug to happen again - all users will now be verified.

With this one, it's now a fatal error to try to add a pathname that cannot be added, ie

	[torvalds@g5 git]$ git add .git/config 
	fatal: unable to add .git/config to index
and
	[torvalds@g5 git]$ git add foo/../bar 
	fatal: unable to add foo/../bar to index

instead of the old "Ignoring path xyz" warning that would end up silently succeeding on any other paths.

		Linus
---
diff --git a/builtin-add.c b/builtin-add.c
index 0346bb5..ac9ed2d 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -172,11 +172,6 @@ static int add_file_to_index(const char 
 	if (lstat(path, &st))
 		die("%s: unable to stat (%s)", path, strerror(errno));
 
-	if (!verify_path(path)) {
-		fprintf(stderr, "Ignoring path %s\n", path);
-		return -1;
-	}
-		
 	if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
 		die("%s: can only add regular files or symbolic links", path);
 
diff --git a/read-cache.c b/read-cache.c
index 6b323dd..9a272f8 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -551,6 +551,8 @@ int add_cache_entry(struct cache_entry *
 
 	if (!ok_to_add)
 		return -1;
+	if (!verify_path(ce->name))
+		return -1;
 
 	if (!skip_df_check &&
 	    check_file_directory_conflict(ce, pos, ok_to_replace)) {
Previous: Linus TorvaldsNext: Linus Torvalds
Message 9 of 13 in “Do "git add" as a builtin”
  1. Linus TorvaldsMay 17, 2006
  2. Junio C HamanoMay 17, 2006
  3. Linus TorvaldsMay 17, 2006
  4. Junio C HamanoMay 18, 2006
  5. Junio C HamanoMay 18, 2006
  6. [WARNING] Please be careful when using "git add" from "next" branchJunio C Hamano, May 18, 2006
  7. FIXED: [WARNING] Please be careful when using "git add" from "next" branchJunio C Hamano, May 19, 2006
  8. Linus TorvaldsMay 18, 2006
  9. Linus TorvaldsMay 18, 2006
  10. Linus TorvaldsMay 18, 2006
  11. Junio C HamanoMay 18, 2006
  12. Linus TorvaldsMay 18, 2006
  13. Linus TorvaldsMay 18, 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.