git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joey Hess <joey@kitenet.net>
To: git@vger.kernel.org
Subject: bug with partial commit and pre-commit hook updating the index
Date: Fri, 10 Oct 2014 13:18:34 -0400	[thread overview]
Message-ID: <20141010171834.GB21355@kitenet.net> (raw)

I have found many uses for the feature that lets a pre-commit hook stage
changes in the index that will be included in the commit. But now I seem
to have found a bug in the support for that, involving partial commits.

It seems that, after a partial commit in which the pre-commit hook
stages a modification of a file, the index is is left without that
staged change. This only occurs with "git commit $file", not "git commit -a".

joey@darkstar:~/tmp/a>ls
joey@darkstar:~/tmp/a>date > foo
joey@darkstar:~/tmp/a>git add foo
joey@darkstar:~/tmp/a>git commit -m "added regular file foo"
[master 79d0f1d] added regular file foo
 1 file changed, 1 insertion(+)
 create mode 100644 foo
joey@darkstar:~/tmp/a>mv ~/pre-commit  .git/hooks/
joey@darkstar:~/tmp/a>cat > .git/hooks/pre-commit
#!/bin/sh
ln -vsf /etc/passwd foo
git add foo
joey@darkstar:~/tmp/a>date > foo
joey@darkstar:~/tmp/a>git commit foo -m update
‘foo’ -> ‘/etc/passwd’
[master efa9f67] update
 1 file changed, 1 insertion(+), 1 deletion(-)
 rewrite foo (100%)
 mode change 100644 => 120000

So, the pre-commit hook replaced file foo with a symlink, and staged it,
and we can see from the commit summary that was correctly included
in the commit. But, look here:

joey@darkstar:~/tmp/a>git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	typechange: foo

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	typechange: foo

builtin/commit.c has a long comment that talks about a false index which
is set up and used during a partial commit. The pre-commit hook is run
using this false index, and the commit is generated from it. I guess the
bug involves the real index not being updated afterwards to reflect the
changes made to the false index.

-- 
see shy jo, resending a mail that vger accepted yesterday but has still 
            not posted

             reply	other threads:[~2014-10-10 17:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 17:18 Joey Hess [this message]
2014-10-10 21:18 ` bug with partial commit and pre-commit hook updating the index Junio C Hamano

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=20141010171834.GB21355@kitenet.net \
    --to=joey@kitenet.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).