{"thread":{"id":"48616","subject":"is there a reason pre-commit.sample uses \"git diff-index\"?","startedAt":"2018-05-31T16:40:50Z","lastAt":"2018-06-01T02:23:55Z","messageCount":8,"participants":["Robert P. J. Day","Duy Nguyen","Johannes Sixt","Stefan Beller","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"348905","messageId":"alpine.LFD.2.21.1805311235410.15130@localhost.localdomain","threadId":"48616","inReplyTo":null,"subject":"is there a reason pre-commit.sample uses \"git diff-index\"?","fromName":"Robert P. J. Day","fromEmail":"rpjday@crashcourse.ca","sentAt":"2018-05-31T16:38:46Z","receivedAt":"2018-05-31T16:40:50Z","isPatch":false,"sender":{"key":"rpjday@crashcourse.ca","avatar":"https://avatars.githubusercontent.com/u/226084077?v=4"},"body":"\n  was going over some hooks and writing some tutorials for some of the\ncommit-related, client-side hooks, and was wondering (perhaps\nstupidly) why the pre-commit.sample hook uses, as its last line:\n\n  exec git diff-index --check --cached $against --\n           ^^^^^^^^^^\n\nas in, could this not be done equivalently with just git diff, not git\ndiff-index? i just did a quick test and it seems to do the same thing,\nbut i've never taken a close look at git diff-index before so i may\njust be clueless about some important distinction.\n\nrday\n\n-- \n\n========================================================================\nRobert P. J. Day                                 Ottawa, Ontario, CANADA\n                  http://crashcourse.ca/dokuwiki\n\nTwitter:                                       http://twitter.com/rpjday\nLinkedIn:                               http://ca.linkedin.com/in/rpjday\n========================================================================\n"},{"id":"348906","messageId":"CACsJy8CP=1_bHAzs+mveaJvbOOzr9vny-2xz6kM4cEcCYWmOOw@mail.gmail.com","threadId":"48616","inReplyTo":"alpine.LFD.2.21.1805311235410.15130@localhost.localdomain","subject":"Re: is there a reason pre-commit.sample uses \"git diff-index\"?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-31T17:05:34Z","receivedAt":"2018-05-31T17:06:09Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, May 31, 2018 at 6:38 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:\n>\n>   was going over some hooks and writing some tutorials for some of the\n> commit-related, client-side hooks, and was wondering (perhaps\n> stupidly) why the pre-commit.sample hook uses, as its last line:\n>\n>   exec git diff-index --check --cached $against --\n>            ^^^^^^^^^^\n>\n> as in, could this not be done equivalently with just git diff, not git\n> diff-index? i just did a quick test and it seems to do the same thing,\n> but i've never taken a close look at git diff-index before so i may\n> just be clueless about some important distinction.\n\ngit diff-index is \"plumbing\", designed for writing scripts. \"git diff\"\non the other hand is for users and its behavior may change even if it\nbreaks backward compatibility.\n-- \nDuy\n"},{"id":"348907","messageId":"alpine.LFD.2.21.1805311323220.17047@localhost.localdomain","threadId":"48616","inReplyTo":"CACsJy8CP=1_bHAzs+mveaJvbOOzr9vny-2xz6kM4cEcCYWmOOw@mail.gmail.com","subject":"Re: is there a reason pre-commit.sample uses \"git diff-index\"?","fromName":"Robert P. J. Day","fromEmail":"rpjday@crashcourse.ca","sentAt":"2018-05-31T17:27:20Z","receivedAt":"2018-05-31T17:29:24Z","isPatch":false,"sender":{"key":"rpjday@crashcourse.ca","avatar":"https://avatars.githubusercontent.com/u/226084077?v=4"},"body":"On Thu, 31 May 2018, Duy Nguyen wrote:\n\n> On Thu, May 31, 2018 at 6:38 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:\n> >\n> >   was going over some hooks and writing some tutorials for some of\n> > the commit-related, client-side hooks, and was wondering (perhaps\n> > stupidly) why the pre-commit.sample hook uses, as its last line:\n> >\n> >   exec git diff-index --check --cached $against --\n> >            ^^^^^^^^^^\n> >\n> > as in, could this not be done equivalently with just git diff, not\n> > git diff-index? i just did a quick test and it seems to do the\n> > same thing, but i've never taken a close look at git diff-index\n> > before so i may just be clueless about some important distinction.\n>\n> git diff-index is \"plumbing\", designed for writing scripts. \"git\n> diff\" on the other hand is for users and its behavior may change\n> even if it breaks backward compatibility.\n\n  ah, this was a philosophical underpinning i was unaware of. i see\noccasional explanations of git porcelain versus plumbing, but i don't\nrecall anyone simply stating that the plumbing is meant to have a\nlong-term stability that is not guaranteed for the porcelain.\n\n  in any event, this does mean that, stability issues aside, \"git\ndiff\" would apparently have worked just fine for that hook.\n\nrday\n\n-- \n\n========================================================================\nRobert P. J. Day                                 Ottawa, Ontario, CANADA\n                  http://crashcourse.ca/dokuwiki\n\nTwitter:                                       http://twitter.com/rpjday\nLinkedIn:                               http://ca.linkedin.com/in/rpjday\n========================================================================\n"},{"id":"348915","messageId":"CACsJy8Do6iqvv=XvOu4YoD07t0OjckrpvNeF+XnH__w2+a=Big@mail.gmail.com","threadId":"48616","inReplyTo":"alpine.LFD.2.21.1805311323220.17047@localhost.localdomain","subject":"Re: is there a reason pre-commit.sample uses \"git diff-index\"?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-31T17:41:42Z","receivedAt":"2018-05-31T17:42:20Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, May 31, 2018 at 7:27 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:\n> On Thu, 31 May 2018, Duy Nguyen wrote:\n>\n>> On Thu, May 31, 2018 at 6:38 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:\n>> >\n>> >   was going over some hooks and writing some tutorials for some of\n>> > the commit-related, client-side hooks, and was wondering (perhaps\n>> > stupidly) why the pre-commit.sample hook uses, as its last line:\n>> >\n>> >   exec git diff-index --check --cached $against --\n>> >            ^^^^^^^^^^\n>> >\n>> > as in, could this not be done equivalently with just git diff, not\n>> > git diff-index? i just did a quick test and it seems to do the\n>> > same thing, but i've never taken a close look at git diff-index\n>> > before so i may just be clueless about some important distinction.\n>>\n>> git diff-index is \"plumbing\", designed for writing scripts. \"git\n>> diff\" on the other hand is for users and its behavior may change\n>> even if it breaks backward compatibility.\n>\n>   ah, this was a philosophical underpinning i was unaware of. i see\n> occasional explanations of git porcelain versus plumbing, but i don't\n> recall anyone simply stating that the plumbing is meant to have a\n> long-term stability that is not guaranteed for the porcelain.\n>\n>   in any event, this does mean that, stability issues aside, \"git\n> diff\" would apparently have worked just fine for that hook.\n\nI think there are also stuff like config variables which can change\nporcelain command behavior but usually not plumbing. Command exit code\nmay be another area where porcelain and plumbing differ. But in this\nparticular case, I think \"git diff\" works fine (but still should not\nbe used unless you're just writing a quick throwaway script).\n-- \nDuy\n"},{"id":"348945","messageId":"f27d8344-4acb-3e87-3bd9-b23b21c4b82a@kdbg.org","threadId":"48616","inReplyTo":"alpine.LFD.2.21.1805311323220.17047@localhost.localdomain","subject":"Re: is there a reason pre-commit.sample uses \"git diff-index\"?","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2018-05-31T23:08:36Z","receivedAt":"2018-05-31T23:08:42Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 31.05.2018 um 19:27 schrieb Robert P. J. Day:\n> On Thu, 31 May 2018, Duy Nguyen wrote:\n>> git diff-index is \"plumbing\", designed for writing scripts. \"git\n>> diff\" on the other hand is for users and its behavior may change\n>> even if it breaks backward compatibility.\n> \n>    ah, this was a philosophical underpinning i was unaware of. i see\n> occasional explanations of git porcelain versus plumbing, but i don't\n> recall anyone simply stating that the plumbing is meant to have a\n> long-term stability that is not guaranteed for the porcelain.\n\nSo, there you have it. ;) Plumbing commands offer long-term stability. \nThat is not just philosophical, but practically relevant.\n\n>    in any event, this does mean that, stability issues aside, \"git\n> diff\" would apparently have worked just fine for that hook.\n\nIt may have worked just fine. You should still not use it.\n\nDidn't you say that you are teaching git and hooks? Then you should \nteach the right thing, and the right thing is to use plumbing for scripts.\n\n-- Hannes\n"},{"id":"348946","messageId":"alpine.LFD.2.21.1805311907280.19720@localhost.localdomain","threadId":"48616","inReplyTo":"f27d8344-4acb-3e87-3bd9-b23b21c4b82a@kdbg.org","subject":"Re: is there a reason pre-commit.sample uses \"git diff-index\"?","fromName":"Robert P. J. Day","fromEmail":"rpjday@crashcourse.ca","sentAt":"2018-05-31T23:09:03Z","receivedAt":"2018-05-31T23:11:09Z","isPatch":false,"sender":{"key":"rpjday@crashcourse.ca","avatar":"https://avatars.githubusercontent.com/u/226084077?v=4"},"body":"On Fri, 1 Jun 2018, Johannes Sixt wrote:\n\n> Am 31.05.2018 um 19:27 schrieb Robert P. J. Day:\n> > On Thu, 31 May 2018, Duy Nguyen wrote:\n> >> git diff-index is \"plumbing\", designed for writing scripts. \"git\n> >> diff\" on the other hand is for users and its behavior may change\n> >> even if it breaks backward compatibility.\n> >\n> >    ah, this was a philosophical underpinning i was unaware of. i\n> > see occasional explanations of git porcelain versus plumbing, but\n> > i don't recall anyone simply stating that the plumbing is meant to\n> > have a long-term stability that is not guaranteed for the\n> > porcelain.\n>\n> So, there you have it. ;) Plumbing commands offer long-term\n> stability. That is not just philosophical, but practically relevant.\n>\n> >    in any event, this does mean that, stability issues aside, \"git\n> > diff\" would apparently have worked just fine for that hook.\n>\n> It may have worked just fine. You should still not use it.\n>\n> Didn't you say that you are teaching git and hooks? Then you should\n> teach the right thing, and the right thing is to use plumbing for\n> scripts.\n\n  sure, i agree, but i don't recall *ever* running across the claim\nthat the \"plumbing\" commands had a long-term stability and backward\ncompatibility that the porcelain commands did not. is that mentioned\nanywhere?\n\nrday\n\n-- \n\n========================================================================\nRobert P. J. Day                                 Ottawa, Ontario, CANADA\n                  http://crashcourse.ca/dokuwiki\n\nTwitter:                                       http://twitter.com/rpjday\nLinkedIn:                               http://ca.linkedin.com/in/rpjday\n========================================================================\n"},{"id":"348948","messageId":"CAGZ79kZ9x2OWU+qfZRckZFAdy1KFqttAZqkJwbzsvQfqUokg3A@mail.gmail.com","threadId":"48616","inReplyTo":"alpine.LFD.2.21.1805311907280.19720@localhost.localdomain","subject":"Re: is there a reason pre-commit.sample uses \"git diff-index\"?","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-05-31T23:25:04Z","receivedAt":"2018-05-31T23:25:09Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, May 31, 2018 at 4:09 PM, Robert P. J. Day <rpjday@crashcourse.ca> wrote:\n> On Fri, 1 Jun 2018, Johannes Sixt wrote:\n>\n>> Am 31.05.2018 um 19:27 schrieb Robert P. J. Day:\n>> > On Thu, 31 May 2018, Duy Nguyen wrote:\n>> >> git diff-index is \"plumbing\", designed for writing scripts. \"git\n>> >> diff\" on the other hand is for users and its behavior may change\n>> >> even if it breaks backward compatibility.\n>> >\n>> >    ah, this was a philosophical underpinning i was unaware of. i\n>> > see occasional explanations of git porcelain versus plumbing, but\n>> > i don't recall anyone simply stating that the plumbing is meant to\n>> > have a long-term stability that is not guaranteed for the\n>> > porcelain.\n>>\n>> So, there you have it. ;) Plumbing commands offer long-term\n>> stability. That is not just philosophical, but practically relevant.\n>>\n>> >    in any event, this does mean that, stability issues aside, \"git\n>> > diff\" would apparently have worked just fine for that hook.\n>>\n>> It may have worked just fine. You should still not use it.\n>>\n>> Didn't you say that you are teaching git and hooks? Then you should\n>> teach the right thing, and the right thing is to use plumbing for\n>> scripts.\n>\n>   sure, i agree, but i don't recall *ever* running across the claim\n> that the \"plumbing\" commands had a long-term stability and backward\n> compatibility that the porcelain commands did not. is that mentioned\n> anywhere?\n\n`man git`\n\nLOW-LEVEL COMMANDS (PLUMBING)\n       Although Git includes its own porcelain layer, its low-level commands\n       are sufficient to support development of alternative porcelains.\n       Developers of such porcelains might start by reading about git-update-\n       index(1) and git-read-tree(1).\n\n       The interface (input, output, set of options and the semantics) to\n       these low-level commands are meant to be a lot more stable than\n       Porcelain level commands, because these commands are primarily for\n       scripted use. The interface to Porcelain commands on the other hand are\n       subject to change in order to improve the end user experience.\n\nOne example that Junio seemed to worry about was 940a911f8ec (log:\nif --decorate is not given, default to --decorate=auto, 2017-03-23), as git log\nseems to be used pseudo-plumbing-ly as there is no good and equally powerful\nplumbing command, so the likelihood of git-log calls in scripts out\nthere is high.\n\nSo maybe the community should strive to be more aggressive about\nchanging the porcelain interface for the better.\n\nOne thing that we discussed internally for example is changing the\noutput of the porcelain output of fetch, pull and push to give less\ncryptic output, but rather a one line progress bar (and only show errors\nwhen they occur). I think that would be an improvement, as I don't think\nmany people care about the exact numbers of objects transferred in\na push/fetch, but rather want to have an estimate of the time left for\nexample. Also a one line progress bar might save some precious screen\nreal estate.\n\nStefan\n"},{"id":"348963","messageId":"xmqqh8mn9rd6.fsf@gitster-ct.c.googlers.com","threadId":"48616","inReplyTo":"CAGZ79kZ9x2OWU+qfZRckZFAdy1KFqttAZqkJwbzsvQfqUokg3A@mail.gmail.com","subject":"Re: is there a reason pre-commit.sample uses \"git diff-index\"?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-06-01T02:23:49Z","receivedAt":"2018-06-01T02:23:55Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> plumbing command, so the likelihood of git-log calls in scripts out\n> there is high.\n>\n> So maybe the community should strive to be more aggressive about\n> changing the porcelain interface for the better.\n\nTo me, these two paragraphs are being incoherent.\n\nIf plumbing these days lag behind \"log\" Porcelain and tempt script\nwriters more towards \"log\", we should aggressively reject attempts\nto change the \"log\" Porcelain behaviour to keep it stable, until a\nsuitable plumbing that scripters can rely on catches up.\n\nOr course, aggressively improving plumbing would be a good solution\nto that problem as well ;-)\n"}]}