{"thread":{"id":"15235","subject":"[StGit PATCH] Invoke the correct interactive editor","startedAt":"2008-08-28T00:19:43Z","lastAt":"2008-08-30T22:16:11Z","messageCount":2,"participants":["Karl Hasselström","Catalin Marinas"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"88831","messageId":"20080828001843.5510.76140.stgit@yoghurt","threadId":"15235","inReplyTo":null,"subject":"[StGit PATCH] Invoke the correct interactive editor","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-28T00:19:43Z","receivedAt":"2008-08-28T00:19:43Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"The order is supposed to be GIT_EDITOR, stgit.editor, core.editor,\nVISUAL, EDITOR, vi. This patch makes it so.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n stgit/utils.py  |   22 +++++++++++++---------\n t/t3300-edit.sh |    8 ++++----\n t/test-lib.sh   |    5 ++---\n 3 files changed, 19 insertions(+), 16 deletions(-)\n\n\ndiff --git a/stgit/utils.py b/stgit/utils.py\nindex 864975d..d1409cc 100644\n--- a/stgit/utils.py\n+++ b/stgit/utils.py\n@@ -170,17 +170,21 @@ def rename(basedir, file1, file2):\n class EditorException(StgException):\n     pass\n \n+def get_editor():\n+    for editor in [os.environ.get('GIT_EDITOR'),\n+                   config.get('stgit.editor'), # legacy\n+                   config.get('core.editor'),\n+                   os.environ.get('VISUAL'),\n+                   os.environ.get('EDITOR'),\n+                   'vi']:\n+        if editor:\n+            return editor\n+\n def call_editor(filename):\n     \"\"\"Run the editor on the specified filename.\"\"\"\n-\n-    # the editor\n-    editor = config.get('stgit.editor')\n-    if not editor:\n-        editor = os.environ.get('EDITOR', 'vi')\n-    editor += ' %s' % filename\n-\n-    out.start('Invoking the editor: \"%s\"' % editor)\n-    err = os.system(editor)\n+    cmd = '%s %s' % (get_editor(), filename)\n+    out.start('Invoking the editor: \"%s\"' % cmd)\n+    err = os.system(cmd)\n     if err:\n         raise EditorException, 'editor failed, exit code: %d' % err\n     out.done()\ndiff --git a/t/t3300-edit.sh b/t/t3300-edit.sh\nindex 5c2d32e..ad3b23f 100755\n--- a/t/t3300-edit.sh\n+++ b/t/t3300-edit.sh\n@@ -99,7 +99,7 @@ EOF\n }\n \n mkeditor vi\n-test_expect_failure 'Edit commit message interactively (vi)' '\n+test_expect_success 'Edit commit message interactively (vi)' '\n     m=$(msg HEAD) &&\n     PATH=.:$PATH stg edit p2 &&\n     test \"$(msg HEAD)\" = \"$m/vi\"\n@@ -114,14 +114,14 @@ test_expect_success 'Edit commit message interactively (EDITOR)' '\n '\n \n mkeditor e2\n-test_expect_failure 'Edit commit message interactively (VISUAL)' '\n+test_expect_success 'Edit commit message interactively (VISUAL)' '\n     m=$(msg HEAD) &&\n     VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&\n     test \"$(msg HEAD)\" = \"$m/e2\"\n '\n \n mkeditor e3\n-test_expect_failure 'Edit commit message interactively (core.editor)' '\n+test_expect_success 'Edit commit message interactively (core.editor)' '\n     m=$(msg HEAD) &&\n     git config core.editor e3 &&\n     VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&\n@@ -137,7 +137,7 @@ test_expect_success 'Edit commit message interactively (stgit.editor)' '\n '\n \n mkeditor e5\n-test_expect_failure 'Edit commit message interactively (GIT_EDITOR)' '\n+test_expect_success 'Edit commit message interactively (GIT_EDITOR)' '\n     m=$(msg HEAD) &&\n     GIT_EDITOR=./e5 VISUAL=./e2 EDITOR=./e1 PATH=.:$PATH stg edit p2 &&\n     test \"$(msg HEAD)\" = \"$m/e5\"\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex ad8da68..c1fb1b3 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -14,8 +14,8 @@ PAGER=cat\n TZ=UTC\n TERM=dumb\n export LANG LC_ALL PAGER TERM TZ\n-EDITOR=:\n-VISUAL=:\n+unset EDITOR\n+unset VISUAL\n unset GIT_EDITOR\n unset AUTHOR_DATE\n unset AUTHOR_EMAIL\n@@ -42,7 +42,6 @@ GIT_MERGE_VERBOSITY=5\n export GIT_MERGE_VERBOSITY\n export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME\n export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n-export EDITOR VISUAL\n GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}\n \n # Protect ourselves from common misconfiguration to export\n"},{"id":"89271","messageId":"b0943d9e0808301516o71c073ai5d5f8833e004a8e2@mail.gmail.com","threadId":"15235","inReplyTo":"20080828001843.5510.76140.stgit@yoghurt","subject":"Re: [StGit PATCH] Invoke the correct interactive editor","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2008-08-30T22:16:11Z","receivedAt":"2008-08-30T22:16:11Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"2008/8/28 Karl Hasselström <kha@treskal.com>:\n> The order is supposed to be GIT_EDITOR, stgit.editor, core.editor,\n> VISUAL, EDITOR, vi. This patch makes it so.\n\nLooks OK. Thanks.\n\n-- \nCatalin\n"}]}