@matheusbsbs / matheus-bagliano / commits / 740001a578
Fork 0

Fix commit-msg hook to allow editing

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. This is based on Wincent's patch, but redone with a clarified logic. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 8, 2007 at 23:23 UTC 740001a5780a12972c83c99f25c49c8d8cebdb43
2 files changed +7 -4
builtin-commit.c
+5 -4
@@ -787,16 +787,17 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
787 char index[PATH_MAX];
788 const char *env[2] = { index, NULL };
789 snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
790 - launch_editor(git_path(commit_editmsg), &sb, env);
791 - } else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
792 - rollback_index_files();
793 - die("could not read commit message");
790 + launch_editor(git_path(commit_editmsg), NULL, env);
791 }
792 if (!no_verify &&
793 run_hook(index_file, "commit-msg", git_path(commit_editmsg))) {
794 rollback_index_files();
795 exit(1);
796 }
797 + if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
798 + rollback_index_files();
799 + die("could not read commit message");
800 + }
801
802 /* Truncate the message just before the diff, if any. */
803 p = strstr(sb.buf, "\ndiff --git a/");
builtin-tag.c
+2
@@ -53,6 +53,8 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
53 die("There was a problem with the editor %s.", editor);
54 }
55
56 + if (!buffer)
57 + return;
58 if (strbuf_read_file(buffer, path, 0) < 0)
59 die("could not read message file '%s': %s",
60 path, strerror(errno));