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

Re: Bug Report: git add

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 7, 2011, 07:28 UTC
Message-ID
<7vlizmfrl1.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20110407014819.GA12730@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 20 quoted lines
> @@ -139,8 +138,21 @@ static int lstat_cache_matchlen(struct cache_def *cache,
>  			if (errno == ENOENT)
>  				*ret_flags |= FL_NOENT;
>  		} else if (S_ISDIR(st.st_mode)) {
> -			last_slash_dir = last_slash;
> -			continue;
> +			struct stat junk;
> +			struct strbuf gitdir = STRBUF_INIT;
> +			strbuf_add(&gitdir, cache->path, match_len);
> +			strbuf_addstr(&gitdir, "/.git");
> +			if (lstat(gitdir.buf, &junk) < 0) {
> +				if (errno == ENOENT) {
> +					last_slash_dir = last_slash;
> +					strbuf_release(&gitdir);
> +					continue;
> +				}
> +				*ret_flags = FL_LSTATERR;
> +			}
> +			else
> +				*ret_flags = FL_GITREPO;
This only checks "does the directory have .git in it?".

It probably is sufficient, but setup.c:is_git_directory() may do a more appropriate check, I think. That ".git" thing could be a regular file (i.e. "gitdir: path"), so depending on the junk.st_mode, you may have to call read_gitfile_gently() on it before checking with is_git_directory().

Alternatively, resolve_gitlink_ref() might be usable, but because it is primarily meant to deal with a submodule, there is a slight impedance mismatch with the test we are trying to do. In this codepath, all we care about is if the subdirectory is controlled by a separate git repository, and it does not matter if that is an untracked directory from the superproject's point of view, or if it is bound to the superproject as a submodule.

Also I suspect resolve_gitlink_ref() may not work for a submodule that does not have an initial commit but that is a separate issue.

Previous: Jeff KingNext: Jeff King
Message 11 of 13 in “Bug Report: git add”
  1. Darren CookApr 5, 2011
  2. Ramkumar RamachandraApr 6, 2011
  3. Jakub NarebskiApr 10, 2011
  4. Ramkumar RamachandraApr 10, 2011
  5. Junio C HamanoApr 11, 2011
  6. Jeff KingApr 11, 2011
  7. Jeff KingApr 7, 2011
  8. Junio C HamanoApr 7, 2011
  9. Jeff KingApr 7, 2011
  10. Jeff KingApr 7, 2011
  11. Junio C HamanoApr 7, 2011
  12. Jeff KingApr 8, 2011
  13. Jeff KingApr 8, 2011

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.