Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tests: check error message from run_command

In git versions starting at v1.7.5-rc0~29^2 until v1.7.5-rc3~2 (Revert
"run-command: prettify -D_FORTIFY_SOURCE workaround", 2011-04-18)
fixed it, the run_command facility would write a truncated error
message when the command is present but cannot be executed for some
other reason.  For example, if I add a 'hello' command to git:

	$ echo 'echo hello' >git-hello
	$ chmod +x git-hello
	$ PATH=.:$PATH git hello

and make it non-executable, this is what I normally get:

	$ chmod -x git-hello
	$ git hello
	fatal: cannot exec 'git-hello': Permission denied

But with the problematic versions, we get disturbing output:

	$ PATH=.:$PATH git hello
	fatal: $

Add some tests to make sure it doesn't happen again.

The hello-script used in these tests uses cat instead of echo because
on Windows the bash spawned by git converts LF to CRLF in text written
by echo while the bash running tests does not, causing the test to
fail if "echo" is used.  Thanks to Hannes for noticing.

Signed-off-by: Jonathan Nieder <>
Improved-by: Johannes Sixt <>
Signed-off-by: Junio C Hamano <>
  • Loading branch information...
commit c0f19bf3b9c42036722396ee26d2c173d6abf761 1 parent 60e199c
@jrn jrn authored gitster committed
Showing with 25 additions and 0 deletions.
  1. +23 −0 t/
  2. +2 −0  test-run-command.c
23 t/
@@ -7,8 +7,31 @@ test_description='Test run command'
. ./
+cat >hello-script <<-EOF
+ cat hello-script
test_expect_success 'start_command reports ENOENT' '
test-run-command start-command-ENOENT ./does-not-exist
+test_expect_success 'run_command can run a command' '
+ cat hello-script > &&
+ chmod +x &&
+ test-run-command run-command ./ >actual 2>err &&
+ test_cmp hello-script actual &&
+ test_cmp empty err
+test_expect_success POSIXPERM 'run_command reports EACCES' '
+ cat hello-script > &&
+ chmod -x &&
+ test_must_fail test-run-command run-command ./ 2>err &&
+ grep "fatal: cannot exec.*" err
2  test-run-command.c
@@ -29,6 +29,8 @@ int main(int argc, char **argv)
fprintf(stderr, "FAIL %s\n", argv[1]);
return 1;
+ if (!strcmp(argv[1], "run-command"))
+ exit(run_command(&proc));
fprintf(stderr, "check usage\n");
return 1;
Please sign in to comment.
Something went wrong with that request. Please try again.