merge: backport GIT_MERGE_AUTOEDIT support
Even though 1.7.9.x series does not open the editor by default when merging in general, it does do so in one occassion: when merging an annotated tag. And worse yet, there is no good way for older scripts to decline this. Backport the support for GIT_MERGE_AUTOEDIT environment variable from 1.7.10 track to help those stuck on 1.7.9.x maintenance track. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Mar 20, 2012 at 15:39 UTC
d387868a7d29621e85e8c5c061d1f50586db74e5
2 files changed
+40
-3
Documentation/merge-options.txt
+12
-2
@@ -8,9 +8,19 @@ failed and do not autocommit, to give the user a chance to
8
inspect and further tweak the merge result before committing.
9
10
--edit::
11
--e::
11
+--no-edit::
12
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.
24
25
--ff::
26
When the merge resolves as a fast-forward, only update the branch
builtin/merge.c
+28
-1
@@ -1109,6 +1109,33 @@ static void write_merge_state(void)
1109
close(fd);
1110
}
1111
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
+
1139
int cmd_merge(int argc, const char **argv, const char *prefix)
1140
{
1141
unsigned char result_tree[20];
@@ -1298,7 +1325,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1325
merge_remote_util(commit)->obj &&
1326
merge_remote_util(commit)->obj->type == OBJ_TAG) {
1327
if (option_edit < 0)
1301
- option_edit = 1;
1328
+ option_edit = default_edit_option();
1329
allow_fast_forward = 0;
1330
}
1331
}