]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7005-editor.sh
Do not use VISUAL editor on dumb terminals
[thirdparty/git.git] / t / t7005-editor.sh
CommitLineData
ef0c2abf
AR
1#!/bin/sh
2
3test_description='GIT_EDITOR, core.editor, and stuff'
4
5. ./test-lib.sh
6
7for i in GIT_EDITOR core_editor EDITOR VISUAL vi
8do
9 cat >e-$i.sh <<-EOF
80f0e53d 10 #!$SHELL_PATH
ef0c2abf
AR
11 echo "Edited by $i" >"\$1"
12 EOF
13 chmod +x e-$i.sh
14done
15unset vi
16mv e-vi.sh vi
ef0c2abf
AR
17unset EDITOR VISUAL GIT_EDITOR
18
19test_expect_success setup '
20
21 msg="Hand edited" &&
22 echo "$msg" >expect &&
23 git add vi &&
24 test_tick &&
25 git commit -m "$msg" &&
26 git show -s --pretty=oneline |
27 sed -e "s/^[0-9a-f]* //" >actual &&
28 diff actual expect
29
30'
31
32TERM=dumb
33export TERM
34test_expect_success 'dumb should error out when falling back on vi' '
35
36 if git commit --amend
37 then
38 echo "Oops?"
72638812 39 false
ef0c2abf
AR
40 else
41 : happy
42 fi
43'
44
d33738d7
JN
45test_expect_success 'dumb should prefer EDITOR to VISUAL' '
46
47 EDITOR=./e-EDITOR.sh &&
48 VISUAL=./e-VISUAL.sh &&
49 export EDITOR VISUAL &&
50 git commit --amend &&
51 test "$(git show -s --format=%s)" = "Edited by EDITOR"
52
53'
54
ef0c2abf
AR
55TERM=vt100
56export TERM
57for i in vi EDITOR VISUAL core_editor GIT_EDITOR
58do
59 echo "Edited by $i" >expect
60 unset EDITOR VISUAL GIT_EDITOR
61 git config --unset-all core.editor
62 case "$i" in
63 core_editor)
64 git config core.editor ./e-core_editor.sh
65 ;;
66 [A-Z]*)
67 eval "$i=./e-$i.sh"
68 export $i
69 ;;
70 esac
71 test_expect_success "Using $i" '
e70f3202 72 git --exec-path=. commit --amend &&
ef0c2abf
AR
73 git show -s --pretty=oneline |
74 sed -e "s/^[0-9a-f]* //" >actual &&
75 diff actual expect
76 '
77done
78
79unset EDITOR VISUAL GIT_EDITOR
80git config --unset-all core.editor
81for i in vi EDITOR VISUAL core_editor GIT_EDITOR
82do
83 echo "Edited by $i" >expect
84 case "$i" in
85 core_editor)
86 git config core.editor ./e-core_editor.sh
87 ;;
88 [A-Z]*)
89 eval "$i=./e-$i.sh"
90 export $i
91 ;;
92 esac
93 test_expect_success "Using $i (override)" '
e70f3202 94 git --exec-path=. commit --amend &&
ef0c2abf
AR
95 git show -s --pretty=oneline |
96 sed -e "s/^[0-9a-f]* //" >actual &&
97 diff actual expect
98 '
99done
100
5b46a428
JS
101if ! echo 'echo space > "$1"' > "e space.sh"
102then
103 say "Skipping; FS does not support spaces in filenames"
104 test_done
5b46a428
JS
105fi
106
fc99469a
JS
107test_expect_success 'editor with a space' '
108
5b46a428
JS
109 chmod a+x "e space.sh" &&
110 GIT_EDITOR="./e\ space.sh" git commit --amend &&
111 test space = "$(git show -s --pretty=format:%s)"
fc99469a
JS
112
113'
114
115unset GIT_EDITOR
116test_expect_success 'core.editor with a space' '
117
5b46a428
JS
118 git config core.editor \"./e\ space.sh\" &&
119 git commit --amend &&
120 test space = "$(git show -s --pretty=format:%s)"
fc99469a
JS
121
122'
123
ef0c2abf 124test_done