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