Skip to content

Commit 8b27ff7

Browse files
moygitster
authored andcommitted
commit: advertise config --global --edit on guessed identity
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06b2d87 commit 8b27ff7

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

builtin/commit.c

+33-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,20 @@ static const char * const builtin_status_usage[] = {
4242
NULL
4343
};
4444

45-
static const char implicit_ident_advice[] =
45+
static const char implicit_ident_advice_noconfig[] =
46+
N_("Your name and email address were configured automatically based\n"
47+
"on your username and hostname. Please check that they are accurate.\n"
48+
"You can suppress this message by setting them explicitly. Run the\n"
49+
"following command and follow the instructions in your editor to edit\n"
50+
"your configuration file:\n"
51+
"\n"
52+
" git config --global --edit\n"
53+
"\n"
54+
"After doing this, you may fix the identity used for this commit with:\n"
55+
"\n"
56+
" git commit --amend --reset-author\n");
57+
58+
static const char implicit_ident_advice_config[] =
4659
N_("Your name and email address were configured automatically based\n"
4760
"on your username and hostname. Please check that they are accurate.\n"
4861
"You can suppress this message by setting them explicitly:\n"
@@ -1343,6 +1356,24 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13431356
return 0;
13441357
}
13451358

1359+
static const char *implicit_ident_advice(void)
1360+
{
1361+
char *user_config = NULL;
1362+
char *xdg_config = NULL;
1363+
int config_exists;
1364+
1365+
home_config_paths(&user_config, &xdg_config, "config");
1366+
config_exists = file_exists(user_config) || file_exists(xdg_config);
1367+
free(user_config);
1368+
free(xdg_config);
1369+
1370+
if (config_exists)
1371+
return _(implicit_ident_advice_config);
1372+
else
1373+
return _(implicit_ident_advice_noconfig);
1374+
1375+
}
1376+
13461377
static void print_summary(const char *prefix, const unsigned char *sha1,
13471378
int initial_commit)
13481379
{
@@ -1374,7 +1405,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
13741405
strbuf_addbuf_percentquote(&format, &committer_ident);
13751406
if (advice_implicit_identity) {
13761407
strbuf_addch(&format, '\n');
1377-
strbuf_addstr(&format, _(implicit_ident_advice));
1408+
strbuf_addstr(&format, implicit_ident_advice());
13781409
}
13791410
}
13801411
strbuf_release(&author_ident);

0 commit comments

Comments
 (0)