summaryrefslogtreecommitdiffstats
path: root/t/t1800-hook.sh (follow)
Commit message (Collapse)AuthorAgeFilesLines
* run-command: report exec error even on ENOENTRené Scharfe2023-06-121-1/+1
| | | | | | | | | | | | | | | | | If execve(2) fails with ENOENT and we report the error, we use the format "cannot run %s", followed by the actual error message. For other errors we use "cannot exec '%s'". Stop making this subtle distinction and use the second format for all execve(2) errors. This simplifies the code and makes the prefix more precise by indicating the failed operation. It also allows us to slightly simplify t1800.16. On Windows -- which lacks execve(2) -- we already use a single format in all cases: "cannot spawn %s". Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* t1800: loosen matching of error message for bad shebangRené Scharfe2023-06-121-15/+5
| | | | | | | | | | | | | | | | | | | t1800.16 checks whether an attempt to run a hook script with a missing executable in its #! line fails and reports that error. The expected error message differs between platforms. The test handles two common variants, but on NonStop OS we get a third one: "fatal: cannot exec 'bad-hooks/test-hook': ...", which causes the test to fail there. We don't really care about the specific message text all that much here. Use grep and a single regex with alternations to ascertain that we get an error message (fatal or otherwise) about the failed invocation of the hook, but don't bother checking if we get the right variant for the platform the test is running on or whether quoting is done. This looser check let's the test pass on NonStop OS. Reported-by: Randall S. Becker <randall.becker@nexbridge.ca> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* hook: support a --to-stdin=<path> optionEmily Shaffer2023-02-081-0/+18
| | | | | | | | | | | | | | | | | Expose the "path_to_stdin" API added in the preceding commit in the "git hook run" command. For now we won't be using this command interface outside of the tests, but exposing this functionality makes it easier to test the hook API. The plan is to use this to extend the "sendemail-validate" hook[1][2]. 1. https://lore.kernel.org/git/ad152e25-4061-9955-d3e6-a2c8b1bd24e7@amd.com 2. https://lore.kernel.org/git/20230120012459.920932-1-michael.strawbridge@amd.com Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* hook tests: fix redirection logic error in 96e7225b310Ævar Arnfjörð Bjarmason2022-10-311-1/+1
| | | | | | | | | | | | | The tests added in 96e7225b310 (hook: add 'run' subcommand, 2021-12-22) were redirecting to "actual" both in the body of the hook itself and in the testing code below. The net result was that the "2>>actual" redirection later in the test wasn't doing anything. Let's have those redirection do what it looks like they're doing. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
* t1800: correct test to handle CygwinAdam Dinwoodie2022-09-151-3/+3
| | | | | | | | | | | | | | On Cygwin, when failing to spawn a process using start_command, Git outputs the same error as on Linux systems, rather than using the GIT_WINDOWS_NATIVE-specific error output. The WINDOWS test prerequisite is set in both Cygwin and native Windows environments, which means it's not appropriate to use to anticipate the error output from start_command. Instead, use the MINGW test prerequisite, which is only set for Git in native Windows environments, and not for Cygwin. Signed-off-by: Adam Dinwoodie <adam@dinwoodie.org> Helped-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* hook API: don't segfault on strbuf_addf() to NULL "out"Ævar Arnfjörð Bjarmason2022-08-051-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix a logic error in a082345372e (hook API: fix v2.36.0 regression: hooks should be connected to a TTY, 2022-06-07). When it started using the "ungroup" API added in fd3aaf53f71 (run-command: add an "ungroup" option to run_process_parallel(), 2022-06-07) it should have made the same sort of change that fd3aaf53f71 itself made in "t/helper/test-run-command.c". The correct way to emit this "Couldn't start" output with "ungroup" would be: fprintf(stderr, _("Couldn't start hook '%s'\n"), hook_path); But we should instead remove the emitting of this output. As the added test shows we already emit output when we can't run the child. The "cannot run" output here is emitted by run-command.c's child_err_spew(). So the addition of the "Couldn't start hook" output here in 96e7225b310 (hook: add 'run' subcommand, 2021-12-22) was always redundant. For the pre-commit hook we'll now emit exactly the same output as we did before f443246b9f2 (commit: convert {pre-commit,prepare-commit-msg} hook to hook.h, 2021-12-22) (and likewise for others). We could at this point add this to the pick_next_hook() callbacks in hook.c: assert(!out); assert(!*pp_task_cb); And this to notify_start_failure() and notify_hook_finished() (in the latter case the parameter is called "pp_task_cp"): assert(!out); assert(!pp_task_cb); But let's leave any such instrumentation for some eventual cleanup of the "ungroup" API. Reported-by: Ilya K <me@0upti.me> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> Reviewed-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* hook API: fix v2.36.0 regression: hooks should be connected to a TTYÆvar Arnfjörð Bjarmason2022-06-071-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix a regression reported[1] against f443246b9f2 (commit: convert {pre-commit,prepare-commit-msg} hook to hook.h, 2021-12-22): Due to using the run_process_parallel() API in the earlier 96e7225b310 (hook: add 'run' subcommand, 2021-12-22) we'd capture the hook's stderr and stdout, and thus lose the connection to the TTY in the case of e.g. the "pre-commit" hook. As a preceding commit notes GNU parallel's similar --ungroup option also has it emit output faster. While we're unlikely to have hooks that emit truly massive amounts of output (or where the performance thereof matters) it's still informative to measure the overhead. In a similar "seq" test we're now ~30% faster: $ cat .git/hooks/seq-hook; git hyperfine -L rev origin/master,HEAD~0 -s 'make CFLAGS=-O3' './git hook run seq-hook' #!/bin/sh seq 100000000 Benchmark 1: ./git hook run seq-hook' in 'origin/master Time (mean ± σ): 787.1 ms ± 13.6 ms [User: 701.6 ms, System: 534.4 ms] Range (min … max): 773.2 ms … 806.3 ms 10 runs Benchmark 2: ./git hook run seq-hook' in 'HEAD~0 Time (mean ± σ): 603.4 ms ± 1.6 ms [User: 573.1 ms, System: 30.3 ms] Range (min … max): 601.0 ms … 606.2 ms 10 runs Summary './git hook run seq-hook' in 'HEAD~0' ran 1.30 ± 0.02 times faster than './git hook run seq-hook' in 'origin/master' 1. https://lore.kernel.org/git/CA+dzEBn108QoMA28f0nC8K21XT+Afua0V2Qv8XkR8rAeqUCCZw@mail.gmail.com/ Reported-by: Anthony Sottile <asottile@umich.edu> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> [jc: minor fix-up to tests for consistency] Signed-off-by: Junio C Hamano <gitster@pobox.com>
* hook tests: turn exit code assertions into a loopÆvar Arnfjörð Bjarmason2022-03-171-25/+10
| | | | | | | | | Amend a test added in 96e7225b310 (hook: add 'run' subcommand, 2021-12-22) to use a for-loop instead of a copy/pasting the same test for the four exit codes we test. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test-lib-functions: add and use a "test_hook" wrapperÆvar Arnfjörð Bjarmason2022-03-171-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a "test_hook" wrapper similar to the existing "test_config" wrapper added in d960c47a881 (test-lib: add helper functions for config, 2011-08-17). This wrapper: - Will clean up the hook with "test_when_finished", unless --setup is provided. - Will error if we clobber a hook, unless --clobber is provided. - Takes a name like "update" instead of ".git/hooks/update". - Accepts -C <dir>, like "test_config" and "test_commit". By using a wrapper we'll be able to easily change all the hook-related code that assumes that the template-created ".git/hooks" directory is created by "init", "clone" etc. once another topic follows-up and changes the test suite to stop creating trash directories using those templates. In addition this will make it easy to have the hooks configured using the "configuration-based hooks" topic, once we get around to integrating that. I.e. we'll be able to run the tests in a mode where we sometimes create a .git/hooks/<name>, and other times create a script in another location, and point the relevant configuration snippet to it. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* git hook run: add an --ignore-missing flagÆvar Arnfjörð Bjarmason2022-01-081-0/+5
| | | | | | | | | | | | | For certain one-shot hooks we'd like to optimistically run them, and not complain if they don't exist. This was already supported by the underlying hook.c library, but had not been exposed via "git hook run". The command version of this will be used by send-email in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* hook: add 'run' subcommandEmily Shaffer2022-01-081-0/+129
In order to enable hooks to be run as an external process, by a standalone Git command, or by tools which wrap Git, provide an external means to run all configured hook commands for a given hook event. Most of our hooks require more complex functionality than this, but let's start with the bare minimum required to support our simplest hooks. In terms of implementation the usage_with_options() and "goto usage" pattern here mirrors that of builtin/{commit-graph,multi-pack-index}.c. Some of the implementation here, such as a function being named run_hooks_opt() when it's tasked with running one hook, to using the run_processes_parallel_tr2() API to run with jobs=1 is somewhere between a bit odd and and an overkill for the current features of this "hook run" command and the hook.[ch] API. This code will eventually be able to run multiple hooks declared in config in parallel, by starting out with these names and APIs we reduce the later churn of renaming functions, switching from the run_command() to run_processes_parallel_tr2() API etc. Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>