pre-commit hook does not echo on terminal
Asked Answered
D

1

6

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?

Damson answered 7/7, 2022 at 9:49 Comment(4)
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?Seddon
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.Seddon
@Seddon it does not work even with sh -x build_script.sh as entry pointDamson
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....Seddon
D
11

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

Daina answered 7/7, 2022 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.