public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Jeff King <peff@peff•net>
To: Wesley Schwengle <wesleys@opperschaap•net>
Cc: Git maillinglist <git@vger•kernel.org>
Subject: Re: git hook question
Date: Fri, 29 May 2026 01:21:41 -0400	[thread overview]
Message-ID: <20260529052141.GA1099450@coredump.intra.peff.net> (raw)
In-Reply-To: <cc9fda14-d8e8-4982-9a3d-9aa816c0b90c@opperschaap.net>

On Fri, May 29, 2026 at 01:01:34AM -0400, Wesley Schwengle wrote:

> I understand the why, normally pre-push gets `<local-ref> SP
> <local-object-name> SP <remote-ref> SP <remote-object-name> LF'. This has a
> similar feel, albeit a different syntax. The difference feels like a minor
> bug, but not one I'm worried about at this moment: you would expect it to
> get the same arguments/parameters as the regular pre-push hook. But I
> digress.

I think the "git hook" command is mostly intended for scripting, and the
caller is expected to understand the context and provide the appropriate
arguments. The hook command itself doesn't know about what a "pre-push"
hook should look like.

So not a bug, but definitely a gotcha that could perhaps be better
explained in the documentation.

> My actual question is: Is there a way to tell the hook "Don't give me
> arguments, just run the plain command that is defined". I looked in `man 1
> git-hook', but I was unable to find something that looks like it.

I don't think so; the command is expected to handle (or ignore) the
arguments as appropriate. You could obviously write a wrapper script to
handle that, but since hook commands are run with a shell you can inline
it, like:

  git config hook.npm-test.command 'npm run test #'

Git will paste together the shell command:

  npm run test # "$@"

which then treats everything after the "#" as a comment. The more
general form of this trick is to use a shell function, like:

  f() { your_cmd_here; }; f

which would do what you want, but also let you access the arguments
however you like. For example:

  f() { some_cmd "$1"; another_cmd "$2"; }; f

would let you consider the arguments independently.

But for your purposes, using "#" to ignore them is simpler to write.

-Peff

  reply	other threads:[~2026-05-29  5:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29  5:01 git hook question Wesley Schwengle
2026-05-29  5:21 ` Jeff King [this message]
2026-05-29 16:11   ` Wesley Schwengle
2026-05-29 16:22     ` Wesley
2026-05-29 17:52     ` Ben Knoble
2026-05-29 19:23     ` Jeff King
     [not found]       ` <4d938e1e-fdd3-42d6-a879-4d394ee8c00d@opperschaap.net>
2026-05-29 21:00         ` Jeff King
2026-06-03 13:07           ` Adrian Ratiu
2026-06-01  5:33   ` Junio C Hamano
2026-06-01  5:55     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260529052141.GA1099450@coredump.intra.peff.net \
    --to=peff@peff$(echo .)net \
    --cc=git@vger$(echo .)kernel.org \
    --cc=wesleys@opperschaap$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox