Re: Issue when changing staged files in a pre-commit hook

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 20, 2016 at 6:41 AM, Junio C Hamano <gitster@xxxxxxxxx> wrote:
> Duy Nguyen <pclouds@xxxxxxxxx> writes:
>
>> On Wed, Jan 20, 2016 at 1:44 AM, Junio C Hamano <gitster@xxxxxxxxx> wrote:
>>> Duy Nguyen <pclouds@xxxxxxxxx> 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.

OK. Two more points

 - do we catch index changes for partial commit case only? Because
when $GIT_DIR/index is used, we do not have this problem.

 - is Niek's use case still valid? If so, what do we do to support it
(at least in partial commit case)?
-- 
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]