Skip to content

Commit 16e6e72

Browse files
committed
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
2 parents 175bd3b + 59defcc commit 16e6e72

File tree

9 files changed

+169
-26
lines changed

9 files changed

+169
-26
lines changed

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
755755
ident_shown++ ? "" : "\n",
756756
author_ident->buf);
757757

758-
if (!user_ident_sufficiently_given())
758+
if (!committer_ident_sufficiently_given())
759759
status_printf_ln(s, GIT_COLOR_NORMAL,
760760
_("%s"
761761
"Committer: %s"),
@@ -1265,7 +1265,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
12651265
strbuf_addstr(&format, "\n Author: ");
12661266
strbuf_addbuf_percentquote(&format, &author_ident);
12671267
}
1268-
if (!user_ident_sufficiently_given()) {
1268+
if (!committer_ident_sufficiently_given()) {
12691269
strbuf_addstr(&format, "\n Committer: ");
12701270
strbuf_addbuf_percentquote(&format, &committer_ident);
12711271
if (advice_implicit_identity) {

cache.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,8 @@ struct config_include_data {
11491149
#define CONFIG_INCLUDE_INIT { 0 }
11501150
extern int git_config_include(const char *name, const char *value, void *data);
11511151

1152-
#define IDENT_NAME_GIVEN 01
1153-
#define IDENT_MAIL_GIVEN 02
1154-
#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
1155-
extern int user_ident_explicitly_given;
1156-
extern int user_ident_sufficiently_given(void);
1152+
extern int committer_ident_sufficiently_given(void);
1153+
extern int author_ident_sufficiently_given(void);
11571154

11581155
extern const char *git_commit_encoding;
11591156
extern const char *git_log_output_encoding;

ident.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
static struct strbuf git_default_name = STRBUF_INIT;
1111
static struct strbuf git_default_email = STRBUF_INIT;
1212
static char git_default_date[50];
13-
int user_ident_explicitly_given;
13+
14+
#define IDENT_NAME_GIVEN 01
15+
#define IDENT_MAIL_GIVEN 02
16+
#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
17+
static int committer_ident_explicitly_given;
18+
static int author_ident_explicitly_given;
1419

1520
#ifdef NO_GECOS_IN_PWENT
1621
#define get_gecos(ignored) "&"
@@ -109,7 +114,8 @@ const char *ident_default_email(void)
109114

110115
if (email && email[0]) {
111116
strbuf_addstr(&git_default_email, email);
112-
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
117+
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
118+
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
113119
} else
114120
copy_email(xgetpwuid_self(), &git_default_email);
115121
strbuf_trim(&git_default_email);
@@ -327,6 +333,10 @@ const char *fmt_name(const char *name, const char *email)
327333

328334
const char *git_author_info(int flag)
329335
{
336+
if (getenv("GIT_AUTHOR_NAME"))
337+
author_ident_explicitly_given |= IDENT_NAME_GIVEN;
338+
if (getenv("GIT_AUTHOR_EMAIL"))
339+
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
330340
return fmt_ident(getenv("GIT_AUTHOR_NAME"),
331341
getenv("GIT_AUTHOR_EMAIL"),
332342
getenv("GIT_AUTHOR_DATE"),
@@ -336,16 +346,16 @@ const char *git_author_info(int flag)
336346
const char *git_committer_info(int flag)
337347
{
338348
if (getenv("GIT_COMMITTER_NAME"))
339-
user_ident_explicitly_given |= IDENT_NAME_GIVEN;
349+
committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
340350
if (getenv("GIT_COMMITTER_EMAIL"))
341-
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
351+
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
342352
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
343353
getenv("GIT_COMMITTER_EMAIL"),
344354
getenv("GIT_COMMITTER_DATE"),
345355
flag);
346356
}
347357

348-
int user_ident_sufficiently_given(void)
358+
static int ident_is_sufficient(int user_ident_explicitly_given)
349359
{
350360
#ifndef WINDOWS
351361
return (user_ident_explicitly_given & IDENT_MAIL_GIVEN);
@@ -354,14 +364,25 @@ int user_ident_sufficiently_given(void)
354364
#endif
355365
}
356366

367+
int committer_ident_sufficiently_given(void)
368+
{
369+
return ident_is_sufficient(committer_ident_explicitly_given);
370+
}
371+
372+
int author_ident_sufficiently_given(void)
373+
{
374+
return ident_is_sufficient(author_ident_explicitly_given);
375+
}
376+
357377
int git_ident_config(const char *var, const char *value, void *data)
358378
{
359379
if (!strcmp(var, "user.name")) {
360380
if (!value)
361381
return config_error_nonbool(var);
362382
strbuf_reset(&git_default_name);
363383
strbuf_addstr(&git_default_name, value);
364-
user_ident_explicitly_given |= IDENT_NAME_GIVEN;
384+
committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
385+
author_ident_explicitly_given |= IDENT_NAME_GIVEN;
365386
return 0;
366387
}
367388

@@ -370,7 +391,8 @@ int git_ident_config(const char *var, const char *value, void *data)
370391
return config_error_nonbool(var);
371392
strbuf_reset(&git_default_email);
372393
strbuf_addstr(&git_default_email, value);
373-
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
394+
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
395+
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
374396
return 0;
375397
}
376398

t/t0000-basic.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,38 @@ then
115115
exit 1
116116
fi
117117

118+
test_lazy_prereq LAZY_TRUE true
119+
havetrue=no
120+
test_expect_success LAZY_TRUE 'test runs if lazy prereq is satisfied' '
121+
havetrue=yes
122+
'
123+
donthavetrue=yes
124+
test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' '
125+
donthavetrue=no
126+
'
127+
128+
if test "$havetrue$donthavetrue" != yesyes
129+
then
130+
say 'bug in test framework: lazy prerequisites do not work'
131+
exit 1
132+
fi
133+
134+
test_lazy_prereq LAZY_FALSE false
135+
nothavefalse=no
136+
test_expect_success !LAZY_FALSE 'negative lazy prereqs checked' '
137+
nothavefalse=yes
138+
'
139+
havefalse=yes
140+
test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' '
141+
havefalse=no
142+
'
143+
144+
if test "$nothavefalse$havefalse" != yesyes
145+
then
146+
say 'bug in test framework: negative lazy prerequisites do not work'
147+
exit 1
148+
fi
149+
118150
clean=no
119151
test_expect_success 'tests clean up after themselves' '
120152
test_when_finished clean=yes

t/t0007-git-var.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
test_description='basic sanity checks for git var'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'get GIT_AUTHOR_IDENT' '
7+
test_tick &&
8+
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
9+
git var GIT_AUTHOR_IDENT >actual &&
10+
test_cmp expect actual
11+
'
12+
13+
test_expect_success 'get GIT_COMMITTER_IDENT' '
14+
test_tick &&
15+
echo "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" >expect &&
16+
git var GIT_COMMITTER_IDENT >actual &&
17+
test_cmp expect actual
18+
'
19+
20+
test_expect_success !AUTOIDENT 'requested identites are strict' '
21+
(
22+
sane_unset GIT_COMMITTER_NAME &&
23+
sane_unset GIT_COMMITTER_EMAIL &&
24+
test_must_fail git var GIT_COMMITTER_IDENT
25+
)
26+
'
27+
28+
# For git var -l, we check only a representative variable;
29+
# testing the whole output would make our test too brittle with
30+
# respect to unrelated changes in the test suite's environment.
31+
test_expect_success 'git var -l lists variables' '
32+
git var -l >actual &&
33+
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
34+
sed -n s/GIT_AUTHOR_IDENT=//p <actual >actual.author &&
35+
test_cmp expect actual.author
36+
'
37+
38+
test_expect_success 'git var -l lists config' '
39+
git var -l >actual &&
40+
echo false >expect &&
41+
sed -n s/core\\.bare=//p <actual >actual.bare &&
42+
test_cmp expect actual.bare
43+
'
44+
45+
test_expect_success 'listing and asking for variables are exclusive' '
46+
test_must_fail git var -l GIT_COMMITTER_IDENT
47+
'
48+
49+
test_done

t/t7502-commit.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,6 @@ test_expect_success 'message shows author when it is not equal to committer' '
243243
.git/COMMIT_EDITMSG
244244
'
245245

246-
test_expect_success 'setup auto-ident prerequisite' '
247-
if (sane_unset GIT_COMMITTER_EMAIL &&
248-
sane_unset GIT_COMMITTER_NAME &&
249-
git var GIT_COMMITTER_IDENT); then
250-
test_set_prereq AUTOIDENT
251-
else
252-
test_set_prereq NOAUTOIDENT
253-
fi
254-
'
255-
256246
test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
257247
258248
echo >>negative &&
@@ -271,7 +261,7 @@ echo editor started > "$(pwd)/.git/result"
271261
exit 0
272262
EOF
273263

274-
test_expect_success NOAUTOIDENT 'do not fire editor when committer is bogus' '
264+
test_expect_success !AUTOIDENT 'do not fire editor when committer is bogus' '
275265
>.git/result
276266
>expect &&
277267

t/t9001-send-email.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,34 @@ test_expect_success $PREREQ 'Prompting works' '
201201
grep "^To: [email protected]\$" msgtxt1
202202
'
203203

204+
test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
205+
clean_fake_sendmail &&
206+
(sane_unset GIT_AUTHOR_NAME &&
207+
sane_unset GIT_AUTHOR_EMAIL &&
208+
sane_unset GIT_COMMITTER_NAME &&
209+
sane_unset GIT_COMMITTER_EMAIL &&
210+
GIT_SEND_EMAIL_NOTTY=1 git send-email \
211+
--smtp-server="$(pwd)/fake.sendmail" \
212+
213+
$patches </dev/null 2>errors
214+
)
215+
'
216+
217+
test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
218+
clean_fake_sendmail &&
219+
(sane_unset GIT_AUTHOR_NAME &&
220+
sane_unset GIT_AUTHOR_EMAIL &&
221+
sane_unset GIT_COMMITTER_NAME &&
222+
sane_unset GIT_COMMITTER_EMAIL &&
223+
GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
224+
test_must_fail git send-email \
225+
--smtp-server="$(pwd)/fake.sendmail" \
226+
227+
$patches </dev/null 2>errors &&
228+
test_i18ngrep "tell me who you are" errors
229+
)
230+
'
231+
204232
test_expect_success $PREREQ 'tocmd works' '
205233
clean_fake_sendmail &&
206234
cp $patches tocmd.patch &&

t/test-lib-functions.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ test_have_prereq () {
275275

276276
for prerequisite
277277
do
278+
case "$prerequisite" in
279+
!*)
280+
negative_prereq=t
281+
prerequisite=${prerequisite#!}
282+
;;
283+
*)
284+
negative_prereq=
285+
esac
286+
278287
case " $lazily_tested_prereq " in
279288
*" $prerequisite "*)
280289
;;
@@ -294,10 +303,20 @@ test_have_prereq () {
294303
total_prereq=$(($total_prereq + 1))
295304
case "$satisfied_prereq" in
296305
*" $prerequisite "*)
306+
satisfied_this_prereq=t
307+
;;
308+
*)
309+
satisfied_this_prereq=
310+
esac
311+
312+
case "$satisfied_this_prereq,$negative_prereq" in
313+
t,|,t)
297314
ok_prereq=$(($ok_prereq + 1))
298315
;;
299316
*)
300-
# Keep a list of missing prerequisites
317+
# Keep a list of missing prerequisites; restore
318+
# the negative marker if necessary.
319+
prerequisite=${negative_prereq:+!}$prerequisite
301320
if test -z "$missing_prereq"
302321
then
303322
missing_prereq=$prerequisite

t/test-lib.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,12 @@ test_lazy_prereq UTF8_NFD_TO_NFC '
738738
esac
739739
'
740740

741+
test_lazy_prereq AUTOIDENT '
742+
sane_unset GIT_AUTHOR_NAME &&
743+
sane_unset GIT_AUTHOR_EMAIL &&
744+
git var GIT_AUTHOR_IDENT
745+
'
746+
741747
# When the tests are run as root, permission tests will report that
742748
# things are writable when they shouldn't be.
743749
test -w / || test_set_prereq SANITY

0 commit comments

Comments
 (0)