Skip to content

Commit b4479f0

Browse files
jrngitster
authored andcommitted
add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR"
Use the new "git var GIT_EDITOR" feature to decide what editor to use, instead of duplicating its logic elsewhere. This should make the behavior of commands in edge cases (e.g., editor names with spaces) a little more consistent. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6361824 commit b4479f0

File tree

8 files changed

+16
-29
lines changed

8 files changed

+16
-29
lines changed

Documentation/config.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,7 @@ core.editor::
387387
Commands such as `commit` and `tag` that lets you edit
388388
messages by launching an editor uses the value of this
389389
variable when it is set, and the environment variable
390-
`GIT_EDITOR` is not set. The order of preference is
391-
`GIT_EDITOR` environment, `core.editor`, `VISUAL` and
392-
`EDITOR` environment variables and then finally `vi`.
390+
`GIT_EDITOR` is not set. See linkgit:git-var[1].
393391

394392
core.pager::
395393
The command that git will use to paginate output. Can

Documentation/git-commit.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ ENVIRONMENT AND CONFIGURATION VARIABLES
323323
The editor used to edit the commit log message will be chosen from the
324324
GIT_EDITOR environment variable, the core.editor configuration variable, the
325325
VISUAL environment variable, or the EDITOR environment variable (in that
326-
order).
326+
order). See linkgit:git-var[1] for details.
327327

328328
HOOKS
329329
-----

Documentation/git-send-email.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ The --bcc option must be repeated for each user you want on the bcc list.
6060
The --cc option must be repeated for each user you want on the cc list.
6161

6262
--compose::
63-
Use $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an
64-
introductory message for the patch series.
63+
Invoke a text editor (see GIT_EDITOR in linkgit:git-var[1])
64+
to edit an introductory message for the patch series.
6565
+
6666
When '--compose' is used, git send-email will use the From, Subject, and
6767
In-Reply-To headers specified in the message. If the body of the message

contrib/fast-import/git-p4

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,13 +729,10 @@ class P4Submit(Command):
729729
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
730730
tmpFile.close()
731731
mtime = os.stat(fileName).st_mtime
732-
defaultEditor = "vi"
733-
if platform.system() == "Windows":
734-
defaultEditor = "notepad"
735732
if os.environ.has_key("P4EDITOR"):
736733
editor = os.environ.get("P4EDITOR")
737734
else:
738-
editor = os.environ.get("EDITOR", defaultEditor);
735+
editor = read_pipe("git var GIT_EDITOR")
739736
system(editor + " " + fileName)
740737

741738
response = "y"

git-add--interactive.perl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,7 @@ sub edit_hunk_manually {
987987
EOF
988988
close $fh;
989989

990-
my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor")
991-
|| $ENV{VISUAL} || $ENV{EDITOR} || "vi";
990+
chomp(my $editor = run_cmd_pipe(qw(git var GIT_EDITOR)));
992991
system('sh', '-c', $editor.' "$@"', $editor, $hunkfile);
993992

994993
if ($? != 0) {

git-send-email.perl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ sub format_2822_time {
162162

163163
# Handle interactive edition of files.
164164
my $multiedit;
165-
my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
165+
my $editor = Git::command_oneline('var', 'GIT_EDITOR');
166+
166167
sub do_edit {
167168
if (defined($multiedit) && !$multiedit) {
168169
map {

git-sh-setup.sh

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,12 @@ set_reflog_action() {
9999
}
100100
101101
git_editor() {
102-
: "${GIT_EDITOR:=$(git config core.editor)}"
103-
: "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
104-
case "$GIT_EDITOR,$TERM" in
105-
,dumb)
106-
echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
107-
echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
108-
echo >&2 "Please set one of these variables to an appropriate"
109-
echo >&2 "editor or run $0 with options that will not cause an"
110-
echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
111-
exit 1
112-
;;
113-
esac
114-
eval "${GIT_EDITOR:=vi}" '"$@"'
102+
if test -z "${GIT_EDITOR:+set}"
103+
then
104+
GIT_EDITOR="$(git var GIT_EDITOR)" || return $?
105+
fi
106+
107+
eval "$GIT_EDITOR" '"$@"'
115108
}
116109
117110
is_bare_repository () {

git-svn.perl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,9 +1321,8 @@ sub get_commit_entry {
13211321
close $log_fh or croak $!;
13221322

13231323
if ($_edit || ($type eq 'tree')) {
1324-
my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';
1325-
# TODO: strip out spaces, comments, like git-commit.sh
1326-
system($editor, $commit_editmsg);
1324+
chomp(my $editor = command_oneline(qw(var GIT_EDITOR)));
1325+
system('sh', '-c', $editor.' "$@"', $editor, $commit_editmsg);
13271326
}
13281327
rename $commit_editmsg, $commit_msg or croak $!;
13291328
{

0 commit comments

Comments
 (0)