@@ -48,7 +48,7 @@ static const char * const builtin_merge_usage[] = {
4848
4949static int show_diffstat = 1 , shortlog_len = -1 , squash ;
5050static int option_commit = 1 , allow_fast_forward = 1 ;
51- static int fast_forward_only , option_edit ;
51+ static int fast_forward_only , option_edit = -1 ;
5252static int allow_trivial = 1 , have_message ;
5353static int overwrite_ignore = 1 ;
5454static struct strbuf merge_msg = STRBUF_INIT ;
@@ -193,7 +193,7 @@ static struct option builtin_merge_options[] = {
193193 "create a single commit instead of doing a merge" ),
194194 OPT_BOOLEAN (0 , "commit" , & option_commit ,
195195 "perform a commit if the merge succeeds (default)" ),
196- OPT_BOOLEAN ('e' , "edit" , & option_edit ,
196+ OPT_BOOL ('e' , "edit" , & option_edit ,
197197 "edit message before committing" ),
198198 OPT_BOOLEAN (0 , "ff" , & allow_fast_forward ,
199199 "allow fast-forward (default)" ),
@@ -893,12 +893,12 @@ static void prepare_to_commit(void)
893893 write_merge_msg (& msg );
894894 run_hook (get_index_file (), "prepare-commit-msg" ,
895895 git_path ("MERGE_MSG" ), "merge" , NULL , NULL );
896- if (option_edit ) {
896+ if (0 < option_edit ) {
897897 if (launch_editor (git_path ("MERGE_MSG" ), NULL , NULL ))
898898 abort_commit (NULL );
899899 }
900900 read_merge_msg (& msg );
901- stripspace (& msg , option_edit );
901+ stripspace (& msg , 0 < option_edit );
902902 if (!msg .len )
903903 abort_commit (_ ("Empty commit message." ));
904904 strbuf_release (& merge_msg );
@@ -1099,6 +1099,33 @@ static void write_merge_state(void)
10991099 close (fd );
11001100}
11011101
1102+ static int default_edit_option (void )
1103+ {
1104+ static const char name [] = "GIT_MERGE_AUTOEDIT" ;
1105+ const char * e = getenv (name );
1106+ struct stat st_stdin , st_stdout ;
1107+
1108+ if (have_message )
1109+ /* an explicit -m msg without --[no-]edit */
1110+ return 0 ;
1111+
1112+ if (e ) {
1113+ int v = git_config_maybe_bool (name , e );
1114+ if (v < 0 )
1115+ die ("Bad value '%s' in environment '%s'" , e , name );
1116+ return v ;
1117+ }
1118+
1119+ /* Use editor if stdin and stdout are the same and is a tty */
1120+ return (!fstat (0 , & st_stdin ) &&
1121+ !fstat (1 , & st_stdout ) &&
1122+ isatty (0 ) &&
1123+ st_stdin .st_dev == st_stdout .st_dev &&
1124+ st_stdin .st_ino == st_stdout .st_ino &&
1125+ st_stdin .st_mode == st_stdout .st_mode );
1126+ }
1127+
1128+
11021129int cmd_merge (int argc , const char * * argv , const char * prefix )
11031130{
11041131 unsigned char result_tree [20 ];
@@ -1291,6 +1318,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12911318 }
12921319 }
12931320
1321+ if (option_edit < 0 )
1322+ option_edit = default_edit_option ();
1323+
12941324 if (!use_strategies ) {
12951325 if (!remoteheads -> next )
12961326 add_strategies (pull_twohead , DEFAULT_TWOHEAD );
0 commit comments