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

[PATCH v6 05/15] submodule: die on config error when linking modules

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 22, 2016, 11:23 UTC
Message-ID
<1456140216-24169-6-git-send-email-ps@pks.im>
In-Reply-To
<1456140216-24169-1-git-send-email-ps@pks.im>

When trying to connect a submodule with its corresponding repository in '.git/modules' we try to set the core.worktree setting in the submodule, which may fail due to an error encountered in `git_config_set_in_file`.

The function is used in the git-mv command when trying to move a submodule to another location. We already die when renaming a file fails but do not pay attention to the case where updating the connection between submodule and its repository fails. As this leaves the repository in an inconsistent state, as well, abort the program by dying early and presenting the failure to the user.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 submodule.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/submodule.c b/submodule.c
index b83939c..589a82c 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1087,11 +1087,9 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	/* Update core.worktree setting */
 	strbuf_reset(&file_name);
 	strbuf_addf(&file_name, "%s/config", git_dir);
-	if (git_config_set_in_file(file_name.buf, "core.worktree",
-				   relative_path(real_work_tree, git_dir,
-						 &rel_path)))
-		die(_("Could not set core.worktree in %s"),
-		    file_name.buf);
+	git_config_set_in_file_or_die(file_name.buf, "core.worktree",
+				      relative_path(real_work_tree, git_dir,
+						    &rel_path));
 
 	strbuf_release(&file_name);
 	strbuf_release(&rel_path);
-- 
2.7.1
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 6 of 16 in “config: make git_config_set die on failure”
  1. 00/15 config: make git_config_set die on failurePatrick Steinhardt, Feb 22, 2016
  2. 01/15 config: introduce set_or_die wrappersPatrick Steinhardt, Feb 22, 2016
  3. 02/15 branch: report errors in tracking branch setupPatrick Steinhardt, Feb 22, 2016
  4. 03/15 branch: die on config error when unsetting upstreamPatrick Steinhardt, Feb 22, 2016
  5. 04/15 branch: die on config error when editing branch descriptionPatrick Steinhardt, Feb 22, 2016
  6. 05/15 submodule: die on config error when linking modulesPatrick Steinhardt, Feb 22, 2016
  7. 06/15 submodule--helper: die on config error when cloning modulePatrick Steinhardt, Feb 22, 2016
  8. 07/15 remote: die on config error when setting URLPatrick Steinhardt, Feb 22, 2016
  9. 08/15 remote: die on config error when setting/adding branchesPatrick Steinhardt, Feb 22, 2016
  10. 09/15 remote: die on config error when manipulating remotesPatrick Steinhardt, Feb 22, 2016
  11. 10/15 clone: die on config error in cmd_clonePatrick Steinhardt, Feb 22, 2016
  12. 11/15 init-db: die on config errors when initializing empty repoPatrick Steinhardt, Feb 22, 2016
  13. 12/15 sequencer: die on config error when saving replay optsPatrick Steinhardt, Feb 22, 2016
  14. 13/15 compat: die when unable to set core.precomposeunicodePatrick Steinhardt, Feb 22, 2016
  15. 14/15 config: rename git_config_set to git_config_set_gentlyPatrick Steinhardt, Feb 22, 2016
  16. 15/15 config: rename git_config_set_or_die to git_config_setPatrick Steinhardt, Feb 22, 2016

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.