From: Junio C Hamano Date: Mon, 28 Feb 2011 05:58:30 +0000 (-0800) Subject: Merge branch 'js/maint-merge-use-prepare-commit-msg-hook' X-Git-Tag: v1.7.5-rc0~112 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/11e4b4fa49ff3221c9d07a877af6c73b619e9934?ds=inline;hp=-c Merge branch 'js/maint-merge-use-prepare-commit-msg-hook' * js/maint-merge-use-prepare-commit-msg-hook: merge: honor prepare-commit-msg hook --- 11e4b4fa49ff3221c9d07a877af6c73b619e9934 diff --combined builtin/merge.c index 8c58c3cc4a,ca16657d25..9b8c163c89 --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -194,8 -194,8 +194,8 @@@ static struct option builtin_merge_opti "merge strategy to use", option_parse_strategy), OPT_CALLBACK('X', "strategy-option", &xopts, "option=value", "option for selected merge strategy", option_parse_x), - OPT_CALLBACK('m', "message", &merge_msg, "message", - "message to be used for the merge commit (if any)", + OPT_CALLBACK('m', "message", &merge_msg, "MESSAGE", + "merge commit message (for a non-fast-forward merge)", option_parse_message), OPT__VERBOSITY(&verbosity), OPT_BOOLEAN(0, "abort", &abort_current_merge, @@@ -582,8 -582,7 +582,8 @@@ static void write_tree_trivial(unsigne die("git write-tree failed to write a tree"); } -int try_merge_command(const char *strategy, struct commit_list *common, +int try_merge_command(const char *strategy, size_t xopts_nr, + const char **xopts, struct commit_list *common, const char *head_arg, struct commit_list *remotes) { const char **args; @@@ -681,8 -680,7 +681,8 @@@ static int try_merge_strategy(const cha rollback_lock_file(lock); return clean ? 0 : 1; } else { - return try_merge_command(strategy, common, head_arg, remoteheads); + return try_merge_command(strategy, xopts_nr, xopts, + common, head_arg, remoteheads); } } @@@ -797,6 -795,32 +797,32 @@@ static void add_strategies(const char * } + static void write_merge_msg(void) + { + int fd = open(git_path("MERGE_MSG"), O_WRONLY | O_CREAT, 0666); + if (fd < 0) + die_errno("Could not open '%s' for writing", + git_path("MERGE_MSG")); + if (write_in_full(fd, merge_msg.buf, merge_msg.len) != merge_msg.len) + die_errno("Could not write to '%s'", git_path("MERGE_MSG")); + close(fd); + } + + static void read_merge_msg(void) + { + strbuf_reset(&merge_msg); + if (strbuf_read_file(&merge_msg, git_path("MERGE_MSG"), 0) < 0) + die_errno("Could not read from '%s'", git_path("MERGE_MSG")); + } + + static void run_prepare_commit_msg(void) + { + write_merge_msg(); + run_hook(get_index_file(), "prepare-commit-msg", + git_path("MERGE_MSG"), "merge", NULL, NULL); + read_merge_msg(); + } + static int merge_trivial(void) { unsigned char result_tree[20], result_commit[20]; @@@ -808,6 -832,7 +834,7 @@@ parent->next = xmalloc(sizeof(*parent->next)); parent->next->item = remoteheads->item; parent->next->next = NULL; + run_prepare_commit_msg(); commit_tree(merge_msg.buf, result_tree, parent, result_commit, NULL); finish(result_commit, "In-index merge"); drop_save(); @@@ -837,6 -862,7 +864,7 @@@ static int finish_automerge(struct comm } free_commit_list(remoteheads); strbuf_addch(&merge_msg, '\n'); + run_prepare_commit_msg(); commit_tree(merge_msg.buf, result_tree, parents, result_commit, NULL); strbuf_addf(&buf, "Merge made by %s.", wt_strategy); finish(result_commit, buf.buf); @@@ -1318,14 -1344,7 +1346,7 @@@ int cmd_merge(int argc, const char **ar die_errno("Could not write to '%s'", git_path("MERGE_HEAD")); close(fd); strbuf_addch(&merge_msg, '\n'); - fd = open(git_path("MERGE_MSG"), O_WRONLY | O_CREAT, 0666); - if (fd < 0) - die_errno("Could not open '%s' for writing", - git_path("MERGE_MSG")); - if (write_in_full(fd, merge_msg.buf, merge_msg.len) != - merge_msg.len) - die_errno("Could not write to '%s'", git_path("MERGE_MSG")); - close(fd); + write_merge_msg(); fd = open(git_path("MERGE_MODE"), O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) die_errno("Could not open '%s' for writing",