The order is supposed to be GIT_EDITOR, stgit.editor, core.editor,
VISUAL, EDITOR, vi. This patch makes it so.
Signed-off-by: Karl Hasselström <kha@treskal.com>
class EditorException(StgException):
pass
class EditorException(StgException):
pass
+def get_editor():
+ for editor in [os.environ.get('GIT_EDITOR'),
+ config.get('stgit.editor'), # legacy
+ config.get('core.editor'),
+ os.environ.get('VISUAL'),
+ os.environ.get('EDITOR'),
+ 'vi']:
+ if editor:
+ return editor
+
def call_editor(filename):
"""Run the editor on the specified filename."""
def call_editor(filename):
"""Run the editor on the specified filename."""
-
- # the editor
- editor = config.get('stgit.editor')
- if not editor:
- editor = os.environ.get('EDITOR', 'vi')
- editor += ' %s' % filename
-
- out.start('Invoking the editor: "%s"' % editor)
- err = os.system(editor)
+ cmd = '%s %s' % (get_editor(), filename)
+ out.start('Invoking the editor: "%s"' % cmd)
+ err = os.system(cmd)
if err:
raise EditorException, 'editor failed, exit code: %d' % err
out.done()
if err:
raise EditorException, 'editor failed, exit code: %d' % err
out.done()
-test_expect_failure 'Edit commit message interactively (vi)' '
+test_expect_success 'Edit commit message interactively (vi)' '
m=$(msg HEAD) &&
PATH=.:$PATH stg edit p2 &&
test "$(msg HEAD)" = "$m/vi"
m=$(msg HEAD) &&
PATH=.:$PATH stg edit p2 &&
test "$(msg HEAD)" = "$m/vi"
-test_expect_failure 'Edit commit message interactively (VISUAL)' '
+test_expect_success 'Edit commit message interactively (VISUAL)' '
m=$(msg HEAD) &&
VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
test "$(msg HEAD)" = "$m/e2"
'
mkeditor e3
m=$(msg HEAD) &&
VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
test "$(msg HEAD)" = "$m/e2"
'
mkeditor e3
-test_expect_failure 'Edit commit message interactively (core.editor)' '
+test_expect_success 'Edit commit message interactively (core.editor)' '
m=$(msg HEAD) &&
git config core.editor e3 &&
VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
m=$(msg HEAD) &&
git config core.editor e3 &&
VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
-test_expect_failure 'Edit commit message interactively (GIT_EDITOR)' '
+test_expect_success 'Edit commit message interactively (GIT_EDITOR)' '
m=$(msg HEAD) &&
GIT_EDITOR=./e5 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
test "$(msg HEAD)" = "$m/e5"
m=$(msg HEAD) &&
GIT_EDITOR=./e5 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&
test "$(msg HEAD)" = "$m/e5"
TZ=UTC
TERM=dumb
export LANG LC_ALL PAGER TERM TZ
TZ=UTC
TERM=dumb
export LANG LC_ALL PAGER TERM TZ
+unset EDITOR
+unset VISUAL
unset GIT_EDITOR
unset AUTHOR_DATE
unset AUTHOR_EMAIL
unset GIT_EDITOR
unset AUTHOR_DATE
unset AUTHOR_EMAIL
export GIT_MERGE_VERBOSITY
export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
export GIT_MERGE_VERBOSITY
export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
# Protect ourselves from common misconfiguration to export
GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
# Protect ourselves from common misconfiguration to export