Merge branch 'ab/send-email-validate-errors'
Clean-up codepaths that implements "git send-email --validate" option and improves the message from it. * ab/send-email-validate-errors: git-send-email: improve --validate error output git-send-email: refactor duplicate $? checks into a function git-send-email: test full --validate outputmaint
commit
2279289e95
|
|
@ -212,22 +212,31 @@ my $dump_aliases = 0;
|
||||||
my $multiedit;
|
my $multiedit;
|
||||||
my $editor;
|
my $editor;
|
||||||
|
|
||||||
|
sub system_or_msg {
|
||||||
|
my ($args, $msg) = @_;
|
||||||
|
system(@$args);
|
||||||
|
my $signalled = $? & 127;
|
||||||
|
my $exit_code = $? >> 8;
|
||||||
|
return unless $signalled or $exit_code;
|
||||||
|
|
||||||
|
return sprintf(__("fatal: command '%s' died with exit code %d"),
|
||||||
|
$args->[0], $exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub system_or_die {
|
||||||
|
my $msg = system_or_msg(@_);
|
||||||
|
die $msg if $msg;
|
||||||
|
}
|
||||||
|
|
||||||
sub do_edit {
|
sub do_edit {
|
||||||
if (!defined($editor)) {
|
if (!defined($editor)) {
|
||||||
$editor = Git::command_oneline('var', 'GIT_EDITOR');
|
$editor = Git::command_oneline('var', 'GIT_EDITOR');
|
||||||
}
|
}
|
||||||
|
my $die_msg = __("the editor exited uncleanly, aborting everything");
|
||||||
if (defined($multiedit) && !$multiedit) {
|
if (defined($multiedit) && !$multiedit) {
|
||||||
for (@_) {
|
system_or_die(['sh', '-c', $editor.' "$@"', $editor, $_], $die_msg) for @_;
|
||||||
system('sh', '-c', $editor.' "$@"', $editor, $_);
|
|
||||||
if (($? & 127) || ($? >> 8)) {
|
|
||||||
die(__("the editor exited uncleanly, aborting everything"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
system('sh', '-c', $editor.' "$@"', $editor, @_);
|
system_or_die(['sh', '-c', $editor.' "$@"', $editor, @_], $die_msg);
|
||||||
if (($? & 127) || ($? >> 8)) {
|
|
||||||
die(__("the editor exited uncleanly, aborting everything"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -698,9 +707,7 @@ if (@rev_list_opts) {
|
||||||
if ($validate) {
|
if ($validate) {
|
||||||
foreach my $f (@files) {
|
foreach my $f (@files) {
|
||||||
unless (-p $f) {
|
unless (-p $f) {
|
||||||
my $error = validate_patch($f, $target_xfer_encoding);
|
validate_patch($f, $target_xfer_encoding);
|
||||||
$error and die sprintf(__("fatal: %s: %s\nwarning: no patches were sent\n"),
|
|
||||||
$f, $error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1952,11 +1959,14 @@ sub validate_patch {
|
||||||
chdir($repo->wc_path() or $repo->repo_path())
|
chdir($repo->wc_path() or $repo->repo_path())
|
||||||
or die("chdir: $!");
|
or die("chdir: $!");
|
||||||
local $ENV{"GIT_DIR"} = $repo->repo_path();
|
local $ENV{"GIT_DIR"} = $repo->repo_path();
|
||||||
$hook_error = "rejected by sendemail-validate hook"
|
$hook_error = system_or_msg([$validate_hook, $target]);
|
||||||
if system($validate_hook, $target);
|
|
||||||
chdir($cwd_save) or die("chdir: $!");
|
chdir($cwd_save) or die("chdir: $!");
|
||||||
}
|
}
|
||||||
return $hook_error if $hook_error;
|
if ($hook_error) {
|
||||||
|
die sprintf(__("fatal: %s: rejected by sendemail-validate hook\n" .
|
||||||
|
"%s\n" .
|
||||||
|
"warning: no patches were sent\n"), $fn, $hook_error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Any long lines will be automatically fixed if we use a suitable transfer
|
# Any long lines will be automatically fixed if we use a suitable transfer
|
||||||
|
|
@ -1966,7 +1976,8 @@ sub validate_patch {
|
||||||
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
|
or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
|
||||||
while (my $line = <$fh>) {
|
while (my $line = <$fh>) {
|
||||||
if (length($line) > 998) {
|
if (length($line) > 998) {
|
||||||
return sprintf(__("%s: patch contains a line longer than 998 characters"), $.);
|
die sprintf(__("fatal: %s:%d is longer than 998 characters\n" .
|
||||||
|
"warning: no patches were sent\n"), $fn, $.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -415,15 +415,23 @@ test_expect_success $PREREQ 'reject long lines' '
|
||||||
z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
|
z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
|
||||||
clean_fake_sendmail &&
|
clean_fake_sendmail &&
|
||||||
cp $patches longline.patch &&
|
cp $patches longline.patch &&
|
||||||
echo $z512$z512 >>longline.patch &&
|
cat >>longline.patch <<-EOF &&
|
||||||
|
$z512$z512
|
||||||
|
not a long line
|
||||||
|
$z512$z512
|
||||||
|
EOF
|
||||||
test_must_fail git send-email \
|
test_must_fail git send-email \
|
||||||
--from="Example <nobody@example.com>" \
|
--from="Example <nobody@example.com>" \
|
||||||
--to=nobody@example.com \
|
--to=nobody@example.com \
|
||||||
--smtp-server="$(pwd)/fake.sendmail" \
|
--smtp-server="$(pwd)/fake.sendmail" \
|
||||||
--transfer-encoding=8bit \
|
--transfer-encoding=8bit \
|
||||||
$patches longline.patch \
|
$patches longline.patch \
|
||||||
2>errors &&
|
2>actual &&
|
||||||
grep longline.patch errors
|
cat >expect <<-\EOF &&
|
||||||
|
fatal: longline.patch:35 is longer than 998 characters
|
||||||
|
warning: no patches were sent
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success $PREREQ 'no patch was sent' '
|
test_expect_success $PREREQ 'no patch was sent' '
|
||||||
|
|
@ -527,22 +535,33 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
|
||||||
--to=nobody@example.com \
|
--to=nobody@example.com \
|
||||||
--smtp-server="$(pwd)/fake.sendmail" \
|
--smtp-server="$(pwd)/fake.sendmail" \
|
||||||
--validate \
|
--validate \
|
||||||
longline.patch 2>err &&
|
longline.patch 2>actual &&
|
||||||
test_path_is_file my-hooks.ran &&
|
test_path_is_file my-hooks.ran &&
|
||||||
grep "rejected by sendemail-validate" err
|
cat >expect <<-EOF &&
|
||||||
|
fatal: longline.patch: rejected by sendemail-validate hook
|
||||||
|
fatal: command '"'"'$(pwd)/my-hooks/sendemail-validate'"'"' died with exit code 1
|
||||||
|
warning: no patches were sent
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
|
test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
|
||||||
test_config core.hooksPath "$(pwd)/my-hooks" &&
|
hooks_path="$(pwd)/my-hooks" &&
|
||||||
|
test_config core.hooksPath "$hooks_path" &&
|
||||||
test_when_finished "rm my-hooks.ran" &&
|
test_when_finished "rm my-hooks.ran" &&
|
||||||
test_must_fail git send-email \
|
test_must_fail git send-email \
|
||||||
--from="Example <nobody@example.com>" \
|
--from="Example <nobody@example.com>" \
|
||||||
--to=nobody@example.com \
|
--to=nobody@example.com \
|
||||||
--smtp-server="$(pwd)/fake.sendmail" \
|
--smtp-server="$(pwd)/fake.sendmail" \
|
||||||
--validate \
|
--validate \
|
||||||
longline.patch 2>err &&
|
longline.patch 2>actual &&
|
||||||
test_path_is_file my-hooks.ran &&
|
test_path_is_file my-hooks.ran &&
|
||||||
grep "rejected by sendemail-validate" err
|
cat >expect <<-EOF &&
|
||||||
|
fatal: longline.patch: rejected by sendemail-validate hook
|
||||||
|
fatal: command '"'"'$hooks_path/sendemail-validate'"'"' died with exit code 1
|
||||||
|
warning: no patches were sent
|
||||||
|
EOF
|
||||||
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
for enc in 7bit 8bit quoted-printable base64
|
for enc in 7bit 8bit quoted-printable base64
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue