var: add GIT_SEQUENCE_EDITOR variable

The editor program used by Git when editing the sequencer "todo" file is determined by examining a few environment variables and also affected by configuration variables. Introduce "git var GIT_SEQUENCE_EDITOR" to give users access to the final result of the logic without having to know the exact details. This is very similar in spirit to 44fcb497 (Teach git var about GIT_EDITOR, 2009-11-11) that introduced "git var GIT_EDITOR". Signed-off-by: Sean Allred <allred.sean@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sean Allred committed Dec 17, 2022 at 23:09 UTC 4c3dd9304e49402bd4ee19dfaa4c21d0217fb582
3 files changed +52
Documentation/git-var.txt
+8
@@ -50,6 +50,14 @@ ifdef::git-default-editor[]
50 The build you are using chose '{git-default-editor}' as the default.
51 endif::git-default-editor[]
52
53 +GIT_SEQUENCE_EDITOR::
54 + Text editor used to edit the 'todo' file while running `git rebase
55 + -i`. Like `GIT_EDITOR`, the value is meant to be interpreted by
56 + the shell when it is used. The order of preference is the
57 + `$GIT_SEQUENCE_EDITOR` environment variable, then
58 + `sequence.editor` configuration, and then the value of `git var
59 + GIT_EDITOR`.
60 +
61 GIT_PAGER::
62 Text viewer for use by Git commands (e.g., 'less'). The value
63 is meant to be interpreted by the shell. The order of preference
builtin/var.c
+6
@@ -14,6 +14,11 @@ static const char *editor(int flag)
14 return git_editor();
15 }
16
17 +static const char *sequence_editor(int flag)
18 +{
19 + return git_sequence_editor();
20 +}
21 +
22 static const char *pager(int flag)
23 {
24 const char *pgm = git_pager(1);
@@ -36,6 +41,7 @@ static struct git_var git_vars[] = {
41 { "GIT_COMMITTER_IDENT", git_committer_info },
42 { "GIT_AUTHOR_IDENT", git_author_info },
43 { "GIT_EDITOR", editor },
44 + { "GIT_SEQUENCE_EDITOR", sequence_editor },
45 { "GIT_PAGER", pager },
46 { "GIT_DEFAULT_BRANCH", default_branch },
47 { "", NULL },
t/t0007-git-var.sh
+38
@@ -109,6 +109,44 @@ test_expect_success 'get GIT_EDITOR with configuration and environment variable
109 )
110 '
111
112 +test_expect_success 'get GIT_SEQUENCE_EDITOR without configuration' '
113 + (
114 + sane_unset GIT_SEQUENCE_EDITOR &&
115 + git var GIT_EDITOR >expect &&
116 + git var GIT_SEQUENCE_EDITOR >actual &&
117 + test_cmp expect actual
118 + )
119 +'
120 +
121 +test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration' '
122 + test_config sequence.editor foo &&
123 + (
124 + sane_unset GIT_SEQUENCE_EDITOR &&
125 + echo foo >expect &&
126 + git var GIT_SEQUENCE_EDITOR >actual &&
127 + test_cmp expect actual
128 + )
129 +'
130 +
131 +test_expect_success 'get GIT_SEQUENCE_EDITOR with environment variable' '
132 + (
133 + sane_unset GIT_SEQUENCE_EDITOR &&
134 + echo bar >expect &&
135 + GIT_SEQUENCE_EDITOR=bar git var GIT_SEQUENCE_EDITOR >actual &&
136 + test_cmp expect actual
137 + )
138 +'
139 +
140 +test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration and environment variable' '
141 + test_config sequence.editor foo &&
142 + (
143 + sane_unset GIT_SEQUENCE_EDITOR &&
144 + echo bar >expect &&
145 + GIT_SEQUENCE_EDITOR=bar git var GIT_SEQUENCE_EDITOR >actual &&
146 + test_cmp expect actual
147 + )
148 +'
149 +
150 # For git var -l, we check only a representative variable;
151 # testing the whole output would make our test too brittle with
152 # respect to unrelated changes in the test suite's environment.