diff options
| author | Junio C Hamano <gitster@pobox.com> | 2011-02-27 21:58:30 -0800 | 
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2011-02-27 21:58:30 -0800 | 
| commit | 11e4b4fa49ff3221c9d07a877af6c73b619e9934 (patch) | |
| tree | 6fc6a7f10b14013b6d8a57283fab93ceb3cfa355 | |
| parent | fc7ae9c156775cc9679c0bcc7156abb7dba1bd3a (diff) | |
| parent | 65969d43d10512a44f5e7248e4404b946d1d0d9f (diff) | |
| download | git-11e4b4fa49ff3221c9d07a877af6c73b619e9934.tar.gz | |
Merge branch 'js/maint-merge-use-prepare-commit-msg-hook'
* js/maint-merge-use-prepare-commit-msg-hook:
  merge: honor prepare-commit-msg hook
| -rw-r--r-- | builtin/merge.c | 37 | ||||
| -rwxr-xr-x | t/t7505-prepare-commit-msg-hook.sh | 12 | 
2 files changed, 41 insertions, 8 deletions
| diff --git a/builtin/merge.c b/builtin/merge.c index 8c58c3cc4a..9b8c163c89 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -797,6 +797,32 @@ static void add_strategies(const char *string, unsigned attr)  } +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 +834,7 @@ static int merge_trivial(void)  	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 +864,7 @@ static int finish_automerge(struct commit_list *common,  	}  	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 +1346,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)  			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", diff --git a/t/t7505-prepare-commit-msg-hook.sh b/t/t7505-prepare-commit-msg-hook.sh index ff189624d4..5b4b694f18 100755 --- a/t/t7505-prepare-commit-msg-hook.sh +++ b/t/t7505-prepare-commit-msg-hook.sh @@ -132,6 +132,18 @@ test_expect_success 'with hook (-c)' '  ' +test_expect_success 'with hook (merge)' ' + +	head=`git rev-parse HEAD` && +	git checkout -b other HEAD@{1} && +	echo "more" >> file && +	git add file && +	git commit -m other && +	git checkout - && +	git merge other && +	test "`git log -1 --pretty=format:%s`" = merge +' +  cat > "$HOOK" <<'EOF'  #!/bin/sh  exit 1 | 
