All of lore.kernel.org
 help / color / mirror / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Niek van der Kooy <niekvanderkooy@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: Issue when changing staged files in a pre-commit hook
Date: Tue, 19 Jan 2016 19:20:36 +0700	[thread overview]
Message-ID: <CACsJy8DhiYiie7+Cw3PkPJpSX7CGp-r2Mu98mLp4OMhhGdsXgQ@mail.gmail.com> (raw)
In-Reply-To: <CAPYEnzGfnRbajDQAwBTNE5XSaB0WbHKbf1heRV0bUgbq5w_A5g@mail.gmail.com>

On Mon, Dec 28, 2015 at 7:17 PM, Niek van der Kooy
<niekvanderkooy@gmail.com> 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

  parent reply	other threads:[~2016-01-19 12:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-28 12:17 Issue when changing staged files in a pre-commit hook Niek van der Kooy
2016-01-19 11:53 ` Niek van der Kooy
2016-01-19 12:20 ` Duy Nguyen [this message]
2016-01-19 18:44   ` Junio C Hamano
2016-01-19 23:26     ` Duy Nguyen
2016-01-19 23:41       ` Junio C Hamano
2016-01-20  0:23         ` Duy Nguyen
2016-01-20  1:44           ` Junio C Hamano
2016-01-22  8:58             ` Duy Nguyen

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=CACsJy8DhiYiie7+Cw3PkPJpSX7CGp-r2Mu98mLp4OMhhGdsXgQ@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=niekvanderkooy@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.