git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH] Invoke the correct interactive editor
Date: Thu, 28 Aug 2008 02:19:43 +0200	[thread overview]
Message-ID: <20080828001843.5510.76140.stgit@yoghurt> (raw)

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>

---

 stgit/utils.py  |   22 +++++++++++++---------
 t/t3300-edit.sh |    8 ++++----
 t/test-lib.sh   |    5 ++---
 3 files changed, 19 insertions(+), 16 deletions(-)


diff --git a/stgit/utils.py b/stgit/utils.py
index 864975d..d1409cc 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -170,17 +170,21 @@ def rename(basedir, file1, file2):
 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."""
-
-    # 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()
diff --git a/t/t3300-edit.sh b/t/t3300-edit.sh
index 5c2d32e..ad3b23f 100755
--- a/t/t3300-edit.sh
+++ b/t/t3300-edit.sh
@@ -99,7 +99,7 @@ EOF
 }
 
 mkeditor vi
-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"
@@ -114,14 +114,14 @@ test_expect_success 'Edit commit message interactively (EDITOR)' '
 '
 
 mkeditor e2
-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
-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 &&
@@ -137,7 +137,7 @@ test_expect_success 'Edit commit message interactively (stgit.editor)' '
 '
 
 mkeditor e5
-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"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index ad8da68..c1fb1b3 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -14,8 +14,8 @@ PAGER=cat
 TZ=UTC
 TERM=dumb
 export LANG LC_ALL PAGER TERM TZ
-EDITOR=:
-VISUAL=:
+unset EDITOR
+unset VISUAL
 unset GIT_EDITOR
 unset AUTHOR_DATE
 unset AUTHOR_EMAIL
@@ -42,7 +42,6 @@ GIT_MERGE_VERBOSITY=5
 export GIT_MERGE_VERBOSITY
 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
-export EDITOR VISUAL
 GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
 
 # Protect ourselves from common misconfiguration to export

             reply	other threads:[~2008-08-28  0:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-28  0:19 Karl Hasselström [this message]
2008-08-30 22:16 ` [StGit PATCH] Invoke the correct interactive editor Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080828001843.5510.76140.stgit@yoghurt \
    --to=kha@treskal.com \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).