threads / patch / 28704

patchAllow to specify the editor used for git rebase -i by config/environment var

Subject: [PATCH] Allow to specify the editor used for git rebase -i by config/environment var

## tl;dr

2 messages between Oct 17, 2011 and Oct 17, 2011. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Peter Oberndorfer· Oct 17, 2011, 20:26 UTC · lore

The search order for choosing the sequence editor is: $GIT_SEQUENCE_EDITOR git config sequence.editor git var GIT_EDITOR (default editor for commit messages)

With this change is it possible to have a separate (possibly graphical) editor that helps the user during a interactive rebase.

Using $GIT_EDITOR or core.editor config var for this is not possible since they is also used to start the commit message editor for reword action.

Signed-off-by: Peter Oberndorfer <kumbayo84@arcor.de>
---
I reworded the commit message and the config description a bit.
renamed to sequence.editor / $GIT_SEQUENCE_EDITOR
and moved the helper to git-rebase--interactive.sh
 Documentation/config.txt   |    7 +++++++
 git-rebase--interactive.sh |   15 ++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)
Show changes to 2 files +21 −1

Documentation/config.txt, git-rebase--interactive.sh

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 03296b7..048c5f9 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -473,6 +473,13 @@ core.editor::
 	variable when it is set, and the environment variable
 	`GIT_EDITOR` is not set.  See linkgit:git-var[1].
 
+sequence.editor::
+	Text editor used by git rebase -i for editing the rebase todo file.
+	The value is meant to be interpreted by the shell when it is used.
+	It can be overridden by the 'GIT_SEQUENCE_EDITOR' environment variable.
+	When not configured the default commit message editor is used instead.
+	See linkgit:git-var[1]
+
 core.pager::
 	The command that git will use to paginate output.  Can
 	be overridden with the `GIT_PAGER` environment
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 94f36c2..13a0661 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -161,6 +161,19 @@ do_with_author () {
 	)
 }
 
+git_sequence_editor() {
+	if test -z "${GIT_SEQUENCE_EDITOR:+set}"
+	then
+		GIT_SEQUENCE_EDITOR="$(git config sequence.editor)"
+		if [ -z "$GIT_SEQUENCE_EDITOR" ]
+		then
+			GIT_SEQUENCE_EDITOR="$(git var GIT_EDITOR)" || return $?
+		fi
+	fi
+
+	eval "$GIT_SEQUENCE_EDITOR" '"$@"'
+}
+
 pick_one () {
 	ff=--ff
 	case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
@@ -832,7 +845,7 @@ has_action "$todo" ||
 	die_abort "Nothing to do"
 
 cp "$todo" "$todo".backup
-git_editor "$todo" ||
+git_sequence_editor "$todo" ||
 	die_abort "Could not execute editor"
 
 has_action "$todo" ||
-- 
1.7.7.329.g2140c
Junio C Hamano· Oct 17, 2011, 21:36 UTC · re: Peter Oberndorfer · lore

Re: [PATCH] Allow to specify the editor used for git rebase -i by config/environment var

Peter Oberndorfer <kumbayo84@arcor.de> writes:
Show 11 quoted lines
> The search order for choosing the sequence editor is:
> $GIT_SEQUENCE_EDITOR
> git config sequence.editor
> git var GIT_EDITOR (default editor for commit messages)
>
> With this change is it possible to have a separate
> (possibly graphical) editor that helps the user
> during a interactive rebase.
>
> Using $GIT_EDITOR or core.editor config var for this is not possible
> since they is also used to start the commit message editor for reword action.

Thanks. I'll reword the proposed commit log message before queuing, because it won't make _any_ sense to talk about the search order before telling what these things that are searched would do, or why they are useful things to have.

    "rebase -i": support special-purpose editor to edit insn sheet
    The insn sheet used by "rebase -i" is designed to be easily editable by
    any text editor, but an editor that is specifically meant for it (but
    is otherwise unsuitable for editing regular text files) could be useful
    by allowing drag & drop reordering in a GUI environment, for example.
    The GIT_SEQUENCE_EDITOR environment variable and/or the sequence.editor
    configuration variable can be used to specify such an editor, while
    allowing the usual editor to be used to edit commit log messages. As
    usual, the environment variable takes precedence over the configuration
    variable.
    It is envisioned that other "sequencer" based tools will use the same
    mechanism.
    Signed-off-by: Peter Oberndorfer <kumbayo84@arcor.de>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

← back to recent threads