Skip to content

Commit b52ab19

Browse files
committed
Merge branch 'jc/maint-merge-autoedit' into maint
* jc/maint-merge-autoedit: merge: backport GIT_MERGE_AUTOEDIT support
2 parents b8939b2 + d387868 commit b52ab19

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

Documentation/merge-options.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ 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::
11+
--no-edit::
1212
Invoke editor before committing successful merge to further
13-
edit the default merge message.
13+
edit the default merge message. The `--no-edit` option can be
14+
used to accept the auto-generated message (this is generally
15+
discouraged) when merging an annotated tag, in which case
16+
`git merge` automatically spawns the editor so that the result
17+
of the GPG verification of the tag can be seen.
18+
+
19+
Older scripts may depend on the historical behaviour of not allowing the
20+
user to edit the merge log message. They will see an editor opened when
21+
they run `git merge` to merge an annotated tag. To make it easier to adjust
22+
such scripts to the updated behaviour, the environment variable
23+
`GIT_MERGE_AUTOEDIT` can be set to `no` at the beginning of them.
1424

1525
--ff::
1626
When the merge resolves as a fast-forward, only update the branch

builtin/merge.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,33 @@ static void write_merge_state(void)
11091109
close(fd);
11101110
}
11111111

1112+
static int default_edit_option(void)
1113+
{
1114+
static const char name[] = "GIT_MERGE_AUTOEDIT";
1115+
const char *e = getenv(name);
1116+
struct stat st_stdin, st_stdout;
1117+
1118+
if (have_message)
1119+
/* an explicit -m msg without --[no-]edit */
1120+
return 0;
1121+
1122+
if (e) {
1123+
int v = git_config_maybe_bool(name, e);
1124+
if (v < 0)
1125+
die("Bad value '%s' in environment '%s'", e, name);
1126+
return v;
1127+
}
1128+
1129+
/* Use editor if stdin and stdout are the same and is a tty */
1130+
return (!fstat(0, &st_stdin) &&
1131+
!fstat(1, &st_stdout) &&
1132+
isatty(0) && isatty(1) &&
1133+
st_stdin.st_dev == st_stdout.st_dev &&
1134+
st_stdin.st_ino == st_stdout.st_ino &&
1135+
st_stdin.st_mode == st_stdout.st_mode);
1136+
}
1137+
1138+
11121139
int cmd_merge(int argc, const char **argv, const char *prefix)
11131140
{
11141141
unsigned char result_tree[20];
@@ -1298,7 +1325,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12981325
merge_remote_util(commit)->obj &&
12991326
merge_remote_util(commit)->obj->type == OBJ_TAG) {
13001327
if (option_edit < 0)
1301-
option_edit = 1;
1328+
option_edit = default_edit_option();
13021329
allow_fast_forward = 0;
13031330
}
13041331
}

0 commit comments

Comments
 (0)