Skip to content

Commit 46f74f0

Browse files
kraaigitster
authored andcommitted
Prefer EMAIL to username@hostname.
The environment variable $EMAIL gives a better default of user's preferred e-mail address than the hardcoded "username@hostname", as it is understood by many existing programs. We still honor GIT_*_EMAIL environment variables and user.email configuration variable give them higher precedence, so that the user can override $EMAIL or "username@hostname", as they are likely to be more specific to the context of working on a particular project. Signed-off-by: Matt Kraai <kraai@ftbfs.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 20ccef4 commit 46f74f0

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

ident.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,18 @@ static void setup_ident(void)
8383
}
8484

8585
if (!git_default_email[0]) {
86-
if (!pw)
87-
pw = getpwuid(getuid());
88-
if (!pw)
89-
die("You don't exist. Go away!");
90-
copy_email(pw);
86+
const char *email = getenv("EMAIL");
87+
88+
if (email && email[0])
89+
strlcpy(git_default_email, email,
90+
sizeof(git_default_email));
91+
else {
92+
if (!pw)
93+
pw = getpwuid(getuid());
94+
if (!pw)
95+
die("You don't exist. Go away!");
96+
copy_email(pw);
97+
}
9198
}
9299

93100
/* And set the default date */
@@ -197,8 +204,6 @@ const char *fmt_ident(const char *name, const char *email,
197204
name = git_default_name;
198205
if (!email)
199206
email = git_default_email;
200-
if (!email)
201-
email = getenv("EMAIL");
202207

203208
if (!*name) {
204209
struct passwd *pw;

0 commit comments

Comments
 (0)