Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have a trailing period in user.name in Git?

Tags:

git

The following Git statement

cd periodtest/
git init
git config user.name "Test."

# verify that user.name is 'Test.'
git config user.name

touch README
git add README
git commit -a -m "period test"

Results in the following checkout

# check user name after commit
git log 
And the resulting commit w/out the period was:
commit 9b7e4960fd8129059b5759d1bb937b60241fd70b
Author: Test <[email protected]>
Date:   Wed Oct 1 20:28:28 2014 -0700

    period test

Is there a way to get that period to stay in the username?

like image 350
Jeef Avatar asked Oct 02 '14 10:10

Jeef


People also ask

Does git user name matter?

No, your user.name does not matter.


1 Answers

This behaviour is hardcoded into git.

Edit: As it stands this is still true for git version 2.25.1 (27. February 2020).

To create the author string during a commit git removes crud (as git calls it) from the beginning and the end of the string. For this it uses the strbuf_addstr_without_crud function defined in ident.c - see ident.c line 426 version 2.25.1.

Take a look at the function header:

/*
 * Copy over a string to the destination, but avoid special
 * characters ('\n', '<' and '>') and remove crud at the end
 */
static void strbuf_addstr_without_crud(struct strbuf *sb, const char *src)

See ident.c lines 225-262 version 2.25.1.

Git determines crud via another function which checks for specific characters.

static int crud(unsigned char c)
{
  return  c <= 32  ||
    c == '.' ||
    c == ',' ||
    c == ':' ||
    c == ';' ||
    c == '<' ||
    c == '>' ||
    c == '"' ||
    c == '\\' ||
    c == '\'';
}

See ident.c lines 198-210 version 2.25.1.

As you can see a period is considered crud by git and will be removed, at the moment there is no flag or option you can set to avoid this behaviour.


This means you have two options.

  1. You fork git and change the way git creates the author string.

  2. Or you append another character after the trailing period, for example a Zero-width space (which often won't be printed properly on a console)

Alternatively you can always submit a feature request on the git mailing list, but in this case I wouldn't raise my hopes too high.

like image 192
Sascha Wolf Avatar answered Dec 01 '22 21:12

Sascha Wolf