@@ -795,6 +795,32 @@ static void add_strategies(const char *string, unsigned attr)
795
795
796
796
}
797
797
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
+
798
824
static int merge_trivial (void )
799
825
{
800
826
unsigned char result_tree [20 ], result_commit [20 ];
@@ -806,6 +832,7 @@ static int merge_trivial(void)
806
832
parent -> next = xmalloc (sizeof (* parent -> next ));
807
833
parent -> next -> item = remoteheads -> item ;
808
834
parent -> next -> next = NULL ;
835
+ run_prepare_commit_msg ();
809
836
commit_tree (merge_msg .buf , result_tree , parent , result_commit , NULL );
810
837
finish (result_commit , "In-index merge" );
811
838
drop_save ();
@@ -835,6 +862,7 @@ static int finish_automerge(struct commit_list *common,
835
862
}
836
863
free_commit_list (remoteheads );
837
864
strbuf_addch (& merge_msg , '\n' );
865
+ run_prepare_commit_msg ();
838
866
commit_tree (merge_msg .buf , result_tree , parents , result_commit , NULL );
839
867
strbuf_addf (& buf , "Merge made by %s." , wt_strategy );
840
868
finish (result_commit , buf .buf );
@@ -1316,14 +1344,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1316
1344
die_errno ("Could not write to '%s'" , git_path ("MERGE_HEAD" ));
1317
1345
close (fd );
1318
1346
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 ();
1327
1348
fd = open (git_path ("MERGE_MODE" ), O_WRONLY | O_CREAT | O_TRUNC , 0666 );
1328
1349
if (fd < 0 )
1329
1350
die_errno ("Could not open '%s' for writing" ,
0 commit comments