git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Hinrik Örn Sigurðsson" <hinrik.sig@gmail.com>
To: git@vger.kernel.org
Subject: COMMIT_EDITMSG not updated after pre-commit hook
Date: Sun, 3 May 2009 23:20:04 +0000	[thread overview]
Message-ID: <6e4c323b0905031620m48769dbdp52684d6b470ebea3@mail.gmail.com> (raw)

I have a pre-commit hook which extracts documentation from file $foo
if it has pending changes to be committed. The hook creates/updates
the documentation file and calls "git add" on it.

When I do "git commit", the COMMIT_EDITMSG delivered to my editor
notes that this documentation file has been created/updated, but not
that its changes have been added to the index. However, if I go ahead
with the commit, I can see that the doc file changes were indeed
committed.

Here is a simplified test case:

$ cat .git/hooks/pre-commit
#!/usr/bin/env perl
use strict;
use warnings;

my $old = qx"git rev-parse HEAD:foo 2>/dev/null";
my $new = qx"git rev-parse :foo 2>/dev/null";

if (($? >> 8) != 0 || $old ne $new) {
    system "cat source > dest";
    system "git add dest";
}

$ ls
source

$ echo 123 >> source

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   source
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git commit -a
Test commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   source
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       dest
[master 535ed7f] Test commit
 2 files changed, 3 insertions(+), 0 deletions(-)
 create mode 100644 dest

$ git status
# On branch master
nothing to commit (working directory clean)

             reply	other threads:[~2009-05-03 23:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-03 23:20 Hinrik Örn Sigurðsson [this message]
2010-08-18 13:54 ` [RFC/PATCH] commit: update the index after running the pre-commit hook Ævar Arnfjörð Bjarmason
2010-08-18 20:30   ` Junio C Hamano
2010-08-18 22:51   ` Jonathan Nieder

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=6e4c323b0905031620m48769dbdp52684d6b470ebea3@mail.gmail.com \
    --to=hinrik.sig@gmail.com \
    --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).