3

I am trying to run a script with pre-commit hook. Here is my script:

build_script.sh

 #! /bin/bash
 echo "Stage 1: Preparing CMake configuration"

.pre-commit-config.yaml

fail_fast: false
  - repo: local
    hooks:
    -   id: Generate build 
        name: Generate build 
        entry: sh build_script.sh
        language: system
        always_run: true
        pass_filenames: false

I can see when I run command git commit -m "message", the hook calls the script and Generate build will Pass. However, I do not see the echo on the terminal. I would like to see the message, "Stage 1: Preparing CMake configuration". What is wrong with this setup?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
SNR_BT
  • 133
  • 5
  • Strange. Seems the hook framework was catching the stdout. Just for debugging: You also don't see any output if you configure the _entry_ as `sh -x build_script.sh`? – user1934428 Jul 07 '22 at 11:00
  • BTW (not important here, just for completeness): You are tagging this question by _bash_, but you don't run your script as bash. Bear this in mind if you want to use one day bash-specific features. – user1934428 Jul 07 '22 at 11:01
  • @user1934428 it does not work even with `sh -x build_script.sh` as entry point – SNR_BT Jul 07 '22 at 12:37
  • This means that the trace produced by `-x` also does not show up? This is IMO strange design of pre-commit, because stderr is usually used to signal an error, and I find it odd that pre-commit hides stderr as well.... – user1934428 Jul 08 '22 at 05:35

1 Answers1

4

pre-commit takes a bit from unix philosophy here -- it is silent unless there is a problem (by default).

if your script fails then the output will be displayed

you can also use --verbose to show the full output (for debugging) and optionally set verbose: true on your hook itself. note: these are both debugging options and are not intended for use outside that -- we've found that when hooks are noisy contributors tend to ignore all of the output


disclaimer: I wrote pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207