Merge branch 'tr/xsize-bits' into maint
[tgit.git] / t / t7005-editor.sh
blob26ddf9d496f6eacddbec603659be7fca3dff294b
1 #!/bin/sh
3 test_description='GIT_EDITOR, core.editor, and stuff'
5 . ./test-lib.sh
7 unset EDITOR VISUAL GIT_EDITOR
9 test_expect_success 'determine default editor' '
11 vi=$(TERM=vt100 git var GIT_EDITOR) &&
12 test -n "$vi"
16 if ! expr "$vi" : '[a-z]*$' >/dev/null
17 then
18 vi=
21 for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
23 cat >e-$i.sh <<-EOF
24 #!$SHELL_PATH
25 echo "Edited by $i" >"\$1"
26 EOF
27 chmod +x e-$i.sh
28 done
30 if ! test -z "$vi"
31 then
32 mv e-$vi.sh $vi
35 test_expect_success setup '
37 msg="Hand-edited" &&
38 test_commit "$msg" &&
39 echo "$msg" >expect &&
40 git show -s --format=%s > actual &&
41 test_cmp actual expect
45 TERM=dumb
46 export TERM
47 test_expect_success 'dumb should error out when falling back on vi' '
49 if git commit --amend
50 then
51 echo "Oops?"
52 false
53 else
54 : happy
58 test_expect_success 'dumb should prefer EDITOR to VISUAL' '
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"
68 TERM=vt100
69 export TERM
70 for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
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
79 [A-Z]*)
80 eval "$i=./e-$i.sh"
81 export $i
83 esac
84 test_expect_success "Using $i" '
85 git --exec-path=. commit --amend &&
86 git show -s --pretty=oneline |
87 sed -e "s/^[0-9a-f]* //" >actual &&
88 test_cmp actual expect
90 done
92 unset EDITOR VISUAL GIT_EDITOR
93 git config --unset-all core.editor
94 for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
96 echo "Edited by $i" >expect
97 case "$i" in
98 core_editor)
99 git config core.editor ./e-core_editor.sh
101 [A-Z]*)
102 eval "$i=./e-$i.sh"
103 export $i
105 esac
106 test_expect_success "Using $i (override)" '
107 git --exec-path=. commit --amend &&
108 git show -s --pretty=oneline |
109 sed -e "s/^[0-9a-f]* //" >actual &&
110 test_cmp actual expect
112 done
114 if ! echo 'echo space > "$1"' > "e space.sh"
115 then
116 skip_all="Skipping; FS does not support spaces in filenames"
117 test_done
120 test_expect_success 'editor with a space' '
122 chmod a+x "e space.sh" &&
123 GIT_EDITOR="./e\ space.sh" git commit --amend &&
124 test space = "$(git show -s --pretty=format:%s)"
128 unset GIT_EDITOR
129 test_expect_success 'core.editor with a space' '
131 git config core.editor \"./e\ space.sh\" &&
132 git commit --amend &&
133 test space = "$(git show -s --pretty=format:%s)"
137 test_done