@@ -7,125 +7,96 @@ test_description='GIT_EDITOR, core.editor, and stuff'
7
7
unset EDITOR VISUAL GIT_EDITOR
8
8
9
9
test_expect_success ' determine default editor' '
10
-
11
10
vi=$(TERM=vt100 git var GIT_EDITOR) &&
12
11
test -n "$vi"
13
-
14
12
'
15
13
16
- if ! expr " $vi " : ' [a-z]*$' > /dev/null
17
- then
18
- vi=
19
- fi
20
-
21
- for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
22
- do
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
14
+ test_expect_success setup '
15
+ if ! expr "$vi" : "[a-z]*$" >/dev/null
16
+ then
17
+ vi=
18
+ fi &&
29
19
30
- if ! test -z " $vi "
31
- then
32
- mv e-$vi .sh $vi
33
- fi
20
+ for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
21
+ do
22
+ write_script e-$i.sh <<-EOF || return 1
23
+ echo "Edited by $i" >"\$1"
24
+ EOF
25
+ done &&
34
26
35
- test_expect_success setup '
27
+ if ! test -z "$vi"
28
+ then
29
+ mv e-$vi.sh $vi
30
+ fi &&
36
31
37
32
msg="Hand-edited" &&
38
33
test_commit "$msg" &&
39
- echo "$msg" >expect &&
40
- git show -s --format=%s > actual &&
41
- test_cmp expect actual
42
-
34
+ test_commit_message HEAD -m "$msg"
43
35
'
44
36
45
- TERM=dumb
46
- export TERM
47
37
test_expect_success ' dumb should error out when falling back on vi' '
48
-
49
- if git commit --amend
50
- then
51
- echo "Oops?"
52
- false
53
- else
54
- : happy
55
- fi
38
+ test_must_fail env TERM=dumb git commit --amend
56
39
'
57
40
58
41
test_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
-
42
+ TERM=dumb EDITOR=./e-EDITOR.sh VISUAL=./e-VISUAL.sh \
43
+ git commit --amend &&
44
+ test_commit_message HEAD -m "Edited by EDITOR"
66
45
'
67
46
68
- TERM=vt100
69
- export TERM
70
47
for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
71
48
do
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
49
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 expect actual
50
+ if test "$i" = core_editor
51
+ then
52
+ test_config core.editor ./e-core_editor.sh
53
+ fi &&
54
+ (
55
+ case "$i" in
56
+ [A-Z]*)
57
+ eval "$i=./e-$i.sh" &&
58
+ export $i
59
+ ;;
60
+ esac &&
61
+ PATH="$PWD:$PATH" TERM=vt100 git commit --amend
62
+ ) &&
63
+ test_commit_message HEAD -m "Edited by $i"
89
64
'
90
65
done
91
66
92
- unset EDITOR VISUAL GIT_EDITOR
93
- git config --unset-all core.editor
94
- for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
95
- do
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) " '
107
- git --exec-path=. commit --amend &&
108
- git show -s --pretty=oneline |
109
- sed -e "s/^[0-9a-f]* //" >actual &&
110
- test_cmp expect actual
111
- '
112
- done
67
+ test_expect_success ' Using editors with overrides ' '
68
+ (
69
+ TERM=vt100 &&
70
+ export TERM &&
71
+ for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
72
+ do
73
+ echo "Edited by $i" >expect &&
74
+ case "$i" in
75
+ core_editor)
76
+ git config core.editor ./e-core_editor.sh
77
+ ;;
78
+ [A-Z]*)
79
+ eval "$i=./e-$i.sh" &&
80
+ export $i
81
+ ;;
82
+ esac &&
83
+ PATH="$PWD:$PATH" git commit --amend &&
84
+ test_commit_message HEAD expect || exit 1
85
+ done
86
+ )
87
+ '
113
88
114
89
test_expect_success ' editor with a space' '
115
90
echo "echo space >\"\$1\"" >"e space.sh" &&
116
91
chmod a+x "e space.sh" &&
117
92
GIT_EDITOR="./e\ space.sh" git commit --amend &&
118
- test space = "$(git show -s --pretty=format:%s)"
119
-
93
+ test_commit_message HEAD -m space
120
94
'
121
95
122
- unset GIT_EDITOR
123
96
test_expect_success ' core.editor with a space' '
124
-
125
- git config core.editor \"./e\ space.sh\" &&
97
+ test_config core.editor \"./e\ space.sh\" &&
126
98
git commit --amend &&
127
- test space = "$(git show -s --pretty=format:%s)"
128
-
99
+ test_commit_message HEAD -m space
129
100
'
130
101
131
102
test_done
0 commit comments