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

[PATCH 2/4] submodule: unset core.worktree if no working tree is present

From
Stefan Beller <sbeller@google.com>
Date
Dec 7, 2018, 23:54 UTC
Message-ID
<20181207235425.128568-3-sbeller@google.com>
In-Reply-To
<20181207235425.128568-1-sbeller@google.com>

This reintroduces 4fa4f90ccd (submodule: unset core.worktree if no working tree is present, 2018-06-12), which was reverted as part of f178c13fda (Revert "Merge branch 'sb/submodule-core-worktree'", 2018-09-07).

4fa4f90ccd was reverted as its followup commit was faulty, but without the accompanying change of the followup, we'd have an incomplete workflow of setting `core.worktree` again, when it is needed such as checking out a revision that contains a submodule.

So re-introduce that commit as-is, focusing on fixing up the followup
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c               | 14 ++++++++++++++
 submodule.h               |  2 ++
 t/lib-submodule-update.sh |  3 ++-
 3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/submodule.c b/submodule.c
index 6415cc5580..d393e947e6 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1561,6 +1561,18 @@ int bad_to_remove_submodule(const char *path, unsigned flags)
 	return ret;
 }
 
+void submodule_unset_core_worktree(const struct submodule *sub)
+{
+	char *config_path = xstrfmt("%s/modules/%s/config",
+				    get_git_common_dir(), sub->name);
+
+	if (git_config_set_in_file_gently(config_path, "core.worktree", NULL))
+		warning(_("Could not unset core.worktree setting in submodule '%s'"),
+			  sub->path);
+
+	free(config_path);
+}
+
 static const char *get_super_prefix_or_empty(void)
 {
 	const char *s = get_super_prefix();
@@ -1726,6 +1738,8 @@ int submodule_move_head(const char *path,
 
 			if (is_empty_dir(path))
 				rmdir_or_warn(path);
+
+			submodule_unset_core_worktree(sub);
 		}
 	}
 out:
diff --git a/submodule.h b/submodule.h
index a680214c01..9e18e9b807 100644
--- a/submodule.h
+++ b/submodule.h
@@ -131,6 +131,8 @@ int submodule_move_head(const char *path,
 			const char *new_head,
 			unsigned flags);
 
+void submodule_unset_core_worktree(const struct submodule *sub);
+
 /*
  * Prepare the "env_array" parameter of a "struct child_process" for executing
  * a submodule by clearing any repo-specific environment variables, but
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 016391723c..51d4555549 100755
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -709,7 +709,8 @@ test_submodule_recursing_with_args_common() {
 			git branch -t remove_sub1 origin/remove_sub1 &&
 			$command remove_sub1 &&
 			test_superproject_content origin/remove_sub1 &&
-			! test -e sub1
+			! test -e sub1 &&
+			test_must_fail git config -f .git/modules/sub1/config core.worktree
 		)
 	'
 	# ... absorbing a .git directory along the way.
-- 
2.20.0.rc2.403.gdbc3b29805-goog
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 21 in “[PATCH 0/4]”
  1. 0/4 Stefan Beller, Dec 7, 2018
  2. 1/4 submodule update: add regression test with old style setupsStefan Beller, Dec 7, 2018
  3. Junio C HamanoDec 9, 2018
  4. 2/4 submodule: unset core.worktree if no working tree is presentStefan Beller, Dec 7, 2018
  5. Junio C HamanoDec 8, 2018
  6. 3/4 submodule--helper: fix BUG message in ensure_core_worktreeStefan Beller, Dec 7, 2018
  7. Junio C HamanoDec 8, 2018
  8. Stefan BellerDec 12, 2018
  9. Junio C HamanoDec 13, 2018
  10. 4/4 submodule deinit: unset core.worktreeStefan Beller, Dec 7, 2018
  11. Junio C HamanoDec 8, 2018
  12. Junio C HamanoDec 8, 2018
  13. Stefan BellerDec 12, 2018
  14. Junio C HamanoDec 13, 2018
  15. 0/4 submodules: unset core.worktree when no working tree presentStefan Beller, Dec 14, 2018
  16. 1/4 submodule update: add regression test with old style setupsStefan Beller, Dec 14, 2018
  17. Junio C HamanoDec 26, 2018
  18. 2/4 submodule: unset core.worktree if no working tree is presentStefan Beller, Dec 14, 2018
  19. Junio C HamanoDec 26, 2018
  20. 4/4 submodule deinit: unset core.worktreeStefan Beller, Dec 14, 2018
  21. 3/4 submodule--helper: fix BUG message in ensure_core_worktreeStefan Beller, Dec 14, 2018

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.