@@ -52,11 +52,6 @@ static int fill_commit_message(struct repository *repo,
5252 " empty message aborts the commit.\n" );
5353 struct wt_status s ;
5454
55- strbuf_addstr (out , default_message );
56- strbuf_addch (out , '\n' );
57- strbuf_commented_addf (out , comment_line_str , hint , action , comment_line_str );
58- write_file_buf (path , out -> buf , out -> len );
59-
6055 wt_status_prepare (repo , & s );
6156 FREE_AND_NULL (s .branch );
6257 s .ahead_behind_flags = AHEAD_BEHIND_QUICK ;
@@ -68,14 +63,22 @@ static int fill_commit_message(struct repository *repo,
6863 s .whence = FROM_COMMIT ;
6964 s .committable = 1 ;
7065
71- s .fp = fopen (git_path_commit_editmsg () , "a " );
66+ s .fp = fopen (path , "w " );
7267 if (!s .fp )
73- return error_errno (_ ("could not open '%s'" ), git_path_commit_editmsg ());
68+ return error_errno (_ ("could not open '%s'" ), path );
69+
70+ strbuf_addstr (out , default_message );
71+ strbuf_addch (out , '\n' );
72+ strbuf_commented_addf (out , comment_line_str , hint , action , comment_line_str );
73+ if (fwrite (out -> buf , 1 , out -> len , s .fp ) != out -> len )
74+ die_errno (_ ("could not write to '%s'" ), path );
7475
7576 wt_status_collect_changes_trees (& s , old_tree , new_tree );
7677 wt_status_print (& s );
7778 wt_status_collect_free_buffers (& s );
7879 string_list_clear_func (& s .change , change_data_free );
80+ if (fclose (s .fp ))
81+ die_errno (_ ("could not write to '%s'" ), path );
7982
8083 strbuf_reset (out );
8184 if (launch_editor (path , out , NULL )) {
0 commit comments