corrupt:
free(data);
*status_p = -1;
- error(_("corrupt binary patch at line %d: %.*s"),
- state->linenr-1, llen-1, buffer);
+ error(_("corrupt binary patch at %s:%d: %.*s"),
+ state->patch_input_file, state->linenr-1, llen-1, buffer);
return NULL;
}
forward = parse_binary_hunk(state, &buffer, &size, &status, &used);
if (!forward && !status)
/* there has to be one hunk (forward hunk) */
- return error(_("unrecognized binary patch at line %d"), state->linenr-1);
+ return error(_("unrecognized binary patch at %s:%d"),
+ state->patch_input_file, state->linenr-1);
if (status)
/* otherwise we already gave an error message */
return status;
*/
if ((state->apply || state->check) &&
(!patch->is_binary && !metadata_changes(patch))) {
- error(_("patch with only garbage at line %d"), state->linenr);
+ error(_("patch with only garbage at %s:%d"),
+ state->patch_input_file, state->linenr);
return -128;
}
}
EOF
test_cmp expect err
'
+
+test_expect_success 'applying a patch with only garbage reports the input' '
+ cat >garbage.patch <<-\EOF &&
+ diff --git a/f b/f
+ --- a/f
+ +++ b/f
+ this is garbage
+ EOF
+ test_must_fail git apply garbage.patch 2>err &&
+ echo "error: patch with only garbage at garbage.patch:4" >expect &&
+ test_cmp expect err
+'
test_done
" <patch >patch.trunc &&
do_reset &&
- test_must_fail git apply patch.trunc
+ test_must_fail git apply patch.trunc 2>err &&
+ line=$(awk "END { print NR + 1 }" patch.trunc) &&
+ grep "error: corrupt binary patch at patch.trunc:$line: " err
+'
+
+test_expect_success 'reject unrecognized binary diff' '
+ cat >patch.bad <<-\EOF &&
+ diff --git a/f b/f
+ new file mode 100644
+ index 0000000..7898192
+ GIT binary patch
+ bogus
+ EOF
+ test_must_fail git apply patch.bad 2>err &&
+ cat >expect <<-\EOF &&
+ error: unrecognized binary patch at patch.bad:4
+ error: No valid patches in input (allow with "--allow-empty")
+ EOF
+ test_cmp expect err
'
test_done