git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add commit.editor configuration variable
@ 2007-07-19  5:39 Adam Roben
  2007-07-19  6:08 ` Junio C Hamano
  0 siblings, 1 reply; 14+ messages in thread
From: Adam Roben @ 2007-07-19  5:39 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Adam Roben

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.

Signed-off-by: Adam Roben <aroben@apple.com>
---
 Documentation/git-commit.txt |    9 +++++----
 git-commit.sh                |   13 +++++++------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index f96142f..1a628be 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -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
 -----
diff --git a/git-commit.sh b/git-commit.sh
index 3f3de17..c4d8501 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -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
 
-- 
1.5.2.2.620.g42358-dirty

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] Add commit.editor configuration variable
  2007-07-19  5:39 [PATCH] Add commit.editor configuration variable Adam Roben
@ 2007-07-19  6:08 ` Junio C Hamano
  2007-07-19  6:17   ` Adam Roben
  0 siblings, 1 reply; 14+ messages in thread
From: Junio C Hamano @ 2007-07-19  6:08 UTC (permalink / raw)
  To: Adam Roben; +Cc: git

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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Add commit.editor configuration variable
  2007-07-19  6:08 ` Junio C Hamano
@ 2007-07-19  6:17   ` Adam Roben
  2007-07-19  6:23     ` Shawn O. Pearce
  0 siblings, 1 reply; 14+ messages in thread
From: Adam Roben @ 2007-07-19  6:17 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Jul 18, 2007, at 11:08 PM, Junio C Hamano wrote:

> 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Add commit.editor configuration variable
  2007-07-19  6:17   ` Adam Roben
@ 2007-07-19  6:23     ` Shawn O. Pearce
  2007-07-19  6:53       ` Junio C Hamano
  0 siblings, 1 reply; 14+ messages in thread
From: Shawn O. Pearce @ 2007-07-19  6:23 UTC (permalink / raw)
  To: Adam Roben; +Cc: Junio C Hamano, git

Adam Roben <aroben@apple.com> wrote:
> On Jul 18, 2007, at 11:08 PM, Junio C Hamano wrote:
> 
> >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.

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.

-- 
Shawn.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Add commit.editor configuration variable
  2007-07-19  6:23     ` Shawn O. Pearce
@ 2007-07-19  6:53       ` Junio C Hamano
  2007-07-19  9:54         ` Johannes Schindelin
  0 siblings, 1 reply; 14+ messages in thread
From: Junio C Hamano @ 2007-07-19  6:53 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Adam Roben, git

"Shawn O. Pearce" <spearce@spearce.org> writes:

> 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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Add commit.editor configuration variable
  2007-07-19  6:53       ` Junio C Hamano
@ 2007-07-19  9:54         ` Johannes Schindelin
  2007-07-19 18:24           ` [PATCH] Add git-sh-setup::set_editor() Adam Roben
  0 siblings, 1 reply; 14+ messages in thread
From: Johannes Schindelin @ 2007-07-19  9:54 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Shawn O. Pearce, Adam Roben, git

Hi,

On Wed, 18 Jul 2007, Junio C Hamano wrote:

> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] Add git-sh-setup::set_editor()
  2007-07-19  9:54         ` Johannes Schindelin
@ 2007-07-19 18:24           ` Adam Roben
  2007-07-19 18:46             ` Johannes Schindelin
  0 siblings, 1 reply; 14+ messages in thread
From: Adam Roben @ 2007-07-19 18:24 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Shindelin, Adam Roben

This function can be used to set the GIT_EDITOR variable to the user's
preferred editor.

Signed-off-by: Adam Roben <aroben@apple.com>
---
On Jul 19, 2007, at 2:54 AM, Johannes Schindelin wrote:
> 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(-)

diff --git a/git-am.sh b/git-am.sh
index 3a651ae..a5de0a1 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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" ;;
diff --git a/git-commit.sh b/git-commit.sh
index 72e4cf0..9adb03c 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -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
 
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 2e15abb..32d1f53 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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)" &&
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 4ed07e9..f43ab33 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -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
 }
diff --git a/git-tag.sh b/git-tag.sh
index 9aa30b4..0a6f2e7 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -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
-- 
1.5.3.rc2.20.g8e32-dirty

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] Add git-sh-setup::set_editor()
  2007-07-19 18:24           ` [PATCH] Add git-sh-setup::set_editor() Adam Roben
@ 2007-07-19 18:46             ` Johannes Schindelin
  2007-07-19 19:26               ` David Kastrup
  2007-07-19 21:10               ` [PATCH] Print an error when falling back to vi on a dumb terminal Adam Roben
  0 siblings, 2 replies; 14+ messages in thread
From: Johannes Schindelin @ 2007-07-19 18:46 UTC (permalink / raw)
  To: Adam Roben; +Cc: git, Junio C Hamano

Hi,

On Thu, 19 Jul 2007, Adam Roben wrote:

> This function can be used to set the GIT_EDITOR variable to the user's
> preferred editor.

Much nicer, thank you.

However,

> -	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 ...

> +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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Add git-sh-setup::set_editor()
  2007-07-19 18:46             ` Johannes Schindelin
@ 2007-07-19 19:26               ` David Kastrup
  2007-07-19 21:10               ` [PATCH] Print an error when falling back to vi on a dumb terminal Adam Roben
  1 sibling, 0 replies; 14+ messages in thread
From: David Kastrup @ 2007-07-19 19:26 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> On Thu, 19 Jul 2007, Adam Roben wrote:
>
>> This function can be used to set the GIT_EDITOR variable to the user's
>> preferred editor.
>
> Much nicer, thank you.
>
> However,
>
>> -	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 ...
>
>> +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...

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] Print an error when falling back to vi on a dumb terminal
  2007-07-19 18:46             ` Johannes Schindelin
  2007-07-19 19:26               ` David Kastrup
@ 2007-07-19 21:10               ` Adam Roben
  2007-07-19 21:19                 ` Johannes Schindelin
  2007-07-20  0:15                 ` Junio C Hamano
  1 sibling, 2 replies; 14+ messages in thread
From: Adam Roben @ 2007-07-19 21:10 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes.Schindelin, Adam Roben

Signed-off-by: Adam Roben <aroben@apple.com>
---
On Jul 19, 2007, at 11:46 AM, Johannes Schindelin wrote:

> > -       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 ...
> 
> >         +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).

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(-)

diff --git a/git-am.sh b/git-am.sh
index a5de0a1..dd517f4 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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" ;;
diff --git a/git-commit.sh b/git-commit.sh
index 9adb03c..4d5d898 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -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"
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 32d1f53..27f8639 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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"
 
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index f43ab33..dbc4833 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -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 () {
diff --git a/git-tag.sh b/git-tag.sh
index 0a6f2e7..f1a66d0 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -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
-- 
1.5.3.rc2.21.gfc4a18-dirty

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] Print an error when falling back to vi on a dumb terminal
  2007-07-19 21:10               ` [PATCH] Print an error when falling back to vi on a dumb terminal Adam Roben
@ 2007-07-19 21:19                 ` Johannes Schindelin
  2007-07-20  0:15                 ` Junio C Hamano
  1 sibling, 0 replies; 14+ messages in thread
From: Johannes Schindelin @ 2007-07-19 21:19 UTC (permalink / raw)
  To: Adam Roben; +Cc: git, Junio C Hamano

Hi,

On Thu, 19 Jul 2007, Adam Roben wrote:

> Signed-off-by: Adam Roben <aroben@apple.com>

Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

Thanks,
Dscho

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] Print an error when falling back to vi on a dumb terminal
  2007-07-19 21:10               ` [PATCH] Print an error when falling back to vi on a dumb terminal Adam Roben
  2007-07-19 21:19                 ` Johannes Schindelin
@ 2007-07-20  0:15                 ` Junio C Hamano
  2007-07-20  0:28                   ` [PATCH] Add core.editor configuration variable Adam Roben
  1 sibling, 1 reply; 14+ messages in thread
From: Junio C Hamano @ 2007-07-20  0:15 UTC (permalink / raw)
  To: Adam Roben; +Cc: git, Johannes.Schindelin

Adam Roben <aroben@apple.com> writes:

> 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(-)
>
> diff --git a/git-am.sh b/git-am.sh
> index a5de0a1..dd517f4 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -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" ;;

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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] Add core.editor configuration variable
  2007-07-20  0:15                 ` Junio C Hamano
@ 2007-07-20  0:28                   ` Adam Roben
  2007-07-20  5:09                     ` [PATCH] Add GIT_EDITOR environment variable and " Adam Roben
  0 siblings, 1 reply; 14+ messages in thread
From: Adam Roben @ 2007-07-20  0:28 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Adam Roben

This variable lets you specify an editor that will be launched in preference to
the EDITOR and VISUAL environment variables.

Signed-off-by: Adam Roben <aroben@apple.com>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
On Jul 19, 2007, at 5:15 PM, Junio C Hamano wrote:

> 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(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index f96142f..5caad56 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -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
 -----
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 293686c..e7723c9 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -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
diff --git a/git-am.sh b/git-am.sh
index e5e6f2c..dd517f4 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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" ;;
diff --git a/git-commit.sh b/git-commit.sh
index 3f3de17..4d5d898 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -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
 
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f395076..27f8639 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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)" &&
diff --git a/git-send-email.perl b/git-send-email.perl
index 7552cac..ad17b4e 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -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")
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 4ed07e9..dbc4833 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -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
 }
diff --git a/git-tag.sh b/git-tag.sh
index 1c25d88..f1a66d0 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -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
-- 
1.5.3.rc2.21.gfc4a18-dirty

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH] Add GIT_EDITOR environment variable and core.editor configuration variable
  2007-07-20  0:28                   ` [PATCH] Add core.editor configuration variable Adam Roben
@ 2007-07-20  5:09                     ` Adam Roben
  0 siblings, 0 replies; 14+ messages in thread
From: Adam Roben @ 2007-07-20  5:09 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Adam Roben

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.

Signed-off-by: Adam Roben <aroben@apple.com>
---
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(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index f96142f..8e0e7e2 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -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
 -----
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 293686c..d243ed1 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -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
diff --git a/git-am.sh b/git-am.sh
index e5e6f2c..bfd65dc 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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" ;;
diff --git a/git-commit.sh b/git-commit.sh
index 3f3de17..92749df 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -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
 
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f395076..a2d4d09 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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)" &&
diff --git a/git-send-email.perl b/git-send-email.perl
index 7552cac..a09b1c9 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -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")
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 4ed07e9..c51985e 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -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
 }
diff --git a/git-tag.sh b/git-tag.sh
index 1c25d88..5ee3f50 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -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
-- 
1.5.3.rc2.20.g2e098-dirty

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2007-07-20  5:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-19  5:39 [PATCH] Add commit.editor configuration variable Adam Roben
2007-07-19  6:08 ` Junio C Hamano
2007-07-19  6:17   ` Adam Roben
2007-07-19  6:23     ` Shawn O. Pearce
2007-07-19  6:53       ` Junio C Hamano
2007-07-19  9:54         ` Johannes Schindelin
2007-07-19 18:24           ` [PATCH] Add git-sh-setup::set_editor() Adam Roben
2007-07-19 18:46             ` Johannes Schindelin
2007-07-19 19:26               ` David Kastrup
2007-07-19 21:10               ` [PATCH] Print an error when falling back to vi on a dumb terminal Adam Roben
2007-07-19 21:19                 ` Johannes Schindelin
2007-07-20  0:15                 ` Junio C Hamano
2007-07-20  0:28                   ` [PATCH] Add core.editor configuration variable Adam Roben
2007-07-20  5:09                     ` [PATCH] Add GIT_EDITOR environment variable and " Adam Roben

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).