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 <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Jul 25, 2014 at 21:11 UTC
8b27ff7eacc3bafcb12afcd6bbc99cdb8d718a26
1 file changed
+33
-2
builtin/commit.c
+33
-2
@@ -42,7 +42,20 @@ static const char * const builtin_status_usage[] = {
42
NULL
43
};
44
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[] =
59
N_("Your name and email address were configured automatically based\n"
60
"on your username and hostname. Please check that they are accurate.\n"
61
"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)
1356
return 0;
1357
}
1358
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
+
1377
static void print_summary(const char *prefix, const unsigned char *sha1,
1378
int initial_commit)
1379
{
@@ -1374,7 +1405,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
1405
strbuf_addbuf_percentquote(&format, &committer_ident);
1406
if (advice_implicit_identity) {
1407
strbuf_addch(&format, '\n');
1377
- strbuf_addstr(&format, _(implicit_ident_advice));
1408
+ strbuf_addstr(&format, implicit_ident_advice());
1409
}
1410
}
1411
strbuf_release(&author_ident);