Joey Hess
2014-10-10 17:18:34 UTC
I have found many uses for the feature that lets a pre-commit hook stag=
e
changes in the index that will be included in the commit. But now I see=
m
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 commi=
t -a".
***@darkstar:~/tmp/a>ls
***@darkstar:~/tmp/a>date > foo
***@darkstar:~/tmp/a>git add foo
***@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
***@darkstar:~/tmp/a>mv ~/pre-commit .git/hooks/
***@darkstar:~/tmp/a>cat > .git/hooks/pre-commit
#!/bin/sh
ln -vsf /etc/passwd foo
git add foo
***@darkstar:~/tmp/a>date > foo
***@darkstar:~/tmp/a>git commit foo -m update
=E2=80=98foo=E2=80=99 -> =E2=80=98/etc/passwd=E2=80=99
[master efa9f67] update
1 file changed, 1 insertion(+), 1 deletion(-)
rewrite foo (100%)
mode change 100644 =3D> 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:
***@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 direct=
ory)
typechange: foo
builtin/commit.c has a long comment that talks about a false index whic=
h
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 th=
e
bug involves the real index not being updated afterwards to reflect the
changes made to the false index.
--=20
see shy jo, resending a mail that vger accepted yesterday but has still=
=20
not posted
e
changes in the index that will be included in the commit. But now I see=
m
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 commi=
t -a".
***@darkstar:~/tmp/a>ls
***@darkstar:~/tmp/a>date > foo
***@darkstar:~/tmp/a>git add foo
***@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
***@darkstar:~/tmp/a>mv ~/pre-commit .git/hooks/
***@darkstar:~/tmp/a>cat > .git/hooks/pre-commit
#!/bin/sh
ln -vsf /etc/passwd foo
git add foo
***@darkstar:~/tmp/a>date > foo
***@darkstar:~/tmp/a>git commit foo -m update
=E2=80=98foo=E2=80=99 -> =E2=80=98/etc/passwd=E2=80=99
[master efa9f67] update
1 file changed, 1 insertion(+), 1 deletion(-)
rewrite foo (100%)
mode change 100644 =3D> 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:
***@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 direct=
ory)
typechange: foo
builtin/commit.c has a long comment that talks about a false index whic=
h
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 th=
e
bug involves the real index not being updated afterwards to reflect the
changes made to the false index.
--=20
see shy jo, resending a mail that vger accepted yesterday but has still=
=20
not posted