From: Junio C Hamano <gitster@pobox•com>
To: Duy Nguyen <pclouds@gmail•com>
Cc: Niek van der Kooy <niekvanderkooy@gmail•com>,
Git Mailing List <git@vger•kernel.org>
Subject: Re: Issue when changing staged files in a pre-commit hook
Date: Tue, 19 Jan 2016 15:41:17 -0800 [thread overview]
Message-ID: <xmqqwpr56ste.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <CACsJy8DxQnGV5JZnHuvA1Zbpf2BuGdmMF+YNiq51HNK+8vW56Q@mail.gmail.com> (Duy Nguyen's message of "Wed, 20 Jan 2016 06:26:35 +0700")
Duy Nguyen <pclouds@gmail•com> writes:
> On Wed, Jan 20, 2016 at 1:44 AM, Junio C Hamano <gitster@pobox•com> wrote:
>> Duy Nguyen <pclouds@gmail•com> writes:
>>
>>> I think it's the intended behavior.
>>
>> Yeah, pre-commit was designed for inspecting and rejecting, not for
>> tweaking and munging. Perhaps "git commit" can be tightened to make
>> sure that pre-commit that returns successfully did not muck with the
>> working tree and the index?
>
> That was my impression from the docs, but then I saw this comment,
>
> /*
> * Re-read the index as pre-commit hook could have updated it,
> * and write it out as a tree. We must do this before we invoke
> * the editor and after we invoke run_status above.
> */
>
> which comes from 2888605 (builtin-commit: fix partial-commit support -
> 2007-11-18) that admits "the hook can modify it (the index)". And I
> was about to update the docs, but the other way around, about updating
> index and side effects.
I do not think the comment is wrong per-se, but the code we have,
either back then or even today, is insufficient to allow pre-commit
hook that mucks with the fake index that is shown to it.
Re-reading the in-core index at that point may help creating a
commit whose tree matches what the hook did, but the extra change
made by the hook is not ported forward in the real index that the
user will use after a partial commit (and there is no easy way to do
so cleanly--the change the hook makes may even overlap the change in
the real index that are added but left uncommitted, and you would
end up needing to run a threeway merge).
The only sensible thing we can do at that point in the code after
re-reading the index is to make sure that hasn't been changed by the
pre-commit hook and complain loudly to die if we find it modified, I
think.
next prev parent reply other threads:[~2016-01-19 23:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-28 12:17 Issue when changing staged files in a pre-commit hook Niek van der Kooy
2016-01-19 11:53 ` Niek van der Kooy
2016-01-19 12:20 ` Duy Nguyen
2016-01-19 18:44 ` Junio C Hamano
2016-01-19 23:26 ` Duy Nguyen
2016-01-19 23:41 ` Junio C Hamano [this message]
2016-01-20 0:23 ` Duy Nguyen
2016-01-20 1:44 ` Junio C Hamano
2016-01-22 8:58 ` Duy Nguyen
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=xmqqwpr56ste.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=niekvanderkooy@gmail$(echo .)com \
--cc=pclouds@gmail$(echo .)com \
/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