Skip to content

Commit ea7811b

Browse files
avargitster
authored andcommitted
git-send-email: improve --validate error output
Improve the output we emit on --validate error to: * Say "FILE:LINE" instead of "FILE: LINE", to match "grep -n", compiler error messages etc. * Don't say "patch contains a" after just mentioning the filename, just leave it at "FILE:LINE: is longer than[...]. The "contains a" sounded like we were talking about the file in general, when we're actually checking it line-by-line. * Don't just say "rejected by sendemail-validate hook", but combine that with the system_or_msg() output to say what exit code the hook died with. I had an aborted attempt to make the line length checker note all lines that were longer than the limit. I didn't think that was worth the effort, but I've left in the testing change to check that we die as soon as we spot the first long line. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d21616c commit ea7811b

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

git-send-email.perl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ sub system_or_msg {
219219
my $exit_code = $? >> 8;
220220
return unless $signalled or $exit_code;
221221

222-
return sprintf(__("failed to run command %s, died with code %d"),
223-
"@$args", $exit_code);
222+
return sprintf(__("fatal: command '%s' died with exit code %d"),
223+
$args->[0], $exit_code);
224224
}
225225

226226
sub system_or_die {
@@ -1964,7 +1964,8 @@ sub validate_patch {
19641964
}
19651965
if ($hook_error) {
19661966
die sprintf(__("fatal: %s: rejected by sendemail-validate hook\n" .
1967-
"warning: no patches were sent\n"), $fn);
1967+
"%s\n" .
1968+
"warning: no patches were sent\n"), $fn, $hook_error);
19681969
}
19691970
}
19701971

@@ -1975,9 +1976,8 @@ sub validate_patch {
19751976
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
19761977
while (my $line = <$fh>) {
19771978
if (length($line) > 998) {
1978-
die sprintf(__("fatal: %s: %d: patch contains a line longer than 998 characters\n" .
1979-
"warning: no patches were sent\n"),
1980-
$fn, $.);
1979+
die sprintf(__("fatal: %s:%d is longer than 998 characters\n" .
1980+
"warning: no patches were sent\n"), $fn, $.);
19811981
}
19821982
}
19831983
}

t/t9001-send-email.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,11 @@ test_expect_success $PREREQ 'reject long lines' '
415415
z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
416416
clean_fake_sendmail &&
417417
cp $patches longline.patch &&
418-
echo $z512$z512 >>longline.patch &&
418+
cat >>longline.patch <<-EOF &&
419+
$z512$z512
420+
not a long line
421+
$z512$z512
422+
EOF
419423
test_must_fail git send-email \
420424
--from="Example <[email protected]>" \
421425
@@ -424,7 +428,7 @@ test_expect_success $PREREQ 'reject long lines' '
424428
$patches longline.patch \
425429
2>actual &&
426430
cat >expect <<-\EOF &&
427-
fatal: longline.patch: 35: patch contains a line longer than 998 characters
431+
fatal: longline.patch:35 is longer than 998 characters
428432
warning: no patches were sent
429433
EOF
430434
test_cmp expect actual
@@ -533,15 +537,17 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
533537
--validate \
534538
longline.patch 2>actual &&
535539
test_path_is_file my-hooks.ran &&
536-
cat >expect <<-\EOF &&
540+
cat >expect <<-EOF &&
537541
fatal: longline.patch: rejected by sendemail-validate hook
542+
fatal: command '"'"'$(pwd)/my-hooks/sendemail-validate'"'"' died with exit code 1
538543
warning: no patches were sent
539544
EOF
540545
test_cmp expect actual
541546
'
542547

543548
test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
544-
test_config core.hooksPath "$(pwd)/my-hooks" &&
549+
hooks_path="$(pwd)/my-hooks" &&
550+
test_config core.hooksPath "$hooks_path" &&
545551
test_when_finished "rm my-hooks.ran" &&
546552
test_must_fail git send-email \
547553
--from="Example <[email protected]>" \
@@ -550,8 +556,9 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
550556
--validate \
551557
longline.patch 2>actual &&
552558
test_path_is_file my-hooks.ran &&
553-
cat >expect <<-\EOF &&
559+
cat >expect <<-EOF &&
554560
fatal: longline.patch: rejected by sendemail-validate hook
561+
fatal: command '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1
555562
warning: no patches were sent
556563
EOF
557564
test_cmp expect actual

0 commit comments

Comments
 (0)