Skip to content

Commit af6b37f

Browse files
committed
Merge branch 'jc/pull-signed-tag'
* jc/pull-signed-tag: merge: use editor by default in interactive sessions Conflicts: Documentation/merge-options.txt
2 parents 2a2aa8e + f824628 commit af6b37f

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

Documentation/git-merge.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-merge - Join two or more development histories together
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git merge' [-n] [--stat] [--no-commit] [--squash]
12+
'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
1313
[-s <strategy>] [-X <strategy-option>]
1414
[--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
1515
'git merge' <msg> HEAD <commit>...

Documentation/merge-options.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ failed and do not autocommit, to give the user a chance to
88
inspect and further tweak the merge result before committing.
99

1010
--edit::
11-
-e::
12-
Invoke editor before committing successful merge to further
13-
edit the default merge message.
11+
--no-edit::
12+
Invoke an editor before committing successful mechanical merge to
13+
further edit the auto-generated merge message, so that the user
14+
can explain and justify the merge. The `--no-edit` option can be
15+
used to accept the auto-generated message (this is generally
16+
discouraged). The `--edit` option is still useful if you are
17+
giving a draft message with the `-m` option from the command line
18+
and want to edit it in the editor.
19+
+
20+
Older scripts may depend on the historical behaviour of not allowing the
21+
user to edit the merge log message. They will see an editor opened when
22+
they run `git merge`. To make it easier to adjust such scripts to the
23+
updated behaviour, the environment variable `GIT_MERGE_AUTOEDIT` can be
24+
set to `no` at the beginning of them.
1425

1526
--ff::
1627
--no-ff::

builtin/merge.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static const char * const builtin_merge_usage[] = {
4848

4949
static int show_diffstat = 1, shortlog_len = -1, squash;
5050
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;
5252
static int allow_trivial = 1, have_message;
5353
static int overwrite_ignore = 1;
5454
static 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+
11021129
int 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);

t/test-lib.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ GIT_AUTHOR_NAME='A U Thor'
6464
6565
GIT_COMMITTER_NAME='C O Mitter'
6666
GIT_MERGE_VERBOSITY=5
67-
export GIT_MERGE_VERBOSITY
67+
GIT_MERGE_AUTOEDIT=no
68+
export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
6869
export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
6970
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
7071
export EDITOR

0 commit comments

Comments
 (0)