ident: handle NULL email when complaining of empty name
If we see an empty name, we complain about and mention the
matching email in the error message (to give it some
context). However, the "email" pointer may be NULL here if
we were planning to fill it in later from ident_default_email().
This was broken by 59f929596 (fmt_ident: refactor strictness
checks, 2016-02-04). Prior to that commit, we would look up
the default name and email before doing any other actions.
So one solution would be to go back to that.
However, we can't just do so blindly. The logic for handling
the "!email" condition has grown since then. In particular,
looking up the default email can die if getpwuid() fails,
but there are other errors that should take precedence.
Commit 734c7789a (ident: check for useConfigOnly before
auto-detection of name/email, 2016-03-30) reordered the
checks so that we prefer the error message for
useConfigOnly.
Instead, we can observe that while the name-handling depends
on "email" being set, the reverse is not true. So we can
simply set up the email variable first.
This does mean that if both are bogus, we'll complain about
the email before the name. But between the two, there is no
reason to prefer one over the other.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-02-23 11:13:53 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='corner cases in ident strings'
|
2021-10-12 16:56:44 +03:00
|
|
|
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
ident: handle NULL email when complaining of empty name
If we see an empty name, we complain about and mention the
matching email in the error message (to give it some
context). However, the "email" pointer may be NULL here if
we were planning to fill it in later from ident_default_email().
This was broken by 59f929596 (fmt_ident: refactor strictness
checks, 2016-02-04). Prior to that commit, we would look up
the default name and email before doing any other actions.
So one solution would be to go back to that.
However, we can't just do so blindly. The logic for handling
the "!email" condition has grown since then. In particular,
looking up the default email can die if getpwuid() fails,
but there are other errors that should take precedence.
Commit 734c7789a (ident: check for useConfigOnly before
auto-detection of name/email, 2016-03-30) reordered the
checks so that we prefer the error message for
useConfigOnly.
Instead, we can observe that while the name-handling depends
on "email" being set, the reverse is not true. So we can
simply set up the email variable first.
This does mean that if both are bogus, we'll complain about
the email before the name. But between the two, there is no
reason to prefer one over the other.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-02-23 11:13:53 +03:00
|
|
|
. ./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 &&
|
2023-10-31 08:23:30 +03:00
|
|
|
test_grep ! "(null)" err
|
ident: handle NULL email when complaining of empty name
If we see an empty name, we complain about and mention the
matching email in the error message (to give it some
context). However, the "email" pointer may be NULL here if
we were planning to fill it in later from ident_default_email().
This was broken by 59f929596 (fmt_ident: refactor strictness
checks, 2016-02-04). Prior to that commit, we would look up
the default name and email before doing any other actions.
So one solution would be to go back to that.
However, we can't just do so blindly. The logic for handling
the "!email" condition has grown since then. In particular,
looking up the default email can die if getpwuid() fails,
but there are other errors that should take precedence.
Commit 734c7789a (ident: check for useConfigOnly before
auto-detection of name/email, 2016-03-30) reordered the
checks so that we prefer the error message for
useConfigOnly.
Instead, we can observe that while the name-handling depends
on "email" being set, the reverse is not true. So we can
simply set up the email variable first.
This does mean that if both are bogus, we'll complain about
the email before the name. But between the two, there is no
reason to prefer one over the other.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-02-23 11:13:53 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2017-02-23 11:15:55 +03:00
|
|
|
test_expect_success 'commit rejects all-crud name' '
|
ident: don't consider '.' a crud
When we process a user's name (as in user.name), we strip all
leading and trailing crud from it. Right now, we consider a dot
a crud character, and strip it off.
However, this is unsuitable for many personal names because humans
frequently have abbreviated suffixes, such as "Jr." or "Sr." at the end
of their names, and this corrupts them. Some other users may wish to
use an abbreviated name or initial, which will pose a problem especially
in cultures that write the family name first, followed by the personal
name.
Since the current approach causes lots of practical problems, let's
avoid it by no longer considering a dot to be crud.
Note that "." in the name forces the entire name to be quoted to
please mailers, but stripping "." only at the beginning and the end
does not help a name with "." in the middle (like "brian m. carlson")
so this change will not make it much worse. A name like "Given
Family, Jr." that did not have to be quoted now would need to be, in
order to be placed on the e-mail headers, though.
This is based on a weather-balloon patch by Jeff King sent in Aug 2021
https://lore.kernel.org/git/YSKm8Q8nyTavQaox@coredump.intra.peff.net/
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-08-02 19:49:32 +03:00
|
|
|
test_must_fail env GIT_AUTHOR_NAME=" ,;<>" \
|
2017-02-23 11:15:55 +03:00
|
|
|
git commit --allow-empty -m foo
|
|
|
|
'
|
|
|
|
|
ident: don't consider '.' a crud
When we process a user's name (as in user.name), we strip all
leading and trailing crud from it. Right now, we consider a dot
a crud character, and strip it off.
However, this is unsuitable for many personal names because humans
frequently have abbreviated suffixes, such as "Jr." or "Sr." at the end
of their names, and this corrupts them. Some other users may wish to
use an abbreviated name or initial, which will pose a problem especially
in cultures that write the family name first, followed by the personal
name.
Since the current approach causes lots of practical problems, let's
avoid it by no longer considering a dot to be crud.
Note that "." in the name forces the entire name to be quoted to
please mailers, but stripping "." only at the beginning and the end
does not help a name with "." in the middle (like "brian m. carlson")
so this change will not make it much worse. A name like "Given
Family, Jr." that did not have to be quoted now would need to be, in
order to be placed on the e-mail headers, though.
This is based on a weather-balloon patch by Jeff King sent in Aug 2021
https://lore.kernel.org/git/YSKm8Q8nyTavQaox@coredump.intra.peff.net/
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-08-02 19:49:32 +03:00
|
|
|
test_expect_success 'commit does not strip trailing dot' '
|
|
|
|
author_name="Pat Doe Jr." &&
|
|
|
|
env GIT_AUTHOR_NAME="$author_name" \
|
|
|
|
git commit --allow-empty -m foo &&
|
|
|
|
git log -1 --format=%an >actual &&
|
|
|
|
echo "$author_name" >expected &&
|
|
|
|
test_cmp actual expected
|
|
|
|
'
|
|
|
|
|
2017-02-23 11:17:08 +03:00
|
|
|
# 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 &&
|
2023-10-31 08:23:30 +03:00
|
|
|
test_grep "empty ident name" err &&
|
|
|
|
test_grep "Author identity unknown" err
|
2020-08-21 23:36:28 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
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 &&
|
2023-10-31 08:23:30 +03:00
|
|
|
test_grep "empty ident name" err &&
|
|
|
|
test_grep "Committer identity unknown" err
|
2017-02-23 11:17:08 +03:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
ident: handle NULL email when complaining of empty name
If we see an empty name, we complain about and mention the
matching email in the error message (to give it some
context). However, the "email" pointer may be NULL here if
we were planning to fill it in later from ident_default_email().
This was broken by 59f929596 (fmt_ident: refactor strictness
checks, 2016-02-04). Prior to that commit, we would look up
the default name and email before doing any other actions.
So one solution would be to go back to that.
However, we can't just do so blindly. The logic for handling
the "!email" condition has grown since then. In particular,
looking up the default email can die if getpwuid() fails,
but there are other errors that should take precedence.
Commit 734c7789a (ident: check for useConfigOnly before
auto-detection of name/email, 2016-03-30) reordered the
checks so that we prefer the error message for
useConfigOnly.
Instead, we can observe that while the name-handling depends
on "email" being set, the reverse is not true. So we can
simply set up the email variable first.
This does mean that if both are bogus, we'll complain about
the email before the name. But between the two, there is no
reason to prefer one over the other.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-02-23 11:13:53 +03:00
|
|
|
test_done
|