git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: is there a reason pre-commit.sample uses "git diff-index"?

From
Duy Nguyen <pclouds@gmail.com>
Date
May 31, 2018, 17:41 UTC
Message-ID
<CACsJy8Do6iqvv=XvOu4YoD07t0OjckrpvNeF+XnH__w2+a=Big@mail.gmail.com>
In-Reply-To
<alpine.LFD.2.21.1805311323220.17047@localhost.localdomain>
On Thu, May 31, 2018 at 7:27 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:
Show 27 quoted lines
> On Thu, 31 May 2018, Duy Nguyen wrote:
>
>> On Thu, May 31, 2018 at 6:38 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:
>> >
>> >   was going over some hooks and writing some tutorials for some of
>> > the commit-related, client-side hooks, and was wondering (perhaps
>> > stupidly) why the pre-commit.sample hook uses, as its last line:
>> >
>> >   exec git diff-index --check --cached $against --
>> >            ^^^^^^^^^^
>> >
>> > as in, could this not be done equivalently with just git diff, not
>> > git diff-index? i just did a quick test and it seems to do the
>> > same thing, but i've never taken a close look at git diff-index
>> > before so i may just be clueless about some important distinction.
>>
>> git diff-index is "plumbing", designed for writing scripts. "git
>> diff" on the other hand is for users and its behavior may change
>> even if it breaks backward compatibility.
>
>   ah, this was a philosophical underpinning i was unaware of. i see
> occasional explanations of git porcelain versus plumbing, but i don't
> recall anyone simply stating that the plumbing is meant to have a
> long-term stability that is not guaranteed for the porcelain.
>
>   in any event, this does mean that, stability issues aside, "git
> diff" would apparently have worked just fine for that hook.

I think there are also stuff like config variables which can change porcelain command behavior but usually not plumbing. Command exit code may be another area where porcelain and plumbing differ. But in this particular case, I think "git diff" works fine (but still should not be used unless you're just writing a quick throwaway script).

-- 
Duy
Previous: Robert P. J. DayNext: Johannes Sixt
Message 4 of 8 in “is there a reason pre-commit.sample uses "git diff-index"?”
  1. Robert P. J. DayMay 31, 2018
  2. Duy NguyenMay 31, 2018
  3. Robert P. J. DayMay 31, 2018
  4. Duy NguyenMay 31, 2018
  5. Johannes SixtMay 31, 2018
  6. Robert P. J. DayMay 31, 2018
  7. Stefan BellerMay 31, 2018
  8. Junio C HamanoJun 1, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.