зеркало из https://github.com/microsoft/git.git
Merge branch 'jk/send-email-sender-prompt'
General clean-ups in various areas, originally written to support a patch that later turned out to be unneeded. * jk/send-email-sender-prompt: t9001: check send-email behavior with implicit sender t: add tests for "git var" ident: keep separate "explicit" flags for author and committer ident: make user_ident_explicitly_given static t7502: factor out autoident prerequisite test-lib: allow negation of prerequisites
This commit is contained in:
Коммит
16e6e7284f
|
@ -755,7 +755,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
|||
ident_shown++ ? "" : "\n",
|
||||
author_ident->buf);
|
||||
|
||||
if (!user_ident_sufficiently_given())
|
||||
if (!committer_ident_sufficiently_given())
|
||||
status_printf_ln(s, GIT_COLOR_NORMAL,
|
||||
_("%s"
|
||||
"Committer: %s"),
|
||||
|
@ -1265,7 +1265,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
|
|||
strbuf_addstr(&format, "\n Author: ");
|
||||
strbuf_addbuf_percentquote(&format, &author_ident);
|
||||
}
|
||||
if (!user_ident_sufficiently_given()) {
|
||||
if (!committer_ident_sufficiently_given()) {
|
||||
strbuf_addstr(&format, "\n Committer: ");
|
||||
strbuf_addbuf_percentquote(&format, &committer_ident);
|
||||
if (advice_implicit_identity) {
|
||||
|
|
7
cache.h
7
cache.h
|
@ -1149,11 +1149,8 @@ struct config_include_data {
|
|||
#define CONFIG_INCLUDE_INIT { 0 }
|
||||
extern int git_config_include(const char *name, const char *value, void *data);
|
||||
|
||||
#define IDENT_NAME_GIVEN 01
|
||||
#define IDENT_MAIL_GIVEN 02
|
||||
#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
|
||||
extern int user_ident_explicitly_given;
|
||||
extern int user_ident_sufficiently_given(void);
|
||||
extern int committer_ident_sufficiently_given(void);
|
||||
extern int author_ident_sufficiently_given(void);
|
||||
|
||||
extern const char *git_commit_encoding;
|
||||
extern const char *git_log_output_encoding;
|
||||
|
|
36
ident.c
36
ident.c
|
@ -10,7 +10,12 @@
|
|||
static struct strbuf git_default_name = STRBUF_INIT;
|
||||
static struct strbuf git_default_email = STRBUF_INIT;
|
||||
static char git_default_date[50];
|
||||
int user_ident_explicitly_given;
|
||||
|
||||
#define IDENT_NAME_GIVEN 01
|
||||
#define IDENT_MAIL_GIVEN 02
|
||||
#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
|
||||
static int committer_ident_explicitly_given;
|
||||
static int author_ident_explicitly_given;
|
||||
|
||||
#ifdef NO_GECOS_IN_PWENT
|
||||
#define get_gecos(ignored) "&"
|
||||
|
@ -109,7 +114,8 @@ const char *ident_default_email(void)
|
|||
|
||||
if (email && email[0]) {
|
||||
strbuf_addstr(&git_default_email, email);
|
||||
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
} else
|
||||
copy_email(xgetpwuid_self(), &git_default_email);
|
||||
strbuf_trim(&git_default_email);
|
||||
|
@ -327,6 +333,10 @@ const char *fmt_name(const char *name, const char *email)
|
|||
|
||||
const char *git_author_info(int flag)
|
||||
{
|
||||
if (getenv("GIT_AUTHOR_NAME"))
|
||||
author_ident_explicitly_given |= IDENT_NAME_GIVEN;
|
||||
if (getenv("GIT_AUTHOR_EMAIL"))
|
||||
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
return fmt_ident(getenv("GIT_AUTHOR_NAME"),
|
||||
getenv("GIT_AUTHOR_EMAIL"),
|
||||
getenv("GIT_AUTHOR_DATE"),
|
||||
|
@ -336,16 +346,16 @@ const char *git_author_info(int flag)
|
|||
const char *git_committer_info(int flag)
|
||||
{
|
||||
if (getenv("GIT_COMMITTER_NAME"))
|
||||
user_ident_explicitly_given |= IDENT_NAME_GIVEN;
|
||||
committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
|
||||
if (getenv("GIT_COMMITTER_EMAIL"))
|
||||
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
|
||||
getenv("GIT_COMMITTER_EMAIL"),
|
||||
getenv("GIT_COMMITTER_DATE"),
|
||||
flag);
|
||||
}
|
||||
|
||||
int user_ident_sufficiently_given(void)
|
||||
static int ident_is_sufficient(int user_ident_explicitly_given)
|
||||
{
|
||||
#ifndef WINDOWS
|
||||
return (user_ident_explicitly_given & IDENT_MAIL_GIVEN);
|
||||
|
@ -354,6 +364,16 @@ int user_ident_sufficiently_given(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
int committer_ident_sufficiently_given(void)
|
||||
{
|
||||
return ident_is_sufficient(committer_ident_explicitly_given);
|
||||
}
|
||||
|
||||
int author_ident_sufficiently_given(void)
|
||||
{
|
||||
return ident_is_sufficient(author_ident_explicitly_given);
|
||||
}
|
||||
|
||||
int git_ident_config(const char *var, const char *value, void *data)
|
||||
{
|
||||
if (!strcmp(var, "user.name")) {
|
||||
|
@ -361,7 +381,8 @@ int git_ident_config(const char *var, const char *value, void *data)
|
|||
return config_error_nonbool(var);
|
||||
strbuf_reset(&git_default_name);
|
||||
strbuf_addstr(&git_default_name, value);
|
||||
user_ident_explicitly_given |= IDENT_NAME_GIVEN;
|
||||
committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
|
||||
author_ident_explicitly_given |= IDENT_NAME_GIVEN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -370,7 +391,8 @@ int git_ident_config(const char *var, const char *value, void *data)
|
|||
return config_error_nonbool(var);
|
||||
strbuf_reset(&git_default_email);
|
||||
strbuf_addstr(&git_default_email, value);
|
||||
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,38 @@ then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
test_lazy_prereq LAZY_TRUE true
|
||||
havetrue=no
|
||||
test_expect_success LAZY_TRUE 'test runs if lazy prereq is satisfied' '
|
||||
havetrue=yes
|
||||
'
|
||||
donthavetrue=yes
|
||||
test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' '
|
||||
donthavetrue=no
|
||||
'
|
||||
|
||||
if test "$havetrue$donthavetrue" != yesyes
|
||||
then
|
||||
say 'bug in test framework: lazy prerequisites do not work'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
test_lazy_prereq LAZY_FALSE false
|
||||
nothavefalse=no
|
||||
test_expect_success !LAZY_FALSE 'negative lazy prereqs checked' '
|
||||
nothavefalse=yes
|
||||
'
|
||||
havefalse=yes
|
||||
test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' '
|
||||
havefalse=no
|
||||
'
|
||||
|
||||
if test "$nothavefalse$havefalse" != yesyes
|
||||
then
|
||||
say 'bug in test framework: negative lazy prerequisites do not work'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
clean=no
|
||||
test_expect_success 'tests clean up after themselves' '
|
||||
test_when_finished clean=yes
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='basic sanity checks for git var'
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'get GIT_AUTHOR_IDENT' '
|
||||
test_tick &&
|
||||
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
|
||||
git var GIT_AUTHOR_IDENT >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'get GIT_COMMITTER_IDENT' '
|
||||
test_tick &&
|
||||
echo "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" >expect &&
|
||||
git var GIT_COMMITTER_IDENT >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success !AUTOIDENT 'requested identites are strict' '
|
||||
(
|
||||
sane_unset GIT_COMMITTER_NAME &&
|
||||
sane_unset GIT_COMMITTER_EMAIL &&
|
||||
test_must_fail git var GIT_COMMITTER_IDENT
|
||||
)
|
||||
'
|
||||
|
||||
# For git var -l, we check only a representative variable;
|
||||
# testing the whole output would make our test too brittle with
|
||||
# respect to unrelated changes in the test suite's environment.
|
||||
test_expect_success 'git var -l lists variables' '
|
||||
git var -l >actual &&
|
||||
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
|
||||
sed -n s/GIT_AUTHOR_IDENT=//p <actual >actual.author &&
|
||||
test_cmp expect actual.author
|
||||
'
|
||||
|
||||
test_expect_success 'git var -l lists config' '
|
||||
git var -l >actual &&
|
||||
echo false >expect &&
|
||||
sed -n s/core\\.bare=//p <actual >actual.bare &&
|
||||
test_cmp expect actual.bare
|
||||
'
|
||||
|
||||
test_expect_success 'listing and asking for variables are exclusive' '
|
||||
test_must_fail git var -l GIT_COMMITTER_IDENT
|
||||
'
|
||||
|
||||
test_done
|
|
@ -243,16 +243,6 @@ test_expect_success 'message shows author when it is not equal to committer' '
|
|||
.git/COMMIT_EDITMSG
|
||||
'
|
||||
|
||||
test_expect_success 'setup auto-ident prerequisite' '
|
||||
if (sane_unset GIT_COMMITTER_EMAIL &&
|
||||
sane_unset GIT_COMMITTER_NAME &&
|
||||
git var GIT_COMMITTER_IDENT); then
|
||||
test_set_prereq AUTOIDENT
|
||||
else
|
||||
test_set_prereq NOAUTOIDENT
|
||||
fi
|
||||
'
|
||||
|
||||
test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
|
||||
|
||||
echo >>negative &&
|
||||
|
@ -271,7 +261,7 @@ echo editor started > "$(pwd)/.git/result"
|
|||
exit 0
|
||||
EOF
|
||||
|
||||
test_expect_success NOAUTOIDENT 'do not fire editor when committer is bogus' '
|
||||
test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
|
||||
>.git/result
|
||||
>expect &&
|
||||
|
||||
|
|
|
@ -201,6 +201,34 @@ test_expect_success $PREREQ 'Prompting works' '
|
|||
grep "^To: to@example.com\$" msgtxt1
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
|
||||
clean_fake_sendmail &&
|
||||
(sane_unset GIT_AUTHOR_NAME &&
|
||||
sane_unset GIT_AUTHOR_EMAIL &&
|
||||
sane_unset GIT_COMMITTER_NAME &&
|
||||
sane_unset GIT_COMMITTER_EMAIL &&
|
||||
GIT_SEND_EMAIL_NOTTY=1 git send-email \
|
||||
--smtp-server="$(pwd)/fake.sendmail" \
|
||||
--to=to@example.com \
|
||||
$patches </dev/null 2>errors
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
|
||||
clean_fake_sendmail &&
|
||||
(sane_unset GIT_AUTHOR_NAME &&
|
||||
sane_unset GIT_AUTHOR_EMAIL &&
|
||||
sane_unset GIT_COMMITTER_NAME &&
|
||||
sane_unset GIT_COMMITTER_EMAIL &&
|
||||
GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
|
||||
test_must_fail git send-email \
|
||||
--smtp-server="$(pwd)/fake.sendmail" \
|
||||
--to=to@example.com \
|
||||
$patches </dev/null 2>errors &&
|
||||
test_i18ngrep "tell me who you are" errors
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ 'tocmd works' '
|
||||
clean_fake_sendmail &&
|
||||
cp $patches tocmd.patch &&
|
||||
|
|
|
@ -275,6 +275,15 @@ test_have_prereq () {
|
|||
|
||||
for prerequisite
|
||||
do
|
||||
case "$prerequisite" in
|
||||
!*)
|
||||
negative_prereq=t
|
||||
prerequisite=${prerequisite#!}
|
||||
;;
|
||||
*)
|
||||
negative_prereq=
|
||||
esac
|
||||
|
||||
case " $lazily_tested_prereq " in
|
||||
*" $prerequisite "*)
|
||||
;;
|
||||
|
@ -294,10 +303,20 @@ test_have_prereq () {
|
|||
total_prereq=$(($total_prereq + 1))
|
||||
case "$satisfied_prereq" in
|
||||
*" $prerequisite "*)
|
||||
satisfied_this_prereq=t
|
||||
;;
|
||||
*)
|
||||
satisfied_this_prereq=
|
||||
esac
|
||||
|
||||
case "$satisfied_this_prereq,$negative_prereq" in
|
||||
t,|,t)
|
||||
ok_prereq=$(($ok_prereq + 1))
|
||||
;;
|
||||
*)
|
||||
# Keep a list of missing prerequisites
|
||||
# Keep a list of missing prerequisites; restore
|
||||
# the negative marker if necessary.
|
||||
prerequisite=${negative_prereq:+!}$prerequisite
|
||||
if test -z "$missing_prereq"
|
||||
then
|
||||
missing_prereq=$prerequisite
|
||||
|
|
|
@ -738,6 +738,12 @@ test_lazy_prereq UTF8_NFD_TO_NFC '
|
|||
esac
|
||||
'
|
||||
|
||||
test_lazy_prereq AUTOIDENT '
|
||||
sane_unset GIT_AUTHOR_NAME &&
|
||||
sane_unset GIT_AUTHOR_EMAIL &&
|
||||
git var GIT_AUTHOR_IDENT
|
||||
'
|
||||
|
||||
# When the tests are run as root, permission tests will report that
|
||||
# things are writable when they shouldn't be.
|
||||
test -w / || test_set_prereq SANITY
|
||||
|
|
Загрузка…
Ссылка в новой задаче