@@ -797,6 +797,32 @@ static void add_strategies(const char *string, unsigned attr)
797797
798798}
799799
800+ static void write_merge_msg (void )
801+ {
802+ int fd = open (git_path ("MERGE_MSG" ), O_WRONLY | O_CREAT , 0666 );
803+ if (fd < 0 )
804+ die_errno ("Could not open '%s' for writing" ,
805+ git_path ("MERGE_MSG" ));
806+ if (write_in_full (fd , merge_msg .buf , merge_msg .len ) != merge_msg .len )
807+ die_errno ("Could not write to '%s'" , git_path ("MERGE_MSG" ));
808+ close (fd );
809+ }
810+
811+ static void read_merge_msg (void )
812+ {
813+ strbuf_reset (& merge_msg );
814+ if (strbuf_read_file (& merge_msg , git_path ("MERGE_MSG" ), 0 ) < 0 )
815+ die_errno ("Could not read from '%s'" , git_path ("MERGE_MSG" ));
816+ }
817+
818+ static void run_prepare_commit_msg (void )
819+ {
820+ write_merge_msg ();
821+ run_hook (get_index_file (), "prepare-commit-msg" ,
822+ git_path ("MERGE_MSG" ), "merge" , NULL , NULL );
823+ read_merge_msg ();
824+ }
825+
800826static int merge_trivial (void )
801827{
802828 unsigned char result_tree [20 ], result_commit [20 ];
@@ -808,6 +834,7 @@ static int merge_trivial(void)
808834 parent -> next = xmalloc (sizeof (* parent -> next ));
809835 parent -> next -> item = remoteheads -> item ;
810836 parent -> next -> next = NULL ;
837+ run_prepare_commit_msg ();
811838 commit_tree (merge_msg .buf , result_tree , parent , result_commit , NULL );
812839 finish (result_commit , "In-index merge" );
813840 drop_save ();
@@ -837,6 +864,7 @@ static int finish_automerge(struct commit_list *common,
837864 }
838865 free_commit_list (remoteheads );
839866 strbuf_addch (& merge_msg , '\n' );
867+ run_prepare_commit_msg ();
840868 commit_tree (merge_msg .buf , result_tree , parents , result_commit , NULL );
841869 strbuf_addf (& buf , "Merge made by %s." , wt_strategy );
842870 finish (result_commit , buf .buf );
@@ -1318,14 +1346,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13181346 die_errno ("Could not write to '%s'" , git_path ("MERGE_HEAD" ));
13191347 close (fd );
13201348 strbuf_addch (& merge_msg , '\n' );
1321- fd = open (git_path ("MERGE_MSG" ), O_WRONLY | O_CREAT , 0666 );
1322- if (fd < 0 )
1323- die_errno ("Could not open '%s' for writing" ,
1324- git_path ("MERGE_MSG" ));
1325- if (write_in_full (fd , merge_msg .buf , merge_msg .len ) !=
1326- merge_msg .len )
1327- die_errno ("Could not write to '%s'" , git_path ("MERGE_MSG" ));
1328- close (fd );
1349+ write_merge_msg ();
13291350 fd = open (git_path ("MERGE_MODE" ), O_WRONLY | O_CREAT | O_TRUNC , 0666 );
13301351 if (fd < 0 )
13311352 die_errno ("Could not open '%s' for writing" ,
0 commit comments