Add GIT_EDITOR environment and core.editor configuration variables
These variables let you specify an editor that will be launched in preference to the EDITOR and VISUAL environment variables. The order of preference is GIT_EDITOR, core.editor, EDITOR, VISUAL. [jc: added a test and config variable documentation] Signed-off-by: Adam Roben <aroben@apple.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Adam Roben committed
Jul 19, 2007 at 22:09 UTC
ef0c2abf3e5061f891b7f07953ef3b0695f52c89
10 files changed
+129
-23
Documentation/config.txt
+8
@@ -281,6 +281,14 @@ core.excludesfile::
281
of files which are not meant to be tracked. See
282
gitlink:gitignore[5].
283
284
+core.editor::
285
+ Commands such as `commit` and `tag` that lets you edit
286
+ messages by lauching an editor uses the value of this
287
+ variable when it is set, and the environment variable
288
+ `GIT_EDITOR` is not set. The order of preference is
289
+ `GIT_EDITOR` environment, `core.editor`, `EDITOR` and
290
+ `VISUAL` environment variables and then finally `vi`.
291
+
292
core.pager::
293
The command that git will use to paginate output. Can be overridden
294
with the `GIT_PAGER` environment variable.
Documentation/git-commit.txt
+6
-4
@@ -244,10 +244,12 @@ on the Subject: line and the rest of the commit in the body.
244
245
include::i18n.txt[]
246
247
-ENVIRONMENT VARIABLES
248
----------------------
249
-The command specified by either the VISUAL or EDITOR environment
250
-variables is used to edit the commit log message.
247
+ENVIRONMENT AND CONFIGURATION VARIABLES
248
+---------------------------------------
249
+The editor used to edit the commit log message will be chosen from the
250
+GIT_EDITOR environment variable, the core.editor configuration variable, the
251
+VISUAL environment variable, or the EDITOR environment variable (in that
252
+order).
253
254
HOOKS
255
-----
Documentation/git-send-email.txt
+2
-2
@@ -44,8 +44,8 @@ The --cc option must be repeated for each user you want on the cc list.
44
value; if that is unspecified, default to --chain-reply-to.
45
46
--compose::
47
- Use $EDITOR to edit an introductory message for the
48
- patch series.
47
+ Use $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an
48
+ introductory message for the patch series.
49
50
--from::
51
Specify the sender of the emails. This will default to
git-am.sh
+1
-1
@@ -364,7 +364,7 @@ do
364
[yY]*) action=yes ;;
365
[aA]*) action=yes interactive= ;;
366
[nN]*) action=skip ;;
367
- [eE]*) "${VISUAL:-${EDITOR:-vi}}" "$dotest/final-commit"
367
+ [eE]*) git_editor "$dotest/final-commit"
368
action=again ;;
369
[vV]*) action=again
370
LESS=-S ${PAGER:-less} "$dotest/patch" ;;
git-commit.sh
+1
-10
@@ -544,18 +544,9 @@ fi
544
545
case "$no_edit" in
546
'')
547
- case "${VISUAL:-$EDITOR},$TERM" in
548
- ,dumb)
549
- echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
550
- echo >&2 "Please supply the commit log message using either"
551
- echo >&2 "-m or -F option. A boilerplate log message has"
552
- echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
553
- exit 1
554
- ;;
555
- esac
547
git-var GIT_AUTHOR_IDENT > /dev/null || die
548
git-var GIT_COMMITTER_IDENT > /dev/null || die
558
- ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
549
+ git_editor "$GIT_DIR/COMMIT_EDITMSG"
550
;;
551
esac
552
git-rebase--interactive.sh
+1
-1
@@ -414,7 +414,7 @@ EOF
414
die_abort "Nothing to do"
415
416
cp "$TODO" "$TODO".backup
417
- ${VISUAL:-${EDITOR:-vi}} "$TODO" ||
417
+ git_editor "$TODO" ||
418
die "Could not execute editor"
419
420
test -z "$(grep -ve '^$' -e '^#' < $TODO)" &&
git-send-email.perl
+3
-4
@@ -49,8 +49,8 @@ Options:
49
--bcc Specify a list of email addresses that should be Bcc:
50
on all the emails.
51
52
- --compose Use \$EDITOR to edit an introductory message for the
53
- patch series.
52
+ --compose Use \$GIT_EDITOR, core.editor, \$EDITOR, or \$VISUAL to edit
53
+ an introductory message for the patch series.
54
55
--subject Specify the initial "Subject:" line.
56
Only necessary if --compose is also set. If --compose
@@ -341,8 +341,7 @@ GIT: for the patch you are writing.
341
EOT
342
close(C);
343
344
- my $editor = $ENV{EDITOR};
345
- $editor = 'vi' unless defined $editor;
344
+ my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
345
system($editor, $compose_filename);
346
347
open(C2,">",$compose_filename . ".final")
git-sh-setup.sh
+15
@@ -28,6 +28,21 @@ set_reflog_action() {
28
fi
29
}
30
31
+git_editor() {
32
+ GIT_EDITOR=${GIT_EDITOR:-$(git config core.editor || echo ${VISUAL:-${EDITOR}})}
33
+ case "$GIT_EDITOR,$TERM" in
34
+ ,dumb)
35
+ echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
36
+ echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
37
+ echo >&2 "Please set one of these variables to an appropriate"
38
+ echo >&2 "editor or run $0 with options that will not cause an"
39
+ echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
40
+ exit 1
41
+ ;;
42
+ esac
43
+ "${GIT_EDITOR:-vi}" "$1"
44
+}
45
+
46
is_bare_repository () {
47
git rev-parse --is-bare-repository
48
}
git-tag.sh
+1
-1
@@ -177,7 +177,7 @@ if [ "$annotate" ]; then
177
( echo "#"
178
echo "# Write a tag message"
179
echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
180
- ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
180
+ git_editor "$GIT_DIR"/TAG_EDITMSG || exit
181
else
182
printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG
183
fi
t/t7005-editor.sh
new
+91
@@ -0,0 +1,91 @@
1
+#!/bin/sh
2
+
3
+test_description='GIT_EDITOR, core.editor, and stuff'
4
+
5
+. ./test-lib.sh
6
+
7
+for i in GIT_EDITOR core_editor EDITOR VISUAL vi
8
+do
9
+ cat >e-$i.sh <<-EOF
10
+ echo "Edited by $i" >"\$1"
11
+ EOF
12
+ chmod +x e-$i.sh
13
+done
14
+unset vi
15
+mv e-vi.sh vi
16
+PATH=".:$PATH"
17
+unset EDITOR VISUAL GIT_EDITOR
18
+
19
+test_expect_success setup '
20
+
21
+ msg="Hand edited" &&
22
+ echo "$msg" >expect &&
23
+ git add vi &&
24
+ test_tick &&
25
+ git commit -m "$msg" &&
26
+ git show -s --pretty=oneline |
27
+ sed -e "s/^[0-9a-f]* //" >actual &&
28
+ diff actual expect
29
+
30
+'
31
+
32
+TERM=dumb
33
+export TERM
34
+test_expect_success 'dumb should error out when falling back on vi' '
35
+
36
+ if git commit --amend
37
+ then
38
+ echo "Oops?"
39
+ exit 1
40
+ else
41
+ : happy
42
+ fi
43
+'
44
+
45
+TERM=vt100
46
+export TERM
47
+for i in vi EDITOR VISUAL core_editor GIT_EDITOR
48
+do
49
+ echo "Edited by $i" >expect
50
+ unset EDITOR VISUAL GIT_EDITOR
51
+ git config --unset-all core.editor
52
+ case "$i" in
53
+ core_editor)
54
+ git config core.editor ./e-core_editor.sh
55
+ ;;
56
+ [A-Z]*)
57
+ eval "$i=./e-$i.sh"
58
+ export $i
59
+ ;;
60
+ esac
61
+ test_expect_success "Using $i" '
62
+ git commit --amend &&
63
+ git show -s --pretty=oneline |
64
+ sed -e "s/^[0-9a-f]* //" >actual &&
65
+ diff actual expect
66
+ '
67
+done
68
+
69
+unset EDITOR VISUAL GIT_EDITOR
70
+git config --unset-all core.editor
71
+for i in vi EDITOR VISUAL core_editor GIT_EDITOR
72
+do
73
+ echo "Edited by $i" >expect
74
+ case "$i" in
75
+ core_editor)
76
+ git config core.editor ./e-core_editor.sh
77
+ ;;
78
+ [A-Z]*)
79
+ eval "$i=./e-$i.sh"
80
+ export $i
81
+ ;;
82
+ esac
83
+ test_expect_success "Using $i (override)" '
84
+ git commit --amend &&
85
+ git show -s --pretty=oneline |
86
+ sed -e "s/^[0-9a-f]* //" >actual &&
87
+ diff actual expect
88
+ '
89
+done
90
+
91
+test_done