Re: Issue when changing staged files in a pre-commit hook

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 28, 2015 at 7:17 PM, Niek van der Kooy
<niekvanderkooy@xxxxxxxxx> wrote:
> I am having an issue where the default commit message is not changed
> when adding staged files in a pre-commit hook.
> Please see http://stackoverflow.com/questions/34492779/git-update-git-status-part-of-commit-message-after-pre-commit-hook
> for details.

you should probably copy the text here instead of putting a link.
Sometimes I don't bother clicking another link. Make it easy for
people to help you. Long story short, pre-commit hook adds a file,
which ends up in the commit, but is not shown in git-status.

> Is there a workaround / proper way to achieve what I am trying to do,
> or is this a bug?

When you commit something, git may prepare a temporary index that
contains what's to be in the commit, unless you do "git commit"
without -a/-A, or paths... The pre-commit is set up to see this index.
So if you make changes in this index, they will end up in the new
commit. But the index will then be discarded. The main index,
$GIT_DIR/index, may or may not be untouched the whole time. This is
the index that is used by "git status". If you do "git commit" without
-a/-A/paths they "git status" should be consistent because your hook
sees $GIT_DIR/index instead of a temporary one.

I think it's the intended behavior. I believe $GIT_DIR is exported to
your hook, so in theory you could do an extra
"GIT_INDEX_FILE=$GIT_DIR/index git add public" (i.e. you update _two_
index files, one for committing, one for future git commands). But be
careful. It may have unwanted effects. It's probably easier to make an
alias that adds that 'public' file first then commits without hooks.
-- 
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]