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 <allred.sean@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sean Allred committed Nov 26, 2022 at 14:17 UTC 2ad150e35e52705a97f18bee08f34e00a6557d6f
2 files changed +63 -6
builtin/var.c
+1 -6
@@ -11,12 +11,7 @@ static const char var_usage[] = "git var (-l | <variable>)";
11
12 static const char *editor(int flag)
13 {
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();
15 }
16
17 static const char *pager(int flag)
t/t0007-git-var.sh
+62
@@ -5,6 +5,12 @@ test_description='basic sanity checks for git var'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 +sane_unset_all_editors () {
9 + sane_unset GIT_EDITOR &&
10 + sane_unset VISUAL &&
11 + sane_unset EDITOR
12 +}
13 +
14 test_expect_success 'get GIT_AUTHOR_IDENT' '
15 test_tick &&
16 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
@@ -47,6 +53,62 @@ test_expect_success 'get GIT_DEFAULT_BRANCH with configuration' '
53 )
54 '
55
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 +
112 # For git var -l, we check only a representative variable;
113 # testing the whole output would make our test too brittle with
114 # respect to unrelated changes in the test suite's environment.