Merge branch 'fc/parseopt-config'
[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         echo "Edited by $i" >"\$1"
11         EOF
12         chmod +x e-$i.sh
13 done
14 unset vi
15 mv e-vi.sh vi
16 unset EDITOR VISUAL GIT_EDITOR
17
18 test_expect_success setup '
19
20         msg="Hand edited" &&
21         echo "$msg" >expect &&
22         git add vi &&
23         test_tick &&
24         git commit -m "$msg" &&
25         git show -s --pretty=oneline |
26         sed -e "s/^[0-9a-f]* //" >actual &&
27         diff actual expect
28
29 '
30
31 TERM=dumb
32 export TERM
33 test_expect_success 'dumb should error out when falling back on vi' '
34
35         if git commit --amend
36         then
37                 echo "Oops?"
38                 false
39         else
40                 : happy
41         fi
42 '
43
44 TERM=vt100
45 export TERM
46 for i in vi EDITOR VISUAL core_editor GIT_EDITOR
47 do
48         echo "Edited by $i" >expect
49         unset EDITOR VISUAL GIT_EDITOR
50         git config --unset-all core.editor
51         case "$i" in
52         core_editor)
53                 git config core.editor ./e-core_editor.sh
54                 ;;
55         [A-Z]*)
56                 eval "$i=./e-$i.sh"
57                 export $i
58                 ;;
59         esac
60         test_expect_success "Using $i" '
61                 git --exec-path=. commit --amend &&
62                 git show -s --pretty=oneline |
63                 sed -e "s/^[0-9a-f]* //" >actual &&
64                 diff actual expect
65         '
66 done
67
68 unset EDITOR VISUAL GIT_EDITOR
69 git config --unset-all core.editor
70 for i in vi EDITOR VISUAL core_editor GIT_EDITOR
71 do
72         echo "Edited by $i" >expect
73         case "$i" in
74         core_editor)
75                 git config core.editor ./e-core_editor.sh
76                 ;;
77         [A-Z]*)
78                 eval "$i=./e-$i.sh"
79                 export $i
80                 ;;
81         esac
82         test_expect_success "Using $i (override)" '
83                 git --exec-path=. commit --amend &&
84                 git show -s --pretty=oneline |
85                 sed -e "s/^[0-9a-f]* //" >actual &&
86                 diff actual expect
87         '
88 done
89
90 if ! echo 'echo space > "$1"' > "e space.sh"
91 then
92         say "Skipping; FS does not support spaces in filenames"
93         test_done
94         exit
95 fi
96
97 test_expect_success 'editor with a space' '
98
99         chmod a+x "e space.sh" &&
100         GIT_EDITOR="./e\ space.sh" git commit --amend &&
101         test space = "$(git show -s --pretty=format:%s)"
102
103 '
104
105 unset GIT_EDITOR
106 test_expect_success 'core.editor with a space' '
107
108         git config core.editor \"./e\ space.sh\" &&
109         git commit --amend &&
110         test space = "$(git show -s --pretty=format:%s)"
111
112 '
113
114 test_done