Skip to contentSkip to conversation

Bug#469250: Commit f5bbc322 to git broke pre-commit hooks which read stdin

DISCUSSION David Bremner 7 participants 14 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

It looks like line 435 of builtin-commit.c disables stdin for hooks (with the disclaimer that I first looked at the git source ten minutes ago).

hook.no_stdin = 1

I'm not sure if this was by design, but just so you know, this breaks people's hooks. In particular the default metastore pre-commit hook no longer works. I didn't find anything relevant in the docs [1].

David

[1]: http://www.kernel.org/pub/software/scm/git/docs/hooks.html

#1 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Hi,

Quoted 9 lines · David Bremner

It looks like line 435 of builtin-commit.c disables stdin for hooks (with the disclaimer that I first looked at the git source ten minutes ago).

hook.no_stdin = 1

I'm not sure if this was by design, but just so you know, this breaks people's hooks. In particular the default metastore pre-commit hook no longer works. I didn't find anything relevant in the docs [1].

Pardon my ignorance, but what business has metastore reading stdin? There should be nothing coming in, so the change you mentioned should be correct, and your hook relies on something it should not rely on.

Ciao,
Dscho

#2 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Quoted 10 lines · Johannes Schindelin

Hi,

Quoted 6 lines · David Bremner

It looks like line 435 of builtin-commit.c disables stdin for hooks (with the disclaimer that I first looked at the git source ten minutes ago).

hook.no_stdin = 1

Quoted 7 lines
Quoted 3 lines

I'm not sure if this was by design, but just so you know, this breaks people's hooks. In particular the default metastore pre-commit hook no longer works. I didn't find anything relevant in the docs [1].

Pardon my ignorance, but what business has metastore reading stdin? There should be nothing coming in, so the change you mentioned should be correct, and your hook relies on something it should not rely on.

It is not metastore. It is an interactive hook that reads from the user who is sitting on the terminal and invoked the git-commit program.

#3 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Junio" == Junio C Hamano <[email protected]> writes:

Junio> Johannes Schindelin <[email protected]> writes:

>> Pardon my ignorance, but what business has metastore reading >> stdin? There should be nothing coming in, so the change you >> mentioned should be correct, and your hook relies on something >> it should not rely on.

Junio> It is not metastore. It is an interactive hook that reads Junio> from the user who is sitting on the terminal and invoked Junio> the git-commit program.

Yeah, I should have been more explicit. The problem is a line

read -N1 VAR

This used to work, and now it doesn't. Maybe there are good reasons for change in git, I don't know. I'm just reporting that something broke. And asking nicely that what hooks can and can not depend on be documented somewhere to avoid future problems of this type.

All the best,

David

P.S. I removed [email protected] from CC; I'm not sure Debian BTS needs all of the discussion. Feel free to put it back if you disagree.

#4 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Hi,

Quoted 9 lines · David Bremner
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Junio" == Junio C Hamano <[email protected]> writes:

Junio> Johannes Schindelin <[email protected]> writes:

>> Pardon my ignorance, but what business has metastore reading >> stdin? There should be nothing coming in, so the change you >> mentioned should be correct, and your hook relies on something >> it should not rely on.

Quoted 7 lines

Junio> It is not metastore. It is an interactive hook that reads Junio> from the user who is sitting on the terminal and invoked Junio> the git-commit program.

Yeah, I should have been more explicit. The problem is a line

read -N1 VAR

Can you be even more explicit? IOW why does this have to be a pre-commit hook, and cannot be done before calling git-commit itself?

Ciao,
Dscho

#5 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Johannes" == Johannes Schindelin <[email protected]> writes:

Tue, 4 Mar 2008, David Bremner wrote:

Yeah, I should have been more explicit. The problem is a line

read -N1 VAR

Johannes> Can you be even more explicit? IOW why does this have Johannes> to be a pre-commit hook, and cannot be done before Johannes> calling git-commit itself?

I have this feeling I don't really understand the question. Yes, in principle, whatever I am doing in a pre-commit hook could be done by hand first. I guess it is primarily a user interface issue. The goal is modify the behaviour of git-commit in a particular repository; isn't this the purpose of pre-commit hooks?

All the best,

David

#6 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Quoted 12 lines · David Bremner
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Johannes" == Johannes Schindelin <[email protected]> writes:

Tue, 4 Mar 2008, David Bremner wrote:

Yeah, I should have been more explicit. The problem is a line

read -N1 VAR

Johannes> Can you be even more explicit? IOW why does this have Johannes> to be a pre-commit hook, and cannot be done before Johannes> calling git-commit itself?

Quoted 5 lines

I have this feeling I don't really understand the question. Yes, in principle, whatever I am doing in a pre-commit hook could be done by hand first. I guess it is primarily a user interface issue. The goal is modify the behaviour of git-commit in a particular repository; isn't this the purpose of pre-commit hooks?

What happens to such hooks under git-gui?

git-gui invokes the pre-commit hook with stdin coming off the stdin that the wish process inherited when it was spawned. This may not be the best way to interact with the end-user of that repository.

Signature · 1 line
Shawn.
#7 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Quoted 5 lines · Shawn O. Pearce

What happens to such hooks under git-gui?

git-gui invokes the pre-commit hook with stdin coming off the stdin that the wish process inherited when it was spawned. This may not be the best way to interact with the end-user of that repository.

Well, if git-gui is designed to interoperate with CLI git (and I think that is a sensible thing to aim for), we probably should revisit the list of hooks in hooks.txt and make sure we define the environment these hooks are invoked in precisely enough (this incidentally will help C rewrite effort to avoid regressing). Then, hooks that take input from and give output to the user could be launched with I/O redirected to talk with wish (which I presume has a terminal lookalike widget you can embed in your application).

#8 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Shawn O. Pearce

What happens to such hooks under git-gui?

git-gui invokes the pre-commit hook with stdin coming off the stdin that the wish process inherited when it was spawned. This may not be the best way to interact with the end-user of that repository.

Quoted 5 lines

Well, if git-gui is designed to interoperate with CLI git (and I think that is a sensible thing to aim for), we probably should revisit the list of hooks in hooks.txt and make sure we define the environment these hooks are invoked in precisely enough (this incidentally will help C rewrite effort to avoid regressing).

Yup. That I think is key, because then hook authors know what they can assume, and what they cannot.

Quoted 4 lines

Then, hooks that take input from and give
output to the user could be launched with I/O redirected to talk with wish (which I presume has a terminal lookalike widget you can embed in your application).

Nope. In fact the one that I already have right now is not dealing with the \r in the progress meters from git correctly. Someone needs to revisit that code. Something's not right with it.

Oh, and the one that git-gui does have only handles output. It does not permit input. Nor does it actually honor weird stty modes like say noecho. Its most decidely *not* a tty.

Signature · 1 line
Shawn.
#9 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

In reply to Johannes Schindelin
Quoted 2 lines · Johannes Schindelin

Can you be even more explicit? IOW why does this have to be a pre-commit hook, and cannot be done before calling git-commit itself?

metastore adds a .metadata file that contains information (permissions, owners, etc) not normally tracked with git. The pre-commit hook updates the metadata just before committing, to ensure that the metadata included in the commit is consistent with the rest of the commit. You could do it by hand, but that would be an extra step that would have to be rememebered every time.

There's no particular reason for the pre-commit hook to interactively prompt before updating the metadata. I suspect it prompts only because it's an example.

Signature · 1 line
see shy jo
#10 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

In reply to Junio C Hamano
Quoted 12 lines · Junio C Hamano
Quoted 11 lines · Johannes Schindelin
Quoted 9 lines · David Bremner

It looks like line 435 of builtin-commit.c disables stdin for hooks (with the disclaimer that I first looked at the git source ten minutes ago).

hook.no_stdin = 1

I'm not sure if this was by design, but just so you know, this breaks people's hooks. In particular the default metastore pre-commit hook no longer works. I didn't find anything relevant in the docs [1].

Quoted 6 lines
Quoted 3 lines

Pardon my ignorance, but what business has metastore reading stdin? There should be nothing coming in, so the change you mentioned should be correct, and your hook relies on something it should not rely on.

It is not metastore. It is an interactive hook that reads from the user who is sitting on the terminal and invoked the git-commit program.

Are you saying stdin should not be directed to /dev/null, or that an interactive hook is required to do

    exec < /dev/tty || { echo 2>&1 "not interactive"; exit 1; }

before it reads from stdin?

-- Hannes

#11 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Quoted 9 lines · Johannes Sixt
Quoted 2 lines

It is not metastore. It is an interactive hook that reads from the user who is sitting on the terminal and invoked the git-commit program.

Are you saying stdin should not be directed to /dev/null, or that an interactive hook is required to do

    exec < /dev/tty || { echo 2>&1 "not interactive"; exit 1; }

before it reads from stdin?

I am saying that scripted version left the stdin as-is but somehow we ended up spawning with .no_stdin = 1 in the C-rewrite, which is a change in established behaviour. It is often called a regression, unless the change has a very good reason. And I tend to think this particular one falls into the former.

We should audit how the hooks are called from various commands re-implemented, comparing the environment the scripted version used to give them, which includes:

- what directory the hook is run in;
- what environment variables are exported to it;
- what temporary files are visible to them for inspection;
- in what order they are run;
- which file descriptor is connected to what;

I think we already caught some of the environment and ordering issues in commit and checkout, but I am far from confident to say that what we have behave identically to the scripted version.

#12 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

In reply to Johannes Schindelin
Quoted 8 lines · Johannes Schindelin
Quoted 6 lines · David Bremner

It looks like line 435 of builtin-commit.c disables stdin for hooks (with the disclaimer that I first looked at the git source ten minutes ago).

hook.no_stdin = 1

Quoted 7 lines
Quoted 3 lines

I'm not sure if this was by design, but just so you know, this breaks people's hooks. In particular the default metastore pre-commit hook no longer works. I didn't find anything relevant in the docs [1].

Pardon my ignorance, but what business has metastore reading stdin? There should be nothing coming in, so the change you mentioned should be correct, and your hook relies on something it should not rely on.

Never mind pre-commit. What about pre-receive and post-receive hooks, both of which gets data on stdin?

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#13 lore raw

Re: Commit f5bbc322 to git broke pre-commit hooks which read stdin

Hi,

Quoted 11 lines · Jakub Narebski
Quoted 7 lines · Johannes Schindelin
Quoted 5 lines · David Bremner

It looks like line 435 of builtin-commit.c disables stdin for hooks (with the disclaimer that I first looked at the git source ten minutes ago).

hook.no_stdin = 1

Never mind pre-commit. What about pre-receive and post-receive hooks, both of which gets data on stdin?

He was talking about builtin-commit.c. AFAIR there is no code to call pre-receive or post-receive in that file. ;-)

IOW the issue does not apply to the hooks you mentioned.

Ciao,
Dscho