summaryrefslogtreecommitdiff
path: root/ident.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-08-21 20:36:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-21 22:35:47 (GMT)
commit9ed104e5cacdc44f2fe7c2b1fdeada94622ca4e9 (patch)
tree0579d1aeb1d432b547fa1ede3db106b24b7aeaef /ident.c
parent675a4aaf3b226c0089108221b96559e0baae5de9 (diff)
downloadgit-9ed104e5cacdc44f2fe7c2b1fdeada94622ca4e9.zip
git-9ed104e5cacdc44f2fe7c2b1fdeada94622ca4e9.tar.gz
git-9ed104e5cacdc44f2fe7c2b1fdeada94622ca4e9.tar.bz2
ident: say whose identity is missing when giving user.name hint
If `user.name` and `user.email` have not been configured and the user invokes: git commit --author=... without specifying the committer identity, then Git errors out with a message asking the user to configure `user.name` and `user.email` but doesn't tell the user which attribution was missing. This can be confusing for a user new to Git who isn't aware of the distinction between user, author, and committer. Give such users a bit more help by extending the error message to also say which attribution is expected. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ident.c')
-rw-r--r--ident.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/ident.c b/ident.c
index e666ee4..813741c 100644
--- a/ident.c
+++ b/ident.c
@@ -345,18 +345,32 @@ person_only:
return 0;
}
-static const char *env_hint =
-N_("\n"
- "*** Please tell me who you are.\n"
- "\n"
- "Run\n"
- "\n"
- " git config --global user.email \"you@example.com\"\n"
- " git config --global user.name \"Your Name\"\n"
- "\n"
- "to set your account\'s default identity.\n"
- "Omit --global to set the identity only in this repository.\n"
- "\n");
+
+static void ident_env_hint(enum want_ident whose_ident)
+{
+ switch (whose_ident) {
+ case WANT_AUTHOR_IDENT:
+ fputs(_("Author identity unknown\n"), stderr);
+ break;
+ case WANT_COMMITTER_IDENT:
+ fputs(_("Committer identity unknown\n"), stderr);
+ break;
+ default:
+ break;
+ }
+
+ fputs(_("\n"
+ "*** Please tell me who you are.\n"
+ "\n"
+ "Run\n"
+ "\n"
+ " git config --global user.email \"you@example.com\"\n"
+ " git config --global user.name \"Your Name\"\n"
+ "\n"
+ "to set your account\'s default identity.\n"
+ "Omit --global to set the identity only in this repository.\n"
+ "\n"), stderr);
+}
const char *fmt_ident(const char *name, const char *email,
enum want_ident whose_ident, const char *date_str, int flag)
@@ -375,12 +389,12 @@ const char *fmt_ident(const char *name, const char *email,
if (!email) {
if (strict && ident_use_config_only
&& !(ident_config_given & IDENT_MAIL_GIVEN)) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("no email was given and auto-detection is disabled"));
}
email = ident_default_email();
if (strict && default_email_is_bogus) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("unable to auto-detect email address (got '%s')"), email);
}
}
@@ -397,13 +411,13 @@ const char *fmt_ident(const char *name, const char *email,
if (!name) {
if (strict && ident_use_config_only
&& !(ident_config_given & IDENT_NAME_GIVEN)) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("no name was given and auto-detection is disabled"));
}
name = ident_default_name();
using_default = 1;
if (strict && default_name_is_bogus) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("unable to auto-detect name (got '%s')"), name);
}
}
@@ -411,7 +425,7 @@ const char *fmt_ident(const char *name, const char *email,
struct passwd *pw;
if (strict) {
if (using_default)
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("empty ident name (for <%s>) not allowed"), email);
}
pw = xgetpwuid_self(NULL);