]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t0061-run-command.sh
Merge branch 'sg/t5310-jgit-wants-sha1'
[thirdparty/git.git] / t / t0061-run-command.sh
index c887ed5b45e824d281343196c8781cbb6e85abed..7d599675e35a75637a75ab6bfed19ff7f784a312 100755 (executable)
@@ -11,10 +11,19 @@ cat >hello-script <<-EOF
        #!$SHELL_PATH
        cat hello-script
 EOF
->empty
 
-test_expect_success 'start_command reports ENOENT' '
-       test-tool run-command start-command-ENOENT ./does-not-exist
+test_expect_success MINGW 'subprocess inherits only std handles' '
+       test-tool run-command inherited-handle
+'
+
+test_expect_success 'start_command reports ENOENT (slash)' '
+       test-tool run-command start-command-ENOENT ./does-not-exist 2>err &&
+       test_i18ngrep "\./does-not-exist" err
+'
+
+test_expect_success 'start_command reports ENOENT (no slash)' '
+       test-tool run-command start-command-ENOENT does-not-exist 2>err &&
+       test_i18ngrep "does-not-exist" err
 '
 
 test_expect_success 'run_command can run a command' '
@@ -23,7 +32,23 @@ test_expect_success 'run_command can run a command' '
        test-tool run-command run-command ./hello.sh >actual 2>err &&
 
        test_cmp hello-script actual &&
-       test_cmp empty err
+       test_must_be_empty err
+'
+
+
+test_lazy_prereq RUNS_COMMANDS_FROM_PWD '
+       write_script runs-commands-from-pwd <<-\EOF &&
+       true
+       EOF
+       runs-commands-from-pwd >/dev/null 2>&1
+'
+
+test_expect_success !RUNS_COMMANDS_FROM_PWD 'run_command is restricted to PATH' '
+       write_script should-not-run <<-\EOF &&
+       echo yikes
+       EOF
+       test_must_fail test-tool run-command run-command should-not-run 2>err &&
+       test_i18ngrep "should-not-run" err
 '
 
 test_expect_success !MINGW 'run_command can run a script without a #! line' '
@@ -34,7 +59,7 @@ test_expect_success !MINGW 'run_command can run a script without a #! line' '
        test-tool run-command run-command ./hello >actual 2>err &&
 
        test_cmp hello-script actual &&
-       test_cmp empty err
+       test_must_be_empty err
 '
 
 test_expect_success 'run_command does not try to execute a directory' '
@@ -47,7 +72,7 @@ test_expect_success 'run_command does not try to execute a directory' '
        PATH=$PWD/bin1:$PWD/bin2:$PATH \
                test-tool run-command run-command greet >actual 2>err &&
        test_cmp bin2/greet actual &&
-       test_cmp empty err
+       test_must_be_empty err
 '
 
 test_expect_success POSIXPERM 'run_command passes over non-executable file' '
@@ -64,7 +89,7 @@ test_expect_success POSIXPERM 'run_command passes over non-executable file' '
        PATH=$PWD/bin1:$PWD/bin2:$PATH \
                test-tool run-command run-command greet >actual 2>err &&
        test_cmp bin2/greet actual &&
-       test_cmp empty err
+       test_must_be_empty err
 '
 
 test_expect_success POSIXPERM 'run_command reports EACCES' '
@@ -145,7 +170,8 @@ test_trace () {
        expect="$1"
        shift
        GIT_TRACE=1 test-tool run-command "$@" run-command true 2>&1 >/dev/null | \
-               sed -e 's/.* run_command: //' -e '/trace: .*/d' >actual &&
+               sed -e 's/.* run_command: //' -e '/trace: .*/d' \
+                       -e '/RUNTIME_PREFIX requested/d' >actual &&
        echo "$expect true" >expect &&
        test_cmp expect actual
 }
@@ -178,4 +204,33 @@ test_expect_success 'GIT_TRACE with environment variables' '
        )
 '
 
+test_expect_success MINGW 'verify curlies are quoted properly' '
+       : force the rev-parse through the MSYS2 Bash &&
+       git -c alias.r="!git rev-parse" r -- a{b}c >actual &&
+       cat >expect <<-\EOF &&
+       --
+       a{b}c
+       EOF
+       test_cmp expect actual
+'
+
+test_expect_success MINGW 'can spawn .bat with argv[0] containing spaces' '
+       bat="$TRASH_DIRECTORY/bat with spaces in name.bat" &&
+
+       # Every .bat invocation will log its arguments to file "out"
+       rm -f out &&
+       echo "echo %* >>out" >"$bat" &&
+
+       # Ask git to invoke .bat; clone will fail due to fake SSH helper
+       test_must_fail env GIT_SSH="$bat" git clone myhost:src ssh-clone &&
+
+       # Spawning .bat can fail if there are two quoted cmd.exe arguments.
+       # .bat itself is first (due to spaces in name), so just one more is
+       # needed to verify. GIT_SSH will invoke .bat multiple times:
+       # 1) -G myhost
+       # 2) myhost "git-upload-pack src"
+       # First invocation will always succeed. Test the second one.
+       grep "git-upload-pack" out
+'
+
 test_done