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

[RFC PATCH 3/3] commit: advertize config --global --edit on guessed identity

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jul 25, 2014, 13:44 UTC
Message-ID
<1406295891-7316-3-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1406295891-7316-1-git-send-email-Matthieu.Moy@imag.fr>

When the user has no user-wide configuration file, it's faster to use the newly introduced config file template than to run two commands to set user.name and user.email. Advise this to the user.

The old advice is kept if the user already has a configuration file since the template feature would not trigger in this case.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 builtin/commit.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index f2d7979..52ef5a8 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -42,7 +42,20 @@ static const char * const builtin_status_usage[] = {
 	NULL
 };
 
-static const char implicit_ident_advice[] =
+static const char implicit_ident_advice_noconfig[] =
+N_("Your name and email address were configured automatically based\n"
+"on your username and hostname. Please check that they are accurate.\n"
+"You can suppress this message by setting them explicitly. Run the\n"
+"following command and follow the instructions in your editor to edit\n"
+"your configuration file:\n"
+"\n"
+"    git config --global --edit\n"
+"\n"
+"After doing this, you may fix the identity used for this commit with:\n"
+"\n"
+"    git commit --amend --reset-author\n");
+
+static const char implicit_ident_advice_config[] =
 N_("Your name and email address were configured automatically based\n"
 "on your username and hostname. Please check that they are accurate.\n"
 "You can suppress this message by setting them explicitly:\n"
@@ -1403,6 +1416,23 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+static const char *implicit_ident_advice() {
+	char *user_config = NULL;
+	char *xdg_config = NULL;
+	int config_exists;
+
+	home_config_paths(&user_config, &xdg_config, "config");
+	config_exists = file_exists(user_config) || file_exists(xdg_config);
+	free(user_config);
+	free(xdg_config);
+
+	if (config_exists)
+		return _(implicit_ident_advice_config);
+	else
+		return _(implicit_ident_advice_noconfig);
+
+}
+
 static void print_summary(const char *prefix, const unsigned char *sha1,
 			  int initial_commit)
 {
@@ -1441,7 +1471,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
 		strbuf_addbuf_percentquote(&format, &committer_ident);
 		if (advice_implicit_identity) {
 			strbuf_addch(&format, '\n');
-			strbuf_addstr(&format, _(implicit_ident_advice));
+			strbuf_addstr(&format, implicit_ident_advice());
 		}
 	}
 	strbuf_release(&author_ident);
-- 
2.0.2.737.gfb43bde
Previous: Matthieu MoyNext: Eric Sunshine
Message 6 of 13 in “config --global --edit: create a template file if needed”
  1. 1/3 config --global --edit: create a template file if neededMatthieu Moy, Jul 25, 2014
  2. 2/3 home_config_path: allow NULL xdg parameterMatthieu Moy, Jul 25, 2014
  3. Tanay AbhraJul 25, 2014
  4. Junio C HamanoJul 25, 2014
  5. Matthieu MoyJul 25, 2014
  6. 3/3 commit: advertize config --global --edit on guessed identityMatthieu Moy, Jul 25, 2014
  7. Eric SunshineJul 25, 2014
  8. Eric SunshineJul 25, 2014
  9. Matthieu MoyJul 25, 2014
  10. Eric SunshineJul 25, 2014
  11. Junio C HamanoJul 25, 2014
  12. Junio C HamanoJul 25, 2014
  13. Matthieu MoyJul 25, 2014

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.