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

[PATCH] git-remote: load config whenever create_symref() might be called

From
JDJérémie Detrey <jeremie.detrey@altu.fr>
Date
Dec 26, 2020, 13:44 UTC
Message-ID
<20201226134420.722643-1-Jeremie.Detrey@altu.fr>

Currently, the calls to `create_symref()` do not honor the `core.logAllRefUpdates` nor the `user.{name,email}` configuration settings, and therefore write reflogs even when explicitly asked not to, and ignore the configured user identity.

This happens on `git remote add --fetch`, `git remote set-head`, and `git remote rename`: these are the three commands which may create a symbolic-ref for the remote's HEAD.

A call to `git_config(git_default_config, NULL);` for these three commands is enough to load the necessary configuration beforehand.

The call to `git_config()` was inserted right after command-line processing for these three commands. One might also decide to push it closer to the actual call to `create_symref()`, as it is not needed elsewhere, but it made more sense not to have it buried into nested `if` conditions.

Signed-off-by: Jérémie Detrey <Jeremie.Detrey@altu.fr>
---
 builtin/remote.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/builtin/remote.c b/builtin/remote.c
index 64b4b551eb..f797fc3f65 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -190,6 +190,8 @@ static int add(int argc, const char **argv)
 	name = argv[0];
 	url = argv[1];
 
+	git_config(git_default_config, NULL);
+
 	remote = remote_get(name);
 	if (remote_is_configured(remote, 1))
 		die(_("remote %s already exists."), name);
@@ -685,6 +687,8 @@ static int mv(int argc, const char **argv)
 	rename.new_name = argv[2];
 	rename.remote_branches = &remote_branches;
 
+	git_config(git_default_config, NULL);
+
 	oldremote = remote_get(rename.old_name);
 	if (!remote_is_configured(oldremote, 1))
 		die(_("No such remote: '%s'"), rename.old_name);
@@ -1326,6 +1330,8 @@ static int set_head(int argc, const char **argv)
 	if (argc)
 		strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
 
+	git_config(git_default_config, NULL);
+
 	if (!opt_a && !opt_d && argc == 2) {
 		head_name = xstrdup(argv[1]);
 	} else if (opt_a && !opt_d && argc == 1) {
-- 
2.29.2
Next: Junio C Hamano
Message 1 of 5 in “git-remote: load config whenever create_symref() might be called”
  1. git-remote: load config whenever create_symref() might be calledJérémie Detrey, Dec 26, 2020
  2. Junio C HamanoDec 26, 2020
  3. Jérémie DetreyDec 26, 2020
  4. Eric SunshineDec 27, 2020
  5. Junio C HamanoDec 27, 2020

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.