Merge branch 'jk/ident-empty'
user.email that consists of only cruft chars should consistently error out, but didn't. * jk/ident-empty: ident: do not ignore empty config name/email ident: reject all-crud ident name ident: handle NULL email when complaining of empty name ident: mark error messages for translation
This commit is contained in:
commit
066c38ca17
49
ident.c
49
ident.c
@ -153,7 +153,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email,
|
|||||||
|
|
||||||
const char *ident_default_name(void)
|
const char *ident_default_name(void)
|
||||||
{
|
{
|
||||||
if (!git_default_name.len) {
|
if (!(ident_config_given & IDENT_NAME_GIVEN) && !git_default_name.len) {
|
||||||
copy_gecos(xgetpwuid_self(&default_name_is_bogus), &git_default_name);
|
copy_gecos(xgetpwuid_self(&default_name_is_bogus), &git_default_name);
|
||||||
strbuf_trim(&git_default_name);
|
strbuf_trim(&git_default_name);
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ const char *ident_default_name(void)
|
|||||||
|
|
||||||
const char *ident_default_email(void)
|
const char *ident_default_email(void)
|
||||||
{
|
{
|
||||||
if (!git_default_email.len) {
|
if (!(ident_config_given & IDENT_MAIL_GIVEN) && !git_default_email.len) {
|
||||||
const char *email = getenv("EMAIL");
|
const char *email = getenv("EMAIL");
|
||||||
|
|
||||||
if (email && email[0]) {
|
if (email && email[0]) {
|
||||||
@ -203,6 +203,15 @@ static int crud(unsigned char c)
|
|||||||
c == '\'';
|
c == '\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int has_non_crud(const char *str)
|
||||||
|
{
|
||||||
|
for (; *str; str++) {
|
||||||
|
if (!crud(*str))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy over a string to the destination, but avoid special
|
* Copy over a string to the destination, but avoid special
|
||||||
* characters ('\n', '<' and '>') and remove crud at the end
|
* characters ('\n', '<' and '>') and remove crud at the end
|
||||||
@ -351,19 +360,32 @@ const char *fmt_ident(const char *name, const char *email,
|
|||||||
int want_date = !(flag & IDENT_NO_DATE);
|
int want_date = !(flag & IDENT_NO_DATE);
|
||||||
int want_name = !(flag & IDENT_NO_NAME);
|
int want_name = !(flag & IDENT_NO_NAME);
|
||||||
|
|
||||||
|
if (!email) {
|
||||||
|
if (strict && ident_use_config_only
|
||||||
|
&& !(ident_config_given & IDENT_MAIL_GIVEN)) {
|
||||||
|
fputs(_(env_hint), stderr);
|
||||||
|
die(_("no email was given and auto-detection is disabled"));
|
||||||
|
}
|
||||||
|
email = ident_default_email();
|
||||||
|
if (strict && default_email_is_bogus) {
|
||||||
|
fputs(_(env_hint), stderr);
|
||||||
|
die(_("unable to auto-detect email address (got '%s')"), email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (want_name) {
|
if (want_name) {
|
||||||
int using_default = 0;
|
int using_default = 0;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
if (strict && ident_use_config_only
|
if (strict && ident_use_config_only
|
||||||
&& !(ident_config_given & IDENT_NAME_GIVEN)) {
|
&& !(ident_config_given & IDENT_NAME_GIVEN)) {
|
||||||
fputs(_(env_hint), stderr);
|
fputs(_(env_hint), stderr);
|
||||||
die("no name was given and auto-detection is disabled");
|
die(_("no name was given and auto-detection is disabled"));
|
||||||
}
|
}
|
||||||
name = ident_default_name();
|
name = ident_default_name();
|
||||||
using_default = 1;
|
using_default = 1;
|
||||||
if (strict && default_name_is_bogus) {
|
if (strict && default_name_is_bogus) {
|
||||||
fputs(_(env_hint), stderr);
|
fputs(_(env_hint), stderr);
|
||||||
die("unable to auto-detect name (got '%s')", name);
|
die(_("unable to auto-detect name (got '%s')"), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!*name) {
|
if (!*name) {
|
||||||
@ -371,24 +393,13 @@ const char *fmt_ident(const char *name, const char *email,
|
|||||||
if (strict) {
|
if (strict) {
|
||||||
if (using_default)
|
if (using_default)
|
||||||
fputs(_(env_hint), stderr);
|
fputs(_(env_hint), stderr);
|
||||||
die("empty ident name (for <%s>) not allowed", email);
|
die(_("empty ident name (for <%s>) not allowed"), email);
|
||||||
}
|
}
|
||||||
pw = xgetpwuid_self(NULL);
|
pw = xgetpwuid_self(NULL);
|
||||||
name = pw->pw_name;
|
name = pw->pw_name;
|
||||||
}
|
}
|
||||||
}
|
if (strict && !has_non_crud(name))
|
||||||
|
die(_("name consists only of disallowed characters: %s"), name);
|
||||||
if (!email) {
|
|
||||||
if (strict && ident_use_config_only
|
|
||||||
&& !(ident_config_given & IDENT_MAIL_GIVEN)) {
|
|
||||||
fputs(_(env_hint), stderr);
|
|
||||||
die("no email was given and auto-detection is disabled");
|
|
||||||
}
|
|
||||||
email = ident_default_email();
|
|
||||||
if (strict && default_email_is_bogus) {
|
|
||||||
fputs(_(env_hint), stderr);
|
|
||||||
die("unable to auto-detect email address (got '%s')", email);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_reset(&ident);
|
strbuf_reset(&ident);
|
||||||
@ -403,7 +414,7 @@ const char *fmt_ident(const char *name, const char *email,
|
|||||||
strbuf_addch(&ident, ' ');
|
strbuf_addch(&ident, ' ');
|
||||||
if (date_str && date_str[0]) {
|
if (date_str && date_str[0]) {
|
||||||
if (parse_date(date_str, &ident) < 0)
|
if (parse_date(date_str, &ident) < 0)
|
||||||
die("invalid date format: %s", date_str);
|
die(_("invalid date format: %s"), date_str);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strbuf_addstr(&ident, ident_default_date());
|
strbuf_addstr(&ident, ident_default_date());
|
||||||
|
36
t/t7518-ident-corner-cases.sh
Executable file
36
t/t7518-ident-corner-cases.sh
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='corner cases in ident strings'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
# confirm that we do not segfault _and_ that we do not say "(null)", as
|
||||||
|
# glibc systems will quietly handle our NULL pointer
|
||||||
|
#
|
||||||
|
# Note also that we can't use "env" here because we need to unset a variable,
|
||||||
|
# and "-u" is not portable.
|
||||||
|
test_expect_success 'empty name and missing email' '
|
||||||
|
(
|
||||||
|
sane_unset GIT_AUTHOR_EMAIL &&
|
||||||
|
GIT_AUTHOR_NAME= &&
|
||||||
|
test_must_fail git commit --allow-empty -m foo 2>err &&
|
||||||
|
test_i18ngrep ! null err
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit rejects all-crud name' '
|
||||||
|
test_must_fail env GIT_AUTHOR_NAME=" .;<>" \
|
||||||
|
git commit --allow-empty -m foo
|
||||||
|
'
|
||||||
|
|
||||||
|
# We must test the actual error message here, as an unwanted
|
||||||
|
# auto-detection could fail for other reasons.
|
||||||
|
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_done
|
Loading…
Reference in New Issue
Block a user