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

Re: Adding nested repository with slash adds files instead of gitlink

From
Duy Nguyen <pclouds@gmail.com>
Date
Jun 19, 2018, 16:09 UTC
Message-ID
<20180619160956.GA21384@duynguyen.home>
In-Reply-To
<CACsJy8DQ-GGEDiV0iA2kTgNgHcT1sSX2Oqb7VZcjyK1nBOFv+A@mail.gmail.com>
On Tue, Jun 19, 2018 at 05:16:17PM +0200, Duy Nguyen wrote:
> No actually, we could do better. Let me see if I can come up with a
> patch or something...

OK. What we currently do is, when we search for potential untracked paths for adding to the index, we unconditionally ignore anything inside ".git". For example, if "foo" is a submodule, "git add ." will visit "foo/.git" then ignore its content completely.

We could do something very similar: when we visit "foo", if "foo/.git" exists, we ignore it as well. In other words, we extend from "ignore anything inside a git repository" to "ignore anything inside any other git worktree".

The following patch basically does that. If you specify "git add foo/bar". It will still visit "foo" first, realize that it's a submodule and drop it. At the end, it will not report foo/bar as an untracked (i.e. add-able) entry, so you can't add it.

I didn't test it extensively to see if it breaks anything though. And I might need to check how it affects untracked cache...

-- 8< --
diff --git a/dir.c b/dir.c
index fe9bf58e4c..8a1a5d8dd5 100644
--- a/dir.c
+++ b/dir.c
@@ -1672,6 +1672,17 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
 	if (dtype != DT_DIR && has_path_in_index)
 		return path_none;
 
+	if (dtype == DT_DIR) {
+		int path_len = path->len;
+		int is_submodule;
+
+		strbuf_addstr(path, "/.git");
+		is_submodule = is_directory(path->buf);
+		strbuf_setlen(path, path_len);
+		if (is_submodule)
+			return path_none;
+	}
+
 	/*
 	 * When we are looking at a directory P in the working tree,
 	 * there are three cases:
-- 8< --
Previous: Duy NguyenNext: Duy Nguyen
Message 8 of 22 in “Adding nested repository with slash adds files instead of gitlink”
  1. Heiko VoigtJun 18, 2018
  2. Duy NguyenJun 18, 2018
  3. Brandon WilliamsJun 18, 2018
  4. Heiko VoigtJun 19, 2018
  5. Duy NguyenJun 19, 2018
  6. Junio C HamanoJun 19, 2018
  7. Duy NguyenJun 19, 2018
  8. Duy NguyenJun 19, 2018
  9. Duy NguyenJun 19, 2018
  10. Kevin DaudtJun 18, 2018
  11. Heiko VoigtJun 19, 2018
  12. Rafael AscensãoJun 19, 2018
  13. Kevin DaudtJun 20, 2018
  14. Rafael AscensãoJun 20, 2018
  15. Duy NguyenJun 20, 2018
  16. Rafael AscensãoJun 20, 2018
  17. Phil SaintyAug 8, 2024
  18. Junio C HamanoAug 8, 2024
  19. Johannes SchindelinAug 13, 2024
  20. Junio C HamanoAug 13, 2024
  21. Phil SaintyAug 13, 2024
  22. Johannes SchindelinAug 14, 2024

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.