1 #!/bin/sh
3 test_description='GIT_EDITOR, core.editor, and stuff'
5 . ./test-lib.sh
7 for i in GIT_EDITOR core_editor EDITOR VISUAL vi
8 do
9 cat >e-$i.sh <<-EOF
10 #!$SHELL_PATH
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
17 unset EDITOR VISUAL GIT_EDITOR
19 test_expect_success setup '
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
30 '
32 TERM=dumb
33 export TERM
34 test_expect_success 'dumb should error out when falling back on vi' '
36 if git commit --amend
37 then
38 echo "Oops?"
39 false
40 else
41 : happy
42 fi
43 '
45 test_expect_success 'dumb should prefer EDITOR to VISUAL' '
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"
53 '
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" '
72 git --exec-path=. commit --amend &&
73 git show -s --pretty=oneline |
74 sed -e "s/^[0-9a-f]* //" >actual &&
75 diff actual expect
76 '
77 done
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)" '
94 git --exec-path=. commit --amend &&
95 git show -s --pretty=oneline |
96 sed -e "s/^[0-9a-f]* //" >actual &&
97 diff actual expect
98 '
99 done
101 if ! echo 'echo space > "$1"' > "e space.sh"
102 then
103 say "Skipping; FS does not support spaces in filenames"
104 test_done
105 fi
107 test_expect_success 'editor with a space' '
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)"
113 '
115 unset GIT_EDITOR
116 test_expect_success 'core.editor with a space' '
118 git config core.editor \"./e\ space.sh\" &&
119 git commit --amend &&
120 test space = "$(git show -s --pretty=format:%s)"
122 '
124 test_done