git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wincent Colaiuta <win@wincent.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, krh@redhat.com, Wincent Colaiuta <win@wincent.com>
Subject: [PATCH 3/3] Fix commit-msg hook to allow editing
Date: Sat,  8 Dec 2007 12:38:09 +0100	[thread overview]
Message-ID: <1197113889-16243-4-git-send-email-win@wincent.com> (raw)
In-Reply-To: <1197113889-16243-3-git-send-email-win@wincent.com>

The old git-commit.sh script allowed the commit-msg hook to not only
prevent a commit from proceding, but also to edit the commit message
on the fly and allow it to proceed. So here we teach builtin-commit
to do the same.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
---
 builtin-commit.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index df9377e..a6223d2 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -787,14 +787,18 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		const char *env[2] = { index, NULL };
 		snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
 		launch_editor(git_path(commit_editmsg), &sb, env);
-	} else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
-		rollback_index_files();
-		die("could not read commit message");
 	}
-	if (!no_verify &&
-	    run_hook(index_file, "commit-msg", git_path(commit_editmsg))) {
+	if (!no_verify) {
+		if (run_hook(index_file, "commit-msg", git_path(commit_editmsg))) {
+			rollback_index_files();
+			exit(1);
+		}
+		strbuf_setlen(&sb, header_len);
+	}
+	if ((no_edit || !no_verify) &&
+	    strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
 		rollback_index_files();
-		exit(1);
+		die("could not read commit message");
 	}
 
 	/* Truncate the message just before the diff, if any. */
-- 
1.5.3.7.1115.gaa595

  reply	other threads:[~2007-12-08 11:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-08 11:38 [PATCH 0/3] builtin-commit fixes Wincent Colaiuta
2007-12-08 11:38 ` [PATCH 1/3] Allow --no-verify to bypass commit-msg hook Wincent Colaiuta
2007-12-08 11:38   ` [PATCH 2/3] Documentation: fix --no-verify documentation for "git commit" Wincent Colaiuta
2007-12-08 11:38     ` Wincent Colaiuta [this message]
2007-12-09  7:21       ` [PATCH 3/3] Fix commit-msg hook to allow editing Junio C Hamano
2007-12-09 12:22         ` Wincent Colaiuta
2007-12-08 12:29 ` [PATCH 4/4] Add tests for pre-commit and commit-msg hooks Wincent Colaiuta
2007-12-08 12:51   ` Wincent Colaiuta

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=1197113889-16243-4-git-send-email-win@wincent.com \
    --to=win@wincent.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=krh@redhat.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 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).