@@ -48,7 +48,7 @@ static const char * const builtin_merge_usage[] = {
48
48
49
49
static int show_diffstat = 1 , shortlog_len = -1 , squash ;
50
50
static 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 ;
52
52
static int allow_trivial = 1 , have_message ;
53
53
static int overwrite_ignore = 1 ;
54
54
static struct strbuf merge_msg = STRBUF_INIT ;
@@ -193,7 +193,7 @@ static struct option builtin_merge_options[] = {
193
193
"create a single commit instead of doing a merge" ),
194
194
OPT_BOOLEAN (0 , "commit" , & option_commit ,
195
195
"perform a commit if the merge succeeds (default)" ),
196
- OPT_BOOLEAN ('e' , "edit" , & option_edit ,
196
+ OPT_BOOL ('e' , "edit" , & option_edit ,
197
197
"edit message before committing" ),
198
198
OPT_BOOLEAN (0 , "ff" , & allow_fast_forward ,
199
199
"allow fast-forward (default)" ),
@@ -893,12 +893,12 @@ static void prepare_to_commit(void)
893
893
write_merge_msg (& msg );
894
894
run_hook (get_index_file (), "prepare-commit-msg" ,
895
895
git_path ("MERGE_MSG" ), "merge" , NULL , NULL );
896
- if (option_edit ) {
896
+ if (0 < option_edit ) {
897
897
if (launch_editor (git_path ("MERGE_MSG" ), NULL , NULL ))
898
898
abort_commit (NULL );
899
899
}
900
900
read_merge_msg (& msg );
901
- stripspace (& msg , option_edit );
901
+ stripspace (& msg , 0 < option_edit );
902
902
if (!msg .len )
903
903
abort_commit (_ ("Empty commit message." ));
904
904
strbuf_release (& merge_msg );
@@ -1099,6 +1099,33 @@ static void write_merge_state(void)
1099
1099
close (fd );
1100
1100
}
1101
1101
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
+
1102
1129
int cmd_merge (int argc , const char * * argv , const char * prefix )
1103
1130
{
1104
1131
unsigned char result_tree [20 ];
@@ -1291,6 +1318,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1291
1318
}
1292
1319
}
1293
1320
1321
+ if (option_edit < 0 )
1322
+ option_edit = default_edit_option ();
1323
+
1294
1324
if (!use_strategies ) {
1295
1325
if (!remoteheads -> next )
1296
1326
add_strategies (pull_twohead , DEFAULT_TWOHEAD );
0 commit comments