]>
Commit | Line | Data |
---|---|---|
ef0c2abf AR |
1 | #!/bin/sh |
2 | ||
3 | test_description='GIT_EDITOR, core.editor, and stuff' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | for i in GIT_EDITOR core_editor EDITOR VISUAL vi | |
8 | do | |
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 | |
14 | done | |
15 | unset vi | |
16 | mv e-vi.sh vi | |
ef0c2abf AR |
17 | unset EDITOR VISUAL GIT_EDITOR |
18 | ||
19 | test_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 | ||
32 | TERM=dumb | |
33 | export TERM | |
34 | test_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 |
45 | test_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 |
55 | TERM=vt100 |
56 | export TERM | |
57 | for i in vi EDITOR VISUAL core_editor GIT_EDITOR | |
58 | do | |
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 | ' | |
77 | done | |
78 | ||
79 | unset EDITOR VISUAL GIT_EDITOR | |
80 | git config --unset-all core.editor | |
81 | for i in vi EDITOR VISUAL core_editor GIT_EDITOR | |
82 | do | |
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 | ' | |
99 | done | |
100 | ||
5b46a428 JS |
101 | if ! echo 'echo space > "$1"' > "e space.sh" |
102 | then | |
103 | say "Skipping; FS does not support spaces in filenames" | |
104 | test_done | |
5b46a428 JS |
105 | fi |
106 | ||
fc99469a JS |
107 | test_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 | ||
115 | unset GIT_EDITOR | |
116 | test_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 | 124 | test_done |