From: "Sean Allred via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Sean Allred <code@seanallred.com>, Sean Allred <allred.sean@gmail.com>
Subject: [PATCH] var: add GIT_SEQUENCE_EDITOR variable
Date: Sun, 20 Nov 2022 19:20:16 +0000 [thread overview]
Message-ID: <pull.1424.git.1668972017089.gitgitgadget@gmail.com> (raw)
From: Sean Allred <allred.sean@gmail.com>
Provides the same benefits to scripts as exposing GIT_EDITOR, but
allows distinguishing the 'sequence' editor from the 'core' editor.
See also 44fcb4977cbae67f4698306ccfe982420ceebcbf.
Signed-off-by: Sean Allred <allred.sean@gmail.com>
---
var: add GIT_SEQUENCE_EDITOR variable
In my case, I'm overriding the sequence editor in git rebase -i to do
some pre-processing on the todo file, but I'd still like to open up the
editor for further manipulation/verification of the todo steps. Just
using GIT_EDITOR here will clobber folks' expectations that their
custom-built sequence editor pops up (e.g. VSCode or Git Cola).
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1424%2Fvermiculus%2Fsa%2Fgit-var-sequence-editor-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1424/vermiculus/sa/git-var-sequence-editor-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1424
Documentation/git-var.txt | 7 +++++++
builtin/var.c | 11 +++++++++++
t/t0007-git-var.sh | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+)
diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
index 6aa521fab23..764a94b2a1f 100644
--- a/Documentation/git-var.txt
+++ b/Documentation/git-var.txt
@@ -49,6 +49,13 @@ ifdef::git-default-editor[]
The build you are using chose '{git-default-editor}' as the default.
endif::git-default-editor[]
+GIT_SEQUENCE_EDITOR::
+ Text editor for use by Git sequencer commands. Like `GIT_EDITOR`,
+ the value is meant to be interpreted by the shell when it is used.
+ The order of preference is the `$GIT_SEQUENCE_EDITOR` environment
+ variable, then `sequence.editor` configuration, and then the value
+ of `git var GIT_EDITOR`.
+
GIT_PAGER::
Text viewer for use by Git commands (e.g., 'less'). The value
is meant to be interpreted by the shell. The order of preference
diff --git a/builtin/var.c b/builtin/var.c
index 491db274292..9a2d31dc4aa 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -19,6 +19,16 @@ static const char *editor(int flag)
return pgm;
}
+static const char *sequence_editor(int flag)
+{
+ const char *pgm = git_sequence_editor();
+
+ if (!pgm && flag & IDENT_STRICT)
+ die("Terminal is dumb, but EDITOR unset");
+
+ return pgm;
+}
+
static const char *pager(int flag)
{
const char *pgm = git_pager(1);
@@ -41,6 +51,7 @@ static struct git_var git_vars[] = {
{ "GIT_COMMITTER_IDENT", git_committer_info },
{ "GIT_AUTHOR_IDENT", git_author_info },
{ "GIT_EDITOR", editor },
+ { "GIT_SEQUENCE_EDITOR", sequence_editor },
{ "GIT_PAGER", pager },
{ "GIT_DEFAULT_BRANCH", default_branch },
{ "", NULL },
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
index e56f4b9ac59..3199285fa7b 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -47,6 +47,44 @@ test_expect_success 'get GIT_DEFAULT_BRANCH with configuration' '
)
'
+test_expect_success 'get GIT_SEQUENCE_EDITOR without configuration' '
+ (
+ sane_unset GIT_SEQUENCE_EDITOR &&
+ git var GIT_EDITOR >expect &&
+ git var GIT_SEQUENCE_EDITOR >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration' '
+ test_config sequence.editor foo &&
+ (
+ sane_unset GIT_SEQUENCE_EDITOR &&
+ echo foo >expect &&
+ git var GIT_SEQUENCE_EDITOR >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'get GIT_SEQUENCE_EDITOR with environment variable' '
+ (
+ sane_unset GIT_SEQUENCE_EDITOR &&
+ echo bar >expect &&
+ GIT_SEQUENCE_EDITOR=bar git var GIT_SEQUENCE_EDITOR >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration and environment variable' '
+ test_config sequence.editor foo &&
+ (
+ sane_unset GIT_SEQUENCE_EDITOR &&
+ echo bar >expect &&
+ GIT_SEQUENCE_EDITOR=bar git var GIT_SEQUENCE_EDITOR >actual &&
+ test_cmp expect actual
+ )
+'
+
# For git var -l, we check only a representative variable;
# testing the whole output would make our test too brittle with
# respect to unrelated changes in the test suite's environment.
base-commit: a0789512c5a4ae7da935cd2e419f253cb3cb4ce7
--
gitgitgadget
next reply other threads:[~2022-11-20 19:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-20 19:20 Sean Allred via GitGitGadget [this message]
2022-11-21 8:09 ` [PATCH] var: add GIT_SEQUENCE_EDITOR variable Junio C Hamano
2022-11-23 12:21 ` Sean Allred
2022-12-17 23:09 ` [PATCH v2] " Sean Allred via GitGitGadget
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1424.git.1668972017089.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=allred.sean@gmail.com \
--cc=code@seanallred.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).