@@ -7,62 +7,45 @@ test_description='GIT_EDITOR, core.editor, and stuff'
77unset EDITOR VISUAL GIT_EDITOR
88
99test_expect_success ' determine default editor' '
10-
1110 vi=$(TERM=vt100 git var GIT_EDITOR) &&
1211 test -n "$vi"
13-
1412'
1513
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 &&
2919
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 &&
3426
35- test_expect_success setup '
27+ if ! test -z "$vi"
28+ then
29+ mv e-$vi.sh $vi
30+ fi &&
3631
3732 msg="Hand-edited" &&
3833 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"
4335'
4436
4537TERM=dumb
4638export TERM
4739test_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
40+ test_must_fail git commit --amend
5641'
5742
5843test_expect_success ' dumb should prefer EDITOR to VISUAL' '
59-
6044 EDITOR=./e-EDITOR.sh &&
6145 VISUAL=./e-VISUAL.sh &&
6246 export EDITOR VISUAL &&
6347 git commit --amend &&
64- test "$(git show -s --format=%s)" = "Edited by EDITOR"
65-
48+ test_commit_message HEAD -m "Edited by EDITOR"
6649'
6750
6851TERM=vt100
8366 esac
8467 test_expect_success " Using $i " '
8568 git --exec-path=. commit --amend &&
86- git show -s --pretty=oneline |
87- sed -e "s/^[0-9a-f]* //" >actual &&
88- test_cmp expect actual
69+ test_commit_message HEAD expect
8970 '
9071done
9172
10586 esac
10687 test_expect_success " Using $i (override)" '
10788 git --exec-path=. commit --amend &&
108- git show -s --pretty=oneline |
109- sed -e "s/^[0-9a-f]* //" >actual &&
110- test_cmp expect actual
89+ test_commit_message HEAD expect
11190 '
11291done
11392
11493test_expect_success ' editor with a space' '
11594 echo "echo space >\"\$1\"" >"e space.sh" &&
11695 chmod a+x "e space.sh" &&
11796 GIT_EDITOR="./e\ space.sh" git commit --amend &&
118- test space = "$(git show -s --pretty=format:%s)"
119-
97+ test_commit_message HEAD -m space
12098'
12199
122100unset GIT_EDITOR
123101test_expect_success ' core.editor with a space' '
124-
125102 git config core.editor \"./e\ space.sh\" &&
126103 git commit --amend &&
127- test space = "$(git show -s --pretty=format:%s)"
128-
104+ test_commit_message HEAD -m space
129105'
130106
131107test_done
0 commit comments