Skip to content

Feature request: fork stdin when calling .config/husky/init.sh #1591

@simon-abbott

Description

@simon-abbott

As a workaround for #171 / #1572 I have made the following .config/husky/init.sh script:

#!/bin/zsh

set -e

# Get the path to the hooks directory
hook_dir="$(git config --global core.hooksPath || echo '')"

if [[ -z "$hook_name" ]]; then
  hook_name="$(basename "$0")"
fi

# Get the path to the hook in question
hook_path="$hook_dir/$hook_name"

# If the hook is executable, run it
if [[ -x "$hook_path" ]]; then
  readonly running_husky_hook_path="$(readlink -f $0)"
  export running_husky_hook_path;
  "$hook_path" "$@"
fi

This allows specifying a global core.hooksPath and will call those scripts before running the local ones. This worked great right up until I wanted to have dual pre-push scripts. The pre-push script reads from stdin, so when trying to do both a global pre-push and a local one, the global one would consume stdin before the local copy gets a chance to run. Then, when it gets back to the local execution it fails to read anything from the now-empty stdin, and thus fails.

It would be great if the main husky script would duplicate the stdin when calling the init.sh script. That way we could truly have multiple hooks run cleanly.

I would also be happy with an official solution for #171 / #1572 instead, but it would likely end up basically being what I have listed above (which you are free to use!) and thus would still suffer from the same stdin issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions