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

[RFC 03/10] submodule: use the 'submodules_file' variable in output messages

From
Antonio Ospite <ao2@ao2.it>
Date
Apr 12, 2018, 22:20 UTC
Message-ID
<20180412222047.5716-4-ao2@ao2.it>
In-Reply-To
<20180412222047.5716-1-ao2@ao2.it>

The gitmodules file path can be customized by setting the 'core.submodulesFile' config option.

Use the 'submodules_file' variable instead of the hardcoded '.gitmodules' in output messages, to reflect the actual path of the gitmodules file.

NOTE: the default git configuration has to be initialized in
'builtin/submodule--helper.c' to make the actual value of
'submodules_file', overridden by 'core.submodulesFile', available to the
helper command.
Signed-off-by: Antonio Ospite <ao2@ao2.it>
---
 builtin/mv.c                |  3 ++-
 builtin/rm.c                |  3 ++-
 builtin/submodule--helper.c | 18 ++++++++++--------
 submodule-config.c          |  4 ++--
 submodule.c                 | 14 +++++++-------
 5 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index 6d141f7a5..ec8f139c4 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -82,7 +82,8 @@ static void prepare_move_submodule(const char *src, int first,
 	if (!S_ISGITLINK(active_cache[first]->ce_mode))
 		die(_("Directory %s is in index and no submodule?"), src);
 	if (!is_staging_gitmodules_ok(&the_index))
-		die(_("Please stage your changes to .gitmodules or stash them to proceed"));
+		die(_("Please stage your changes to %s or stash them to proceed"),
+		    submodules_file);
 	strbuf_addf(&submodule_dotgit, "%s/.git", src);
 	*submodule_gitfile = read_gitfile(submodule_dotgit.buf);
 	if (*submodule_gitfile)
diff --git a/builtin/rm.c b/builtin/rm.c
index 5b6fc7ee8..6fd015d86 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -286,7 +286,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 		list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);
 		if (list.entry[list.nr++].is_submodule &&
 		    !is_staging_gitmodules_ok(&the_index))
-			die (_("Please stage your changes to .gitmodules or stash them to proceed"));
+			die (_("Please stage your changes to %s or stash them to proceed"),
+			     submodules_file);
 	}
 
 	if (pathspec.nr) {
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a404df3ea..72b95d27b 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -458,8 +458,8 @@ static void init_submodule(const char *path, const char *prefix,
 	sub = submodule_from_path(&null_oid, path);
 
 	if (!sub)
-		die(_("No url found for submodule path '%s' in .gitmodules"),
-			displaypath);
+		die(_("No url found for submodule path '%s' in %s"),
+			displaypath, submodules_file);
 
 	/*
 	 * NEEDSWORK: In a multi-working-tree world, this needs to be
@@ -481,8 +481,8 @@ static void init_submodule(const char *path, const char *prefix,
 	strbuf_addf(&sb, "submodule.%s.url", sub->name);
 	if (git_config_get_string(sb.buf, &url)) {
 		if (!sub->url)
-			die(_("No url found for submodule path '%s' in .gitmodules"),
-				displaypath);
+			die(_("No url found for submodule path '%s' in %s"),
+				displaypath, submodules_file);
 
 		url = xstrdup(sub->url);
 
@@ -623,8 +623,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
 	int diff_files_result;
 
 	if (!submodule_from_path(&null_oid, path))
-		die(_("no submodule mapping found in .gitmodules for path '%s'"),
-		      path);
+		die(_("no submodule mapping found in %s for path '%s'"),
+		      submodules_file, path);
 
 	displaypath = get_submodule_displaypath(path, prefix);
 
@@ -749,8 +749,8 @@ static int module_name(int argc, const char **argv, const char *prefix)
 	sub = submodule_from_path(&null_oid, argv[1]);
 
 	if (!sub)
-		die(_("no submodule mapping found in .gitmodules for path '%s'"),
-		    argv[1]);
+		die(_("no submodule mapping found in %s for path '%s'"),
+		    submodules_file, argv[1]);
 
 	printf("%s\n", sub->name);
 
@@ -1855,6 +1855,8 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
 	if (argc < 2 || !strcmp(argv[1], "-h"))
 		usage("git submodule--helper <command>");
 
+	git_config(git_default_config, NULL);
+
 	for (i = 0; i < ARRAY_SIZE(commands); i++) {
 		if (!strcmp(argv[1], commands[i].cmd)) {
 			if (get_super_prefix() &&
diff --git a/submodule-config.c b/submodule-config.c
index 8a3396ade..620d522ee 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -347,9 +347,9 @@ static void warn_multiple_config(const unsigned char *treeish_name,
 	const char *commit_string = "WORKTREE";
 	if (treeish_name)
 		commit_string = sha1_to_hex(treeish_name);
-	warning("%s:.gitmodules, multiple configurations found for "
+	warning("%s:%s, multiple configurations found for "
 			"'submodule.%s.%s'. Skipping second one!",
-			commit_string, name, option);
+			commit_string, submodules_file, name, option);
 }
 
 struct parse_config_parameter {
diff --git a/submodule.c b/submodule.c
index 2afbdb644..97213b549 100644
--- a/submodule.c
+++ b/submodule.c
@@ -94,11 +94,11 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
 		return -1;
 
 	if (is_gitmodules_unmerged(&the_index))
-		die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
+		die(_("Cannot change unmerged %s, resolve merge conflicts first"), submodules_file);
 
 	submodule = submodule_from_path(&null_oid, oldpath);
 	if (!submodule || !submodule->name) {
-		warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
+		warning(_("Could not find section in %s where path=%s"), submodules_file, oldpath);
 		return -1;
 	}
 	strbuf_addstr(&entry, "submodule.");
@@ -106,7 +106,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
 	strbuf_addstr(&entry, ".path");
 	if (git_config_set_in_file_gently(submodules_file, entry.buf, newpath) < 0) {
 		/* Maybe the user already did that, don't error out here */
-		warning(_("Could not update .gitmodules entry %s"), entry.buf);
+		warning(_("Could not update %s entry %s"), submodules_file, entry.buf);
 		strbuf_release(&entry);
 		return -1;
 	}
@@ -128,18 +128,18 @@ int remove_path_from_gitmodules(const char *path)
 		return -1;
 
 	if (is_gitmodules_unmerged(&the_index))
-		die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
+		die(_("Cannot change unmerged %s, resolve merge conflicts first"), submodules_file);
 
 	submodule = submodule_from_path(&null_oid, path);
 	if (!submodule || !submodule->name) {
-		warning(_("Could not find section in .gitmodules where path=%s"), path);
+		warning(_("Could not find section in %s where path=%s"), submodules_file, path);
 		return -1;
 	}
 	strbuf_addstr(&sect, "submodule.");
 	strbuf_addstr(&sect, submodule->name);
 	if (git_config_rename_section_in_file(submodules_file, sect.buf, NULL) < 0) {
 		/* Maybe the user already did that, don't error out here */
-		warning(_("Could not remove .gitmodules entry for %s"), path);
+		warning(_("Could not remove %s entry for %s"), submodules_file, path);
 		strbuf_release(&sect);
 		return -1;
 	}
@@ -150,7 +150,7 @@ int remove_path_from_gitmodules(const char *path)
 void stage_updated_gitmodules(struct index_state *istate)
 {
 	if (add_file_to_index(istate, submodules_file, 0))
-		die(_("staging updated .gitmodules failed"));
+		die(_("staging updated %s failed"), submodules_file);
 }
 
 static int add_submodule_odb(const char *path)
-- 
2.17.0
Previous: Antonio OspiteNext: Antonio Ospite
Message 2 of 28 in “[RFC 00/10] Make .the gitmodules file path configurable”
  1. Antonio OspiteApr 12, 2018
  2. 03/10 submodule: use the 'submodules_file' variable in output messagesAntonio Ospite, Apr 12, 2018
  3. 02/10 submodule: fix getting custom gitmodule file in fetch commandAntonio Ospite, Apr 12, 2018
  4. Stefan BellerApr 12, 2018
  5. Antonio OspiteApr 16, 2018
  6. Stefan BellerApr 16, 2018
  7. Antonio OspiteApr 16, 2018
  8. 01/10 submodule: add 'core.submodulesFile' to override the '.gitmodules' pathAntonio Ospite, Apr 12, 2018
  9. Stefan BellerApr 12, 2018
  10. Antonio OspiteApr 16, 2018
  11. Stefan BellerApr 16, 2018
  12. Antonio OspiteApr 18, 2018
  13. Stefan BellerApr 18, 2018
  14. 04/10 submodule: document 'core.submodulesFile' and fix references to '.gitmodules'Antonio Ospite, Apr 12, 2018
  15. 05/10 submodule: adjust references to '.gitmodules' in commentsAntonio Ospite, Apr 12, 2018
  16. 06/10 completion: add 'core.submodulesfile' to the git-completion.bash fileAntonio Ospite, Apr 12, 2018
  17. Stefan BellerApr 12, 2018
  18. Antonio OspiteApr 16, 2018
  19. Stefan BellerApr 16, 2018
  20. Antonio OspiteApr 13, 2018
  21. 07/10 FIXME: wrap-for-bin.sh: set 'core.submodulesFile' for each git invocationAntonio Ospite, Apr 13, 2018
  22. 09/10 FIXME: submodule: pass custom gitmodules file to 'test-tool submodule-config'Antonio Ospite, Apr 13, 2018
  23. 10/10 FIXME: add a hacky script to test the changes with a patched test suiteAntonio Ospite, Apr 13, 2018
  24. 08/10 FIXME: submodule: fix t1300-repo-config.sh to take into account the new configAntonio Ospite, Apr 13, 2018
  25. Stefan BellerApr 13, 2018
  26. Antonio OspiteApr 16, 2018
  27. Jonathan NiederApr 23, 2018
  28. Antonio OspiteApr 30, 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.