The eleventh batch
[alt-git.git] / t / t7005-editor.sh
blobb9822294fedb7cf3d16d253853d92d274657916d
1 #!/bin/sh
3 test_description='GIT_EDITOR, core.editor, and stuff'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 unset EDITOR VISUAL GIT_EDITOR
10 test_expect_success 'determine default editor' '
12 vi=$(TERM=vt100 git var GIT_EDITOR) &&
13 test -n "$vi"
17 if ! expr "$vi" : '[a-z]*$' >/dev/null
18 then
19 vi=
22 for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
24 cat >e-$i.sh <<-EOF
25 #!$SHELL_PATH
26 echo "Edited by $i" >"\$1"
27 EOF
28 chmod +x e-$i.sh
29 done
31 if ! test -z "$vi"
32 then
33 mv e-$vi.sh $vi
36 test_expect_success setup '
38 msg="Hand-edited" &&
39 test_commit "$msg" &&
40 echo "$msg" >expect &&
41 git show -s --format=%s > actual &&
42 test_cmp expect actual
46 TERM=dumb
47 export TERM
48 test_expect_success 'dumb should error out when falling back on vi' '
50 if git commit --amend
51 then
52 echo "Oops?"
53 false
54 else
55 : happy
59 test_expect_success 'dumb should prefer EDITOR to VISUAL' '
61 EDITOR=./e-EDITOR.sh &&
62 VISUAL=./e-VISUAL.sh &&
63 export EDITOR VISUAL &&
64 git commit --amend &&
65 test "$(git show -s --format=%s)" = "Edited by EDITOR"
69 TERM=vt100
70 export TERM
71 for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
73 echo "Edited by $i" >expect
74 unset EDITOR VISUAL GIT_EDITOR
75 git config --unset-all core.editor
76 case "$i" in
77 core_editor)
78 git config core.editor ./e-core_editor.sh
80 [A-Z]*)
81 eval "$i=./e-$i.sh"
82 export $i
84 esac
85 test_expect_success "Using $i" '
86 git --exec-path=. commit --amend &&
87 git show -s --pretty=oneline |
88 sed -e "s/^[0-9a-f]* //" >actual &&
89 test_cmp expect actual
91 done
93 unset EDITOR VISUAL GIT_EDITOR
94 git config --unset-all core.editor
95 for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
97 echo "Edited by $i" >expect
98 case "$i" in
99 core_editor)
100 git config core.editor ./e-core_editor.sh
102 [A-Z]*)
103 eval "$i=./e-$i.sh"
104 export $i
106 esac
107 test_expect_success "Using $i (override)" '
108 git --exec-path=. commit --amend &&
109 git show -s --pretty=oneline |
110 sed -e "s/^[0-9a-f]* //" >actual &&
111 test_cmp expect actual
113 done
115 test_expect_success 'editor with a space' '
116 echo "echo space >\"\$1\"" >"e space.sh" &&
117 chmod a+x "e space.sh" &&
118 GIT_EDITOR="./e\ space.sh" git commit --amend &&
119 test space = "$(git show -s --pretty=format:%s)"
123 unset GIT_EDITOR
124 test_expect_success 'core.editor with a space' '
126 git config core.editor \"./e\ space.sh\" &&
127 git commit --amend &&
128 test space = "$(git show -s --pretty=format:%s)"
132 test_done