@@ -797,6 +797,32 @@ static void add_strategies(const char *string, unsigned attr)
797
797
798
798
}
799
799
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
+
800
826
static int merge_trivial (void )
801
827
{
802
828
unsigned char result_tree [20 ], result_commit [20 ];
@@ -808,6 +834,7 @@ static int merge_trivial(void)
808
834
parent -> next = xmalloc (sizeof (* parent -> next ));
809
835
parent -> next -> item = remoteheads -> item ;
810
836
parent -> next -> next = NULL ;
837
+ run_prepare_commit_msg ();
811
838
commit_tree (merge_msg .buf , result_tree , parent , result_commit , NULL );
812
839
finish (result_commit , "In-index merge" );
813
840
drop_save ();
@@ -837,6 +864,7 @@ static int finish_automerge(struct commit_list *common,
837
864
}
838
865
free_commit_list (remoteheads );
839
866
strbuf_addch (& merge_msg , '\n' );
867
+ run_prepare_commit_msg ();
840
868
commit_tree (merge_msg .buf , result_tree , parents , result_commit , NULL );
841
869
strbuf_addf (& buf , "Merge made by %s." , wt_strategy );
842
870
finish (result_commit , buf .buf );
@@ -1318,14 +1346,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1318
1346
die_errno ("Could not write to '%s'" , git_path ("MERGE_HEAD" ));
1319
1347
close (fd );
1320
1348
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 ();
1329
1350
fd = open (git_path ("MERGE_MODE" ), O_WRONLY | O_CREAT | O_TRUNC , 0666 );
1330
1351
if (fd < 0 )
1331
1352
die_errno ("Could not open '%s' for writing" ,
0 commit comments