Skip to content

Commit 2ad150e

Browse files
vermiculusgitster
authored andcommitted
var: allow GIT_EDITOR to return null
The handling to die early when there is no EDITOR is valuable when used in normal code (i.e., editor.c). In git-var, where null/empty-string is a perfectly valid value to return, it doesn't make as much sense. Remove this handling from `git var GIT_EDITOR` so that it does not fail so noisily when there is no defined editor. Signed-off-by: Sean Allred <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 26b8abc commit 2ad150e

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

builtin/var.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ static const char var_usage[] = "git var (-l | <variable>)";
1111

1212
static const char *editor(int flag)
1313
{
14-
const char *pgm = git_editor();
15-
16-
if (!pgm && flag & IDENT_STRICT)
17-
die("Terminal is dumb, but EDITOR unset");
18-
19-
return pgm;
14+
return git_editor();
2015
}
2116

2217
static const char *pager(int flag)

t/t0007-git-var.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ test_description='basic sanity checks for git var'
55
TEST_PASSES_SANITIZE_LEAK=true
66
. ./test-lib.sh
77

8+
sane_unset_all_editors () {
9+
sane_unset GIT_EDITOR &&
10+
sane_unset VISUAL &&
11+
sane_unset EDITOR
12+
}
13+
814
test_expect_success 'get GIT_AUTHOR_IDENT' '
915
test_tick &&
1016
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
@@ -47,6 +53,62 @@ test_expect_success 'get GIT_DEFAULT_BRANCH with configuration' '
4753
)
4854
'
4955

56+
test_expect_success 'get GIT_EDITOR without configuration' '
57+
(
58+
sane_unset_all_editors &&
59+
test_expect_code 1 git var GIT_EDITOR >out &&
60+
test_must_be_empty out
61+
)
62+
'
63+
64+
test_expect_success 'get GIT_EDITOR with configuration' '
65+
test_config core.editor foo &&
66+
(
67+
sane_unset_all_editors &&
68+
echo foo >expect &&
69+
git var GIT_EDITOR >actual &&
70+
test_cmp expect actual
71+
)
72+
'
73+
74+
test_expect_success 'get GIT_EDITOR with environment variable GIT_EDITOR' '
75+
(
76+
sane_unset_all_editors &&
77+
echo bar >expect &&
78+
GIT_EDITOR=bar git var GIT_EDITOR >actual &&
79+
test_cmp expect actual
80+
)
81+
'
82+
83+
test_expect_success 'get GIT_EDITOR with environment variable EDITOR' '
84+
(
85+
sane_unset_all_editors &&
86+
echo bar >expect &&
87+
EDITOR=bar git var GIT_EDITOR >actual &&
88+
test_cmp expect actual
89+
)
90+
'
91+
92+
test_expect_success 'get GIT_EDITOR with configuration and environment variable GIT_EDITOR' '
93+
test_config core.editor foo &&
94+
(
95+
sane_unset_all_editors &&
96+
echo bar >expect &&
97+
GIT_EDITOR=bar git var GIT_EDITOR >actual &&
98+
test_cmp expect actual
99+
)
100+
'
101+
102+
test_expect_success 'get GIT_EDITOR with configuration and environment variable EDITOR' '
103+
test_config core.editor foo &&
104+
(
105+
sane_unset_all_editors &&
106+
echo foo >expect &&
107+
EDITOR=bar git var GIT_EDITOR >actual &&
108+
test_cmp expect actual
109+
)
110+
'
111+
50112
# For git var -l, we check only a representative variable;
51113
# testing the whole output would make our test too brittle with
52114
# respect to unrelated changes in the test suite's environment.

0 commit comments

Comments
 (0)