Skip to content

[Feature Request] Pass arguments to --pre command #2046

@toonn

Description

@toonn

Describe your feature request

I'm writing a Git pre-commit hook that should prevent me from committing certain sections I have marked DO NOT COMMIT.

I would like to do something like the following because I only want to grep the parts of files that have been staged:

rg -Fl --pre 'git diff --cached -- $1'  'DO NOT COMMIT'

However, the --pre argument only supports either commands found on the PATH or an absolute path to a file. Right now I'm working around this by using an absolute path to a script, ~/src/repo/.git/hooks/git-diff-cached.sh, but this is a very inelegant approach. It requires me to hardcode the repo's path in the hook. If I want to use this hook in multiple repos I have to either update that path every time or put the script in one central location.

I've attempted to use process substitution, rg -Fl --pre <(printf 'git diff --cached -- $1') 'DO NOT COMMIT' but named pipes are created without execute permission.

Hence, my feature request. Would it be possible to add a flag specifying arguments to be passed to the preprocessing command or having a separate --pre-script flag we can pass a string to rather than a file?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docAn issue with or an improvement to documentation.rollupA PR that has been merged with many others in a rollup.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions