{"thread":{"id":"37707","subject":"bug with partial commit and pre-commit hook updating the index","startedAt":"2014-10-10T17:18:34Z","lastAt":"2014-10-10T21:18:29Z","messageCount":2,"participants":["Joey Hess","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"250486","messageId":"20141010171834.GB21355@kitenet.net","threadId":"37707","inReplyTo":null,"subject":"bug with partial commit and pre-commit hook updating the index","fromName":"Joey Hess","fromEmail":"joey@kitenet.net","sentAt":"2014-10-10T17:18:34Z","receivedAt":"2014-10-10T17:18:34Z","isPatch":false,"sender":{"key":"joey@kitenet.net","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"I have found many uses for the feature that lets a pre-commit hook stage\nchanges in the index that will be included in the commit. But now I seem\nto have found a bug in the support for that, involving partial commits.\n\nIt seems that, after a partial commit in which the pre-commit hook\nstages a modification of a file, the index is is left without that\nstaged change. This only occurs with \"git commit $file\", not \"git commit -a\".\n\njoey@darkstar:~/tmp/a>ls\njoey@darkstar:~/tmp/a>date > foo\njoey@darkstar:~/tmp/a>git add foo\njoey@darkstar:~/tmp/a>git commit -m \"added regular file foo\"\n[master 79d0f1d] added regular file foo\n 1 file changed, 1 insertion(+)\n create mode 100644 foo\njoey@darkstar:~/tmp/a>mv ~/pre-commit  .git/hooks/\njoey@darkstar:~/tmp/a>cat > .git/hooks/pre-commit\n#!/bin/sh\nln -vsf /etc/passwd foo\ngit add foo\njoey@darkstar:~/tmp/a>date > foo\njoey@darkstar:~/tmp/a>git commit foo -m update\n‘foo’ -> ‘/etc/passwd’\n[master efa9f67] update\n 1 file changed, 1 insertion(+), 1 deletion(-)\n rewrite foo (100%)\n mode change 100644 => 120000\n\nSo, the pre-commit hook replaced file foo with a symlink, and staged it,\nand we can see from the commit summary that was correctly included\nin the commit. But, look here:\n\njoey@darkstar:~/tmp/a>git status\nOn branch master\nChanges to be committed:\n  (use \"git reset HEAD <file>...\" to unstage)\n\n\ttypechange: foo\n\nChanges not staged for commit:\n  (use \"git add <file>...\" to update what will be committed)\n  (use \"git checkout -- <file>...\" to discard changes in working directory)\n\n\ttypechange: foo\n\nbuiltin/commit.c has a long comment that talks about a false index which\nis set up and used during a partial commit. The pre-commit hook is run\nusing this false index, and the commit is generated from it. I guess the\nbug involves the real index not being updated afterwards to reflect the\nchanges made to the false index.\n\n-- \nsee shy jo, resending a mail that vger accepted yesterday but has still \n            not posted\n"},{"id":"250492","messageId":"xmqqy4sn4o9m.fsf@gitster.dls.corp.google.com","threadId":"37707","inReplyTo":"20141010171834.GB21355@kitenet.net","subject":"Re: bug with partial commit and pre-commit hook updating the index","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-10-10T21:18:29Z","receivedAt":"2014-10-10T21:18:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joey Hess <joey@kitenet.net> writes:\n\n> I have found many uses for the feature that lets a pre-commit hook stage\n> changes in the index that will be included in the commit. But now I seem\n> to have found a bug in the support for that, involving partial commits.\n>\n> It seems that, after a partial commit in which the pre-commit hook\n> stages a modification of a file, the index is is left without that\n> staged change. This only occurs with \"git commit $file\", not \"git commit -a\".\n\nAren't pre-* hooks about verifications?  Who told you that you are\nallowed to muck with the index there?\n"}]}