@@ -795,6 +795,32 @@ static void add_strategies(const char *string, unsigned attr)
795795
796796}
797797
798+ static void write_merge_msg (void )
799+ {
800+ int fd = open (git_path ("MERGE_MSG" ), O_WRONLY | O_CREAT , 0666 );
801+ if (fd < 0 )
802+ die_errno ("Could not open '%s' for writing" ,
803+ git_path ("MERGE_MSG" ));
804+ if (write_in_full (fd , merge_msg .buf , merge_msg .len ) != merge_msg .len )
805+ die_errno ("Could not write to '%s'" , git_path ("MERGE_MSG" ));
806+ close (fd );
807+ }
808+
809+ static void read_merge_msg (void )
810+ {
811+ strbuf_reset (& merge_msg );
812+ if (strbuf_read_file (& merge_msg , git_path ("MERGE_MSG" ), 0 ) < 0 )
813+ die_errno ("Could not read from '%s'" , git_path ("MERGE_MSG" ));
814+ }
815+
816+ static void run_prepare_commit_msg (void )
817+ {
818+ write_merge_msg ();
819+ run_hook (get_index_file (), "prepare-commit-msg" ,
820+ git_path ("MERGE_MSG" ), "merge" , NULL , NULL );
821+ read_merge_msg ();
822+ }
823+
798824static int merge_trivial (void )
799825{
800826 unsigned char result_tree [20 ], result_commit [20 ];
@@ -806,6 +832,7 @@ static int merge_trivial(void)
806832 parent -> next = xmalloc (sizeof (* parent -> next ));
807833 parent -> next -> item = remoteheads -> item ;
808834 parent -> next -> next = NULL ;
835+ run_prepare_commit_msg ();
809836 commit_tree (merge_msg .buf , result_tree , parent , result_commit , NULL );
810837 finish (result_commit , "In-index merge" );
811838 drop_save ();
@@ -835,6 +862,7 @@ static int finish_automerge(struct commit_list *common,
835862 }
836863 free_commit_list (remoteheads );
837864 strbuf_addch (& merge_msg , '\n' );
865+ run_prepare_commit_msg ();
838866 commit_tree (merge_msg .buf , result_tree , parents , result_commit , NULL );
839867 strbuf_addf (& buf , "Merge made by %s." , wt_strategy );
840868 finish (result_commit , buf .buf );
@@ -1316,14 +1344,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13161344 die_errno ("Could not write to '%s'" , git_path ("MERGE_HEAD" ));
13171345 close (fd );
13181346 strbuf_addch (& merge_msg , '\n' );
1319- fd = open (git_path ("MERGE_MSG" ), O_WRONLY | O_CREAT , 0666 );
1320- if (fd < 0 )
1321- die_errno ("Could not open '%s' for writing" ,
1322- git_path ("MERGE_MSG" ));
1323- if (write_in_full (fd , merge_msg .buf , merge_msg .len ) !=
1324- merge_msg .len )
1325- die_errno ("Could not write to '%s'" , git_path ("MERGE_MSG" ));
1326- close (fd );
1347+ write_merge_msg ();
13271348 fd = open (git_path ("MERGE_MODE" ), O_WRONLY | O_CREAT | O_TRUNC , 0666 );
13281349 if (fd < 0 )
13291350 die_errno ("Could not open '%s' for writing" ,
0 commit comments