Subject: Re: [PATCH v2] send-email: export patch counters in validate environment

From: Junio C Hamano <[email-masked]>
Date: Wed, 12 Apr 2023 14:48:21 -0700

Junio C Hamano <[email-masked]> writes:

> Overall, a very well crafted patch, even though little details and
> some design choices can be improved.

One thing I forgot to mention.  We probably want some test, perhaps
adding something like the following to t9001 after we already test
for --validate.

Thanks.

----------- >8 ---------------------- >8 ---------------------- >8 -----------
expected_file_counter_output () {
	total=$1
	count=0
	while test $count -ne $total
	do
		count=$((count + 1)) &&
		echo "$count/$total" || return
	done
}

test_expect_success $PREREQ '--validate hook allows counting of messages' '
	test_when_finished "rm my-hooks.log" &&
	test_config core.hooksPath "my-hooks" &&

	write_script my-hooks/sendemail-validate <<-\EOF &&
		num=$GIT_SENDEMAIL_FILE_COUNTER &&
		tot=$GIT_SENDEMAIL_FILE_TOTAL &&
		echo "$num/$tot" >>my-hooks.log || exit 1
	EOF

	>my-hooks.log &&
	expected_file_counter_output 1 >expect &&
	git send-email \
		--from="Example <[email-masked]>" \
		--to=[email-masked] \
		--smtp-server="$(pwd)/fake.sendmail" \
		--validate $patches &&
	test_cmp expect my-hooks.log
'