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

Re: names using git config

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 25, 2009, 05:11 UTC
Message-ID
<7veit8kidz.fsf@alter.siamese.dyndns.org>
In-Reply-To
<376636be0906242146h1d4c3b1q8c2e9af26f124af4@mail.gmail.com>
Ryan <ryanphilips19@googlemail.com> writes:
Show 7 quoted lines
> Hi,
>   Thank you for your response.
>
> 1) git config user.name 'Matthieu M. Moy' Works
> 2) git config user.name 'Matthieu M.'  does not
>
> Name cannot end in a '.' <dot>. in git config user.name

That is correct, but I think we are a bit too strict in sanitizing names. The code is ident.c::copy() whose intent was to sanitize useless runs of commas we slurp from GECOS field, but the sanitization is done also for anything specified by the end user.

This patch loosens it, but I think it goes too far, in that it does not stop you from feeding total nonsense with GIT_AUTHOR_NAME environment and user.name configuration.

 ident.c                |    5 ++---
 t/t1300-repo-config.sh |   12 ++++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/ident.c b/ident.c
index 99f1c85..07ec81d 100644
--- a/ident.c
+++ b/ident.c
@@ -212,8 +212,7 @@ const char *fmt_ident(const char *name, const char *email,
 		pw = getpwuid(getuid());
 		if (!pw)
 			die("You don't exist. Go away!");
-		strlcpy(git_default_name, pw->pw_name,
-			sizeof(git_default_name));
+		copy(git_default_name, sizeof(git_default_name), 0, pw->pw_name);
 		name = git_default_name;
 	}
 
@@ -221,7 +220,7 @@ const char *fmt_ident(const char *name, const char *email,
 	if (!name_addr_only && date_str)
 		parse_date(date_str, date, sizeof(date));
 
-	i = copy(buffer, sizeof(buffer), 0, name);
+	i = add_raw(buffer, sizeof(buffer), 0, name);
 	i = add_raw(buffer, sizeof(buffer), i, " <");
 	i = copy(buffer, sizeof(buffer), i, email);
 	if (!name_addr_only) {
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 43ea283..c1a913e 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -758,4 +758,16 @@ test_expect_success 'check split_cmdline return' "
 	test_must_fail git merge master
 	"
 
+test_expect_success 'name ending in dot' '
+	foobar="Foo Bar."
+	git config user.name "$foobar" &&
+	git config user.email "foo.bar@example.com" &&
+	test "$(git config user.name)" = "$foobar" &&
+	(
+		unset GIT_AUTHOR_NAME
+		ident=$(git var GIT_AUTHOR_IDENT | sed -e "s/ *<.*//") &&
+		test "$ident" = "$foobar"
+	)
+'
+
 test_done
Previous: RyanNext: Ryan
Message 4 of 6 in “names using git config”
  1. RyanJun 24, 2009
  2. Matthieu MoyJun 24, 2009
  3. RyanJun 25, 2009
  4. Junio C HamanoJun 25, 2009
  5. RyanJun 25, 2009
  6. Junio C HamanoJun 25, 2009

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.