3838#include "tag.h"
3939#include "alias.h"
4040#include "commit-reach.h"
41+ #include "wt-status.h"
4142
4243#define DEFAULT_TWOHEAD (1<<0)
4344#define DEFAULT_OCTOPUS (1<<1)
@@ -98,6 +99,9 @@ enum ff_type {
9899
99100static enum ff_type fast_forward = FF_ALLOW ;
100101
102+ static const char * cleanup_arg ;
103+ static enum commit_msg_cleanup_mode cleanup_mode ;
104+
101105static int option_parse_message (const struct option * opt ,
102106 const char * arg , int unset )
103107{
@@ -249,6 +253,7 @@ static struct option builtin_merge_options[] = {
249253 N_ ("perform a commit if the merge succeeds (default)" )),
250254 OPT_BOOL ('e' , "edit" , & option_edit ,
251255 N_ ("edit message before committing" )),
256+ OPT_CLEANUP (& cleanup_arg ),
252257 OPT_SET_INT (0 , "ff" , & fast_forward , N_ ("allow fast-forward (default)" ), FF_ALLOW ),
253258 OPT_SET_INT_F (0 , "ff-only" , & fast_forward ,
254259 N_ ("abort if fast-forward is not possible" ),
@@ -612,6 +617,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
612617 return git_config_string (& pull_twohead , k , v );
613618 else if (!strcmp (k , "pull.octopus" ))
614619 return git_config_string (& pull_octopus , k , v );
620+ else if (!strcmp (k , "commit.cleanup" ))
621+ return git_config_string (& cleanup_arg , k , v );
615622 else if (!strcmp (k , "merge.renormalize" ))
616623 option_renormalize = git_config_bool (k , v );
617624 else if (!strcmp (k , "merge.ff" )) {
@@ -800,20 +807,33 @@ static void abort_commit(struct commit_list *remoteheads, const char *err_msg)
800807static const char merge_editor_comment [] =
801808N_ ("Please enter a commit message to explain why this merge is necessary,\n"
802809 "especially if it merges an updated upstream into a topic branch.\n"
803- "\n"
804- "Lines starting with '%c' will be ignored, and an empty message aborts\n"
810+ "\n" );
811+
812+ static const char scissors_editor_comment [] =
813+ N_ ("An empty message aborts the commit.\n" );
814+
815+ static const char no_scissors_editor_comment [] =
816+ N_ ("Lines starting with '%c' will be ignored, and an empty message aborts\n"
805817 "the commit.\n" );
806818
807819static void write_merge_heads (struct commit_list * );
808820static void prepare_to_commit (struct commit_list * remoteheads )
809821{
810822 struct strbuf msg = STRBUF_INIT ;
811823 strbuf_addbuf (& msg , & merge_msg );
812- strbuf_addch (& msg , '\n' );
813824 if (squash )
814825 BUG ("the control must not reach here under --squash" );
815- if (0 < option_edit )
816- strbuf_commented_addf (& msg , _ (merge_editor_comment ), comment_line_char );
826+ if (0 < option_edit ) {
827+ strbuf_addch (& msg , '\n' );
828+ if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS ) {
829+ wt_status_append_cut_line (& msg );
830+ strbuf_commented_addf (& msg , "\n" );
831+ }
832+ strbuf_commented_addf (& msg , _ (merge_editor_comment ));
833+ strbuf_commented_addf (& msg , _ (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS ?
834+ scissors_editor_comment :
835+ no_scissors_editor_comment ), comment_line_char );
836+ }
817837 if (signoff )
818838 append_signoff (& msg , ignore_non_trailer (msg .buf , msg .len ), 0 );
819839 write_merge_heads (remoteheads );
@@ -832,7 +852,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
832852 abort_commit (remoteheads , NULL );
833853
834854 read_merge_msg (& msg );
835- strbuf_stripspace (& msg , 0 < option_edit );
855+ cleanup_message (& msg , cleanup_mode , 0 );
836856 if (!msg .len )
837857 abort_commit (remoteheads , _ ("Empty commit message." ));
838858 strbuf_release (& merge_msg );
@@ -880,7 +900,6 @@ static int finish_automerge(struct commit *head,
880900 parents = remoteheads ;
881901 if (!head_subsumed || fast_forward == FF_NO )
882902 commit_list_insert (head , & parents );
883- strbuf_addch (& merge_msg , '\n' );
884903 prepare_to_commit (remoteheads );
885904 if (commit_tree (merge_msg .buf , merge_msg .len , result_tree , parents ,
886905 & result_commit , NULL , sign_commit ))
@@ -1301,6 +1320,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13011320 }
13021321 resolve_undo_clear ();
13031322
1323+ if (option_edit < 0 )
1324+ option_edit = default_edit_option ();
1325+
1326+ cleanup_mode = get_cleanup_mode (cleanup_arg , 0 < option_edit );
1327+
13041328 if (verbosity < 0 )
13051329 show_diffstat = 0 ;
13061330
@@ -1386,9 +1410,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13861410 fast_forward = FF_NO ;
13871411 }
13881412
1389- if (option_edit < 0 )
1390- option_edit = default_edit_option ();
1391-
13921413 if (!use_strategies ) {
13931414 if (!remoteheads )
13941415 ; /* already up-to-date */
0 commit comments