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