git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Andreas Schwab <schwab@linux-m68k.org>,
	Alvaro Aleman <aaleman@redhat.com>
Subject: [PATCH] ident: say whose identity is missing when giving user.name hint
Date: Fri, 21 Aug 2020 13:36:28 -0700	[thread overview]
Message-ID: <xmqq5z9b91o3.fsf_-_@gitster.c.googlers.com> (raw)
In-Reply-To: <CAOW=8D3WZyoc=PpyzmPRYM2MT_=F4tnuTxJ0Z+_dHMb4Xk8imQ@mail.gmail.com> (Alvaro Aleman's message of "Fri, 21 Aug 2020 15:55:51 -0400")

OK, so here is essentially the same patch but with a bit of cleaning
up, with a test update and a proposed log message.

-- >8 --
When the author or the committer identity is missing when required,
"git" errors out with a message that suggests to set these
configuration variables at the per-user level as the easiest way
forward.  This message is given to a brand-new user, whose
~/.gitconfig hasn't been configured for user.name and user.email,
who runs "git commit --author=...", too, but such a user may find it
confusing ("why?  I just gave you a name and e-mail").

State whose identity is missing as the reason why we are erroring
out, when we give the hint, to help reduce the confusion.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 ident.c                       | 48 ++++++++++++++++++++++-------------
 t/t7518-ident-corner-cases.sh | 13 +++++++++-
 2 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/ident.c b/ident.c
index e666ee4e59..813741c06c 100644
--- a/ident.c
+++ b/ident.c
@@ -345,18 +345,32 @@ int split_ident_line(struct ident_split *split, const char *line, int len)
 	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);
diff --git a/t/t7518-ident-corner-cases.sh b/t/t7518-ident-corner-cases.sh
index b22f631261..dc3e9c8c88 100755
--- a/t/t7518-ident-corner-cases.sh
+++ b/t/t7518-ident-corner-cases.sh
@@ -29,7 +29,18 @@ test_expect_success 'empty configured name does not auto-detect' '
 		sane_unset GIT_AUTHOR_NAME &&
 		test_must_fail \
 			git -c user.name= commit --allow-empty -m foo 2>err &&
-		test_i18ngrep "empty ident name" err
+		test_i18ngrep "empty ident name" err &&
+		test_i18ngrep "Author identity unknown" err
+	)
+'
+
+test_expect_success 'empty configured name does not auto-detect for committer' '
+	(
+		sane_unset GIT_COMMITTER_NAME &&
+		test_must_fail \
+			git -c user.name= commit --allow-empty -m foo 2>err &&
+		test_i18ngrep "empty ident name" err &&
+		test_i18ngrep "Committer identity unknown" err
 	)
 '
 
-- 
2.28.0-416-g2947c83ecf


  reply	other threads:[~2020-08-21 20:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 16:15 --author arg on commit only works if there is an email configured already Alvaro Aleman
2020-08-21 18:28 ` Andreas Schwab
2020-08-21 18:46   ` Junio C Hamano
2020-08-21 19:55     ` Alvaro Aleman
2020-08-21 20:36       ` Junio C Hamano [this message]
2020-08-21 20:52         ` [PATCH] ident: say whose identity is missing when giving user.name hint Eric Sunshine
2020-08-21 21:13           ` Junio C Hamano
2020-08-21 21:31             ` Alvaro Aleman
2020-08-21 21:37               ` Eric Sunshine
2020-08-21 22:35                 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq5z9b91o3.fsf_-_@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=aaleman@redhat.com \
    --cc=git@vger.kernel.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).