Add commit.editor configuration variable
PATCH 1/1 Add commit.editor configuration variable
This variable lets you specify a different editor for editing commit messages. If commit.editor is not set, git-commit falls back to VISUAL, then EDITOR as before.
--- Documentation/git-commit.txt | 9 +++++---- git-commit.sh | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-)
Documentation/git-commit.txt +5 -4
@@ -244,10 +244,11 @@ on the Subject: line and the rest of the commit in the body. include::i18n.txt[] -ENVIRONMENT VARIABLES ---------------------- -The command specified by either the VISUAL or EDITOR environment -variables is used to edit the commit log message. +ENVIRONMENT AND CONFIGURATION VARIABLES +--------------------------------------- +The editor used to edit the commit log message will be chosen from the +commit.editor configuration variable, the VISUAL environment variable, or the +EDITOR environment variable (in that order). HOOKS -----
git-commit.sh +7 -6
@@ -544,18 +544,19 @@ fi case "$no_edit" in '') - case "${VISUAL:-$EDITOR},$TERM" in + commit_editor=$(git config commit.editor || echo ${VISUAL:-$EDITOR}) + case "$commit_editor,$TERM" in ,dumb) - echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined." - echo >&2 "Please supply the commit log message using either" - echo >&2 "-m or -F option. A boilerplate log message has" - echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG" + echo >&2 "Terminal is dumb but commit.editor, VISUAL, and EDITOR" + echo >&2 "are undefined. Please supply the commit log message" + echo >&2 "using either -m or -F option. A boilerplate log message" + echo >&2 "has been prepared in $GIT_DIR/COMMIT_EDITMSG" exit 1 ;; esac git-var GIT_AUTHOR_IDENT > /dev/null || die git-var GIT_COMMITTER_IDENT > /dev/null || die - ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG" + ${commit_editor:-vi} "$GIT_DIR/COMMIT_EDITMSG" ;; esac
Signature · 1 line
1.5.2.2.620.g42358-dirty
I do not think commit.editor is a good name. Wouldn't we want that customized editor for "git tag -a" as well? Probably core.editor would come nicely next to core.pager we already have.
Quoted 4 lines · Junio C Hamano
I do not think commit.editor is a good name. Wouldn't we want that customized editor for "git tag -a" as well? Probably core.editor would come nicely next to core.pager we already have.
I considered core.editor, but if it's an editor that is *only*
used for commit messages then that seems to be a too-general name, and something like core.commit_message_editor seemed far too long. Any suggestions?
I had forgotten about "git tag -a" -- I will add support for that
as well.
-Adam
Quoted 7 lines · Adam Roben
Quoted 4 lines · Junio C Hamano
I do not think commit.editor is a good name. Wouldn't we want that customized editor for "git tag -a" as well? Probably core.editor would come nicely next to core.pager we already have.
Quoted 7 lines
I considered core.editor, but if it's an editor that is *only*
used for commit messages then that seems to be a too-general name, and something like core.commit_message_editor seemed far too long. Any suggestions?I had forgotten about "git tag -a" -- I will add support for that
as well.
We only launch an editor for three reasons: commit messages, tag messages and git-rebase -i. If we were to ever add a new editor using thingy, odds are the user would want the same editor by default for that too.
So please, core.editor, and also use it in git-rebase--interactive.
Signature · 1 line
Shawn.
Quoted 6 lines · Shawn O. Pearce
We only launch an editor for three reasons: commit messages, tag messages and git-rebase -i. If we were to ever add a new editor using thingy, odds are the user would want the same editor by default for that too.
So please, core.editor, and also use it in git-rebase--interactive.
Ah, add "git-am -i" to the mix. Potentially, git-notes would use it as well.
Hi,
Quoted 11 lines · Junio C Hamano
Quoted 6 lines · Shawn O. Pearce
We only launch an editor for three reasons: commit messages, tag messages and git-rebase -i. If we were to ever add a new editor using thingy, odds are the user would want the same editor by default for that too.
So please, core.editor, and also use it in git-rebase--interactive.
Ah, add "git-am -i" to the mix. Potentially, git-notes would use it as well.
Now with so many commands in the lot, how about putting the code into git-sh-setup, into a function "get_editor()"?
Ciao,
Dscho
PATCH 1/1 Add git-sh-setup::set_editor()
This function can be used to set the GIT_EDITOR variable to the user's preferred editor.
---
Quoted 2 lines · Johannes Schindelin
Now with so many commands in the lot, how about putting the code into git-sh-setup, into a function "
get_editor()"?
Here you go. I didn't add anything similar for git-send-email.perl since that is the only case we have in perl of invoking the editor right now, and I wasn't sure of a good place to add such a function.
git-am.sh | 3 ++- git-commit.sh | 6 +++--- git-rebase--interactive.sh | 3 ++- git-sh-setup.sh | 5 +++++ git-tag.sh | 3 ++- 5 files changed, 14 insertions(+), 6 deletions(-)
git-am.sh +2 -1
@@ -7,6 +7,7 @@ USAGE='[--signoff] [--dotest=<dir>] [--utf8 | --no-utf8] [--binary] [--3way] or, when resuming [--skip | --resolved]' . git-sh-setup set_reflog_action am +set_editor require_work_tree git var GIT_COMMITTER_IDENT >/dev/null || exit
@@ -364,7 +365,7 @@ do [yY]*) action=yes ;; [aA]*) action=yes interactive= ;; [nN]*) action=skip ;; - [eE]*) "$(git config core.editor || echo ${VISUAL:-${EDITOR:-vi}})" "$dotest/final-commit" + [eE]*) "$GIT_EDITOR" "$dotest/final-commit" action=again ;; [vV]*) action=again LESS=-S ${PAGER:-less} "$dotest/patch" ;;
git-commit.sh +3 -3
@@ -6,6 +6,7 @@ USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]' SUBDIRECTORY_OK=Yes . git-sh-setup +set_editor require_work_tree git rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
@@ -544,8 +545,7 @@ fi case "$no_edit" in '') - commit_editor=$(git config core.editor || echo ${VISUAL:-$EDITOR}) - case "$commit_editor,$TERM" in + case "$GIT_EDITOR,$TERM" in ,dumb) echo >&2 "Terminal is dumb but core.editor, VISUAL, and EDITOR" echo >&2 "are undefined. Please supply the commit log message"
@@ -556,7 +556,7 @@ case "$no_edit" in esac git-var GIT_AUTHOR_IDENT > /dev/null || die git-var GIT_COMMITTER_IDENT > /dev/null || die - ${commit_editor:-vi} "$GIT_DIR/COMMIT_EDITMSG" + $GIT_EDITOR "$GIT_DIR/COMMIT_EDITMSG" ;; esac
git-rebase--interactive.sh +2 -1
@@ -15,6 +15,7 @@ USAGE='(--continue | --abort | --skip | [--preserve-merges] [--verbose] . git-sh-setup require_work_tree +set_editor DOTEST="$GIT_DIR/.dotest-merge" TODO="$DOTEST"/todo
@@ -414,7 +415,7 @@ EOF die_abort "Nothing to do" cp "$TODO" "$TODO".backup - $(git config core.editor || echo ${VISUAL:-${EDITOR:-vi}}) "$TODO" || + $GIT_EDITOR "$TODO" || die "Could not execute editor" test -z "$(grep -ve '^$' -e '^#' < $TODO)" &&
git-sh-setup.sh +5 -0
@@ -28,6 +28,11 @@ set_reflog_action() { fi } +set_editor() { + GIT_EDITOR=$(git config core.editor || echo ${VISUAL:-${EDITOR:-vi}}) + export GIT_EDITOR +} + is_bare_repository () { git rev-parse --is-bare-repository }
git-tag.sh +2 -1
@@ -4,6 +4,7 @@ USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]' SUBDIRECTORY_OK='Yes' . git-sh-setup +set_editor message_given= annotate=
@@ -177,7 +178,7 @@ if [ "$annotate" ]; then ( echo "#" echo "# Write a tag message" echo "#" ) > "$GIT_DIR"/TAG_EDITMSG - $(git config core.editor || echo ${VISUAL:-${EDITOR:-vi}}) "$GIT_DIR"/TAG_EDITMSG || exit + $GIT_EDITOR "$GIT_DIR"/TAG_EDITMSG || exit else printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG fi
Signature · 1 line
1.5.3.rc2.20.g8e32-dirty
Re: [PATCH] Add git-sh-setup::set_editor()
Hi,
Quoted 2 lines · Adam Roben
This function can be used to set the
GIT_EDITORvariable to the user's preferred editor.
Much nicer, thank you.
However,
git-commit.sh fi · line 549
Quoted 4 lines
git-commit.sh +1
-2- commit_editor=$(git config core.editor || echo ${VISUAL:-$EDITOR}) - case "$commit_editor,$TERM" in + case "$GIT_EDITOR,$TERM" in ,dumb)
This can no longer happen, since ...
git-sh-setup.sh set_reflog_action() { · line 34
Quoted 4 lines
git-sh-setup.sh +4
-0+set_editor() { + GIT_EDITOR=$(git config core.editor || echo ${VISUAL:-${EDITOR:-vi}}) + export GIT_EDITOR +}
... "vi" is the last resort, not "", right?
So I guess you just want to drag that test and warning into git-sh-setup (where I think it has a better home anyway).
Ciao,
Dscho
PATCH 1/1 Print an error when falling back to vi on a dumb terminal
---
Quoted 12 lines · Johannes Schindelin
Review
Quoted 4 lines
(quoted diff) +1
-2- commit_editor=$(git config core.editor || echo ${VISUAL:-$EDITOR}) - case "$commit_editor,$TERM" in + case "$GIT_EDITOR,$TERM" in ,dumb)This can no longer happen, since ...
Quoted 4 lines
+set_editor() {
+ GIT_EDITOR=$(git config core.editor || echo ${VISUAL:-${EDITOR:-vi}})
+ exportGIT_EDITOR
+}
Quoted 4 lines
... "vi" is the last resort, not "", right?
So I guess you just want to drag that test and warning into git-sh-setup (where I think it has a better home anyway).
Here you go. I'm not terribly happy with the error message, though. I tried to be as clear as possible and to keep some of the nice information that was in the git-commit error message. Please improve upon it if you can.
git-am.sh | 4 ++-- git-commit.sh | 11 +---------- git-rebase--interactive.sh | 2 +- git-sh-setup.sh | 15 +++++++++++++-- git-tag.sh | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-)
git-am.sh +2 -2
@@ -7,7 +7,6 @@ USAGE='[--signoff] [--dotest=<dir>] [--utf8 | --no-utf8] [--binary] [--3way] or, when resuming [--skip | --resolved]' . git-sh-setup set_reflog_action am -set_editor require_work_tree git var GIT_COMMITTER_IDENT >/dev/null || exit
@@ -365,7 +364,8 @@ do [yY]*) action=yes ;; [aA]*) action=yes interactive= ;; [nN]*) action=skip ;; - [eE]*) "$GIT_EDITOR" "$dotest/final-commit" + [eE]*) set_editor + "$GIT_EDITOR" "$dotest/final-commit" action=again ;; [vV]*) action=again LESS=-S ${PAGER:-less} "$dotest/patch" ;;
git-commit.sh +1 -10
@@ -6,7 +6,6 @@ USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]' SUBDIRECTORY_OK=Yes . git-sh-setup -set_editor require_work_tree git rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
@@ -545,15 +544,7 @@ fi case "$no_edit" in '') - case "$GIT_EDITOR,$TERM" in - ,dumb) - echo >&2 "Terminal is dumb but core.editor, VISUAL, and EDITOR" - echo >&2 "are undefined. Please supply the commit log message" - echo >&2 "using either -m or -F option. A boilerplate log message" - echo >&2 "has been prepared in $GIT_DIR/COMMIT_EDITMSG" - exit 1 - ;; - esac + set_editor git-var GIT_AUTHOR_IDENT > /dev/null || die git-var GIT_COMMITTER_IDENT > /dev/null || die $GIT_EDITOR "$GIT_DIR/COMMIT_EDITMSG"
git-rebase--interactive.sh +1 -1
@@ -15,7 +15,6 @@ USAGE='(--continue | --abort | --skip | [--preserve-merges] [--verbose] . git-sh-setup require_work_tree -set_editor DOTEST="$GIT_DIR/.dotest-merge" TODO="$DOTEST"/todo
@@ -415,6 +414,7 @@ EOF die_abort "Nothing to do" cp "$TODO" "$TODO".backup + set_editor $GIT_EDITOR "$TODO" || die "Could not execute editor"
git-sh-setup.sh +13 -2
@@ -29,8 +29,19 @@ set_reflog_action() { } set_editor() { - GIT_EDITOR=$(git config core.editor || echo ${VISUAL:-${EDITOR:-vi}}) - export GIT_EDITOR + GIT_EDITOR=$(git config core.editor || echo ${VISUAL:-${EDITOR}}) + case "$GIT_EDITOR,$TERM" in + ,dumb) + echo >&2 "No editor specified in core.editor, VISUAL, or EDITOR." + echo >&2 "Tried to fall back to vi but terminal is dumb." + echo >&2 "Please set one of these variables to an appropriate" + echo >&2 "editor or run $0 with options that will not cause an" + echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)." + exit 1 + ;; + esac + GIT_EDITOR=${GIT_EDITOR:-vi} + export GIT_EDITOR } is_bare_repository () {
git-tag.sh +1 -1
@@ -4,7 +4,6 @@ USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]' SUBDIRECTORY_OK='Yes' . git-sh-setup -set_editor message_given= annotate=
@@ -178,6 +177,7 @@ if [ "$annotate" ]; then ( echo "#" echo "# Write a tag message" echo "#" ) > "$GIT_DIR"/TAG_EDITMSG + set_editor $GIT_EDITOR "$GIT_DIR"/TAG_EDITMSG || exit else printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG
Signature · 1 line
1.5.3.rc2.21.gfc4a18-dirty
Re: [PATCH] Print an error when falling back to vi on a dumb terminal
Quoted 24 lines · Adam Roben
Here you go. I'm not terribly happy with the error message, though. I tried to be as clear as possible and to keep some of the nice information that was in the git-commit error message. Please improve upon it if you can.
git-am.sh | 4 ++-- git-commit.sh | 11 +---------- git-rebase--interactive.sh | 2 +- git-sh-setup.sh | 15 +++++++++++++-- git-tag.sh | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-)git-am.sh +0
-1@@ -7,7 +7,6 @@ USAGE='[--signoff] [--dotest=<dir>] [--utf8 | --no-utf8] [--binary] [--3way] or, when resuming [--skip | --resolved]' . git-sh-setup set_reflog_action am -set_editor require_work_tree git var GIT_COMMITTER_IDENT >/dev/null || exit
git-am.sh do · line 371
Quoted 9 lines
git-am.sh +2
-1@@ -365,7 +364,8 @@ do [yY]*) action=yes ;; [aA]*) action=yes interactive= ;; [nN]*) action=skip ;; - [eE]*) "$GIT_EDITOR" "$dotest/final-commit" + [eE]*) set_editor + "$GIT_EDITOR" "$dotest/final-commit" action=again ;; [vV]*) action=again LESS=-S ${PAGER:-less} "$dotest/patch" ;;
Sounds sane.
Could you please re-diff to make this into a single patch without intermediate "Oh, doing it this way is cleaner", and also with Dscho's Ack? I do not think we would need to have 3 commits for this topic --- it is not like wide userbase tested each iteration.
PATCH 1/1 Add core.editor configuration variable
This variable lets you specify an editor that will be launched in preference to the EDITOR and VISUAL environment variables.
---
Quoted 5 lines · Junio C Hamano
Could you please re-diff to make this into a single patch without intermediate "Oh, doing it this way is cleaner", and also with Dscho's Ack? I do not think we would need to have 3 commits for this topic --- it is not like wide userbase tested each iteration.
Documentation/git-commit.txt | 9 +++++---- Documentation/git-send-email.txt | 4 ++-- git-am.sh | 3 ++- git-commit.sh | 12 ++---------- git-rebase--interactive.sh | 3 ++- git-send-email.perl | 3 +-- git-sh-setup.sh | 16 ++++++++++++++++ git-tag.sh | 3 ++- 8 files changed, 32 insertions(+), 21 deletions(-)
Documentation/git-commit.txt +5 -4
@@ -244,10 +244,11 @@ on the Subject: line and the rest of the commit in the body. include::i18n.txt[] -ENVIRONMENT VARIABLES ---------------------- -The command specified by either the VISUAL or EDITOR environment -variables is used to edit the commit log message. +ENVIRONMENT AND CONFIGURATION VARIABLES +--------------------------------------- +The editor used to edit the commit log message will be chosen from the +core.editor configuration variable, the VISUAL environment variable, or the +EDITOR environment variable (in that order). HOOKS -----
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. value; if that is unspecified, default to --chain-reply-to. --compose:: - Use $EDITOR to edit an introductory message for the - patch series. + Use core.editor, $VISUAL, or $EDITOR to edit an introductory message + for the patch series. --from:: Specify the sender of the emails. This will default to
git-am.sh +2 -1
@@ -364,7 +364,8 @@ do [yY]*) action=yes ;; [aA]*) action=yes interactive= ;; [nN]*) action=skip ;; - [eE]*) "${VISUAL:-${EDITOR:-vi}}" "$dotest/final-commit" + [eE]*) set_editor + "$GIT_EDITOR" "$dotest/final-commit" action=again ;; [vV]*) action=again LESS=-S ${PAGER:-less} "$dotest/patch" ;;
git-commit.sh +2 -10
@@ -544,18 +544,10 @@ fi case "$no_edit" in '') - case "${VISUAL:-$EDITOR},$TERM" in - ,dumb) - echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined." - echo >&2 "Please supply the commit log message using either" - echo >&2 "-m or -F option. A boilerplate log message has" - echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG" - exit 1 - ;; - esac + set_editor git-var GIT_AUTHOR_IDENT > /dev/null || die git-var GIT_COMMITTER_IDENT > /dev/null || die - ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG" + $GIT_EDITOR "$GIT_DIR/COMMIT_EDITMSG" ;; esac
git-rebase--interactive.sh +2 -1
@@ -414,7 +414,8 @@ EOF die_abort "Nothing to do" cp "$TODO" "$TODO".backup - ${VISUAL:-${EDITOR:-vi}} "$TODO" || + set_editor + $GIT_EDITOR "$TODO" || die "Could not execute editor" test -z "$(grep -ve '^$' -e '^#' < $TODO)" &&
git-send-email.perl +1 -2
@@ -341,8 +341,7 @@ GIT: for the patch you are writing. EOT close(C); - my $editor = $ENV{EDITOR}; - $editor = 'vi' unless defined $editor; + my $editor = $repo->config("core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi"; system($editor, $compose_filename); open(C2,">",$compose_filename . ".final")
git-sh-setup.sh +16 -0
@@ -28,6 +28,22 @@ set_reflog_action() { fi } +set_editor() { + GIT_EDITOR=$(git config core.editor || echo ${VISUAL:-${EDITOR}}) + case "$GIT_EDITOR,$TERM" in + ,dumb) + echo >&2 "No editor specified in core.editor, VISUAL, or EDITOR." + echo >&2 "Tried to fall back to vi but terminal is dumb." + echo >&2 "Please set one of these variables to an appropriate" + echo >&2 "editor or run $0 with options that will not cause an" + echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)." + exit 1 + ;; + esac + GIT_EDITOR=${GIT_EDITOR:-vi} + export GIT_EDITOR +} + is_bare_repository () { git rev-parse --is-bare-repository }
git-tag.sh +2 -1
@@ -177,7 +177,8 @@ if [ "$annotate" ]; then ( echo "#" echo "# Write a tag message" echo "#" ) > "$GIT_DIR"/TAG_EDITMSG - ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit + set_editor + $GIT_EDITOR "$GIT_DIR"/TAG_EDITMSG || exit else printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG fi
Signature · 1 line
1.5.3.rc2.21.gfc4a18-dirty
PATCH 1/1 Add GIT_EDITOR environment variable and core.editor configuration variable
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.
---
This patch obsoletes all the previous ones I've sent for this change.
After discussing a bit with Junio and Shawn, this patch introduces git-sh-setup::git_editor() to handle invoking the editor. It also respects the GIT_EDITOR environment variable for overriding the choice of editor.
Hopefully this is the last version of this patch :-)
Documentation/git-commit.txt | 10 ++++++---- Documentation/git-send-email.txt | 4 ++-- git-am.sh | 2 +- git-commit.sh | 11 +---------- git-rebase--interactive.sh | 2 +- git-send-email.perl | 7 +++---- git-sh-setup.sh | 15 +++++++++++++++ git-tag.sh | 2 +- 8 files changed, 30 insertions(+), 23 deletions(-)
Documentation/git-commit.txt +6 -4
@@ -244,10 +244,12 @@ on the Subject: line and the rest of the commit in the body. include::i18n.txt[] -ENVIRONMENT VARIABLES ---------------------- -The command specified by either the VISUAL or EDITOR environment -variables is used to edit the commit log message. +ENVIRONMENT AND CONFIGURATION VARIABLES +--------------------------------------- +The editor used to edit the commit log message will be chosen from the +GIT_EDITOR environment variable, the core.editor configuration variable, the +VISUAL environment variable, or the EDITOR environment variable (in that +order). HOOKS -----
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. value; if that is unspecified, default to --chain-reply-to. --compose:: - Use $EDITOR to edit an introductory message for the - patch series. + Use $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an + introductory message for the patch series. --from:: Specify the sender of the emails. This will default to
git-am.sh +1 -1
@@ -364,7 +364,7 @@ do [yY]*) action=yes ;; [aA]*) action=yes interactive= ;; [nN]*) action=skip ;; - [eE]*) "${VISUAL:-${EDITOR:-vi}}" "$dotest/final-commit" + [eE]*) git_editor "$dotest/final-commit" action=again ;; [vV]*) action=again LESS=-S ${PAGER:-less} "$dotest/patch" ;;
git-commit.sh +1 -10
@@ -544,18 +544,9 @@ fi case "$no_edit" in '') - case "${VISUAL:-$EDITOR},$TERM" in - ,dumb) - echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined." - echo >&2 "Please supply the commit log message using either" - echo >&2 "-m or -F option. A boilerplate log message has" - echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG" - exit 1 - ;; - esac git-var GIT_AUTHOR_IDENT > /dev/null || die git-var GIT_COMMITTER_IDENT > /dev/null || die - ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG" + git_editor "$GIT_DIR/COMMIT_EDITMSG" ;; esac
git-rebase--interactive.sh +1 -1
@@ -414,7 +414,7 @@ EOF die_abort "Nothing to do" cp "$TODO" "$TODO".backup - ${VISUAL:-${EDITOR:-vi}} "$TODO" || + git_editor "$TODO" || die "Could not execute editor" test -z "$(grep -ve '^$' -e '^#' < $TODO)" &&
git-send-email.perl +3 -4
@@ -49,8 +49,8 @@ Options: --bcc Specify a list of email addresses that should be Bcc: on all the emails. - --compose Use \$EDITOR to edit an introductory message for the - patch series. + --compose Use \$GIT_EDITOR, core.editor, \$EDITOR, or \$VISUAL to edit + an introductory message for the patch series. --subject Specify the initial "Subject:" line. Only necessary if --compose is also set. If --compose
@@ -341,8 +341,7 @@ GIT: for the patch you are writing. EOT close(C); - my $editor = $ENV{EDITOR}; - $editor = 'vi' unless defined $editor; + my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi"; system($editor, $compose_filename); open(C2,">",$compose_filename . ".final")
git-sh-setup.sh +15 -0
@@ -28,6 +28,21 @@ set_reflog_action() { fi } +git_editor() { + GIT_EDITOR=${GIT_EDITOR:-$(git config core.editor || echo ${VISUAL:-${EDITOR}})} + case "$GIT_EDITOR,$TERM" in + ,dumb) + echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL," + echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb." + echo >&2 "Please set one of these variables to an appropriate" + echo >&2 "editor or run $0 with options that will not cause an" + echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)." + exit 1 + ;; + esac + "${GIT_EDITOR:-vi}" "$1" +} + is_bare_repository () { git rev-parse --is-bare-repository }
git-tag.sh +1 -1
@@ -177,7 +177,7 @@ if [ "$annotate" ]; then ( echo "#" echo "# Write a tag message" echo "#" ) > "$GIT_DIR"/TAG_EDITMSG - ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit + git_editor "$GIT_DIR"/TAG_EDITMSG || exit else printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG fi
Signature · 1 line
1.5.3.rc2.20.g2e098-dirty
Re: [PATCH] Print an error when falling back to vi on a dumb terminal
In reply to Adam RobenRe: [PATCH] Add git-sh-setup::set_editor()
In reply to Johannes SchindelinQuoted 16 lines · Johannes Schindelin
Quoted 2 lines · Adam Roben
This function can be used to set the
GIT_EDITORvariable to the user's preferred editor.Much nicer, thank you.
However,
git-commit.sh fi · line 549
Quoted 4 lines
git-commit.sh +1
-2- commit_editor=$(git config core.editor || echo ${VISUAL:-$EDITOR}) - case "$commit_editor,$TERM" in + case "$GIT_EDITOR,$TERM" in ,dumb)This can no longer happen, since ...
Quoted 4 lines
git-sh-setup.sh set_reflog_action() { · line 34
Quoted 4 lines
git-sh-setup.sh +4
-0+set_editor() { + GIT_EDITOR=$(git config core.editor || echo ${VISUAL:-${EDITOR:-vi}}) + export GIT_EDITOR +}
Strictly speaking it can happen when git has an empty string for core.editor configured. Not that the behavior chosen in this case would make any sense, but just for the record...
Signature · 1 line
David Kastrup