am -i, git-svn: use "git var GIT_PAGER"
[git/git.git] / t / t7005-editor.sh
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 #!$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
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?"
39 false
40 else
41 : happy
42 fi
43 '
44
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
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
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)" '
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
100
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
106
107 test_expect_success 'editor with a space' '
108
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)"
112
113 '
114
115 unset GIT_EDITOR
116 test_expect_success 'core.editor with a space' '
117
118 git config core.editor \"./e\ space.sh\" &&
119 git commit --amend &&
120 test space = "$(git show -s --pretty=format:%s)"
121
122 '
123
124 test_done