blob: b2ca77b3384c97954991eae9c5af89c4d8d8035e [file] [log] [blame]
Adam Robenef0c2ab2007-07-19 22:09:35 -07001#!/bin/sh
2
3test_description='GIT_EDITOR, core.editor, and stuff'
4
5. ./test-lib.sh
6
Jonathan Nieder8f4b5762009-10-30 20:44:41 -05007unset EDITOR VISUAL GIT_EDITOR
8
9test_expect_success 'determine default editor' '
10
11 vi=$(TERM=vt100 git var GIT_EDITOR) &&
12 test -n "$vi"
13
14'
15
Junio C Hamanoe0ae1e62010-06-21 11:18:54 -070016if ! expr "$vi" : '[a-z]*$' >/dev/null
Jonathan Nieder8f4b5762009-10-30 20:44:41 -050017then
18 vi=
19fi
20
21for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
Adam Robenef0c2ab2007-07-19 22:09:35 -070022do
23 cat >e-$i.sh <<-EOF
Johannes Sixt80f0e532009-03-25 12:48:30 +010024 #!$SHELL_PATH
Adam Robenef0c2ab2007-07-19 22:09:35 -070025 echo "Edited by $i" >"\$1"
26 EOF
27 chmod +x e-$i.sh
28done
Jonathan Nieder8f4b5762009-10-30 20:44:41 -050029
30if ! test -z "$vi"
31then
32 mv e-$vi.sh $vi
33fi
Adam Robenef0c2ab2007-07-19 22:09:35 -070034
35test_expect_success setup '
36
Jonathan Nieder8f4b5762009-10-30 20:44:41 -050037 msg="Hand-edited" &&
38 test_commit "$msg" &&
Adam Robenef0c2ab2007-07-19 22:09:35 -070039 echo "$msg" >expect &&
Jonathan Nieder8f4b5762009-10-30 20:44:41 -050040 git show -s --format=%s > actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -070041 test_cmp expect actual
Adam Robenef0c2ab2007-07-19 22:09:35 -070042
43'
44
45TERM=dumb
46export TERM
47test_expect_success 'dumb should error out when falling back on vi' '
48
49 if git commit --amend
50 then
51 echo "Oops?"
Junio C Hamano72638812007-12-22 19:14:33 -080052 false
Adam Robenef0c2ab2007-07-19 22:09:35 -070053 else
54 : happy
55 fi
56'
57
Jonathan Niederd33738d2009-11-11 17:56:07 -060058test_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
66'
67
Adam Robenef0c2ab2007-07-19 22:09:35 -070068TERM=vt100
69export TERM
Jonathan Nieder8f4b5762009-10-30 20:44:41 -050070for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
Adam Robenef0c2ab2007-07-19 22:09:35 -070071do
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 test_expect_success "Using $i" '
Björn Steinbrinke70f3202007-11-11 18:38:11 +010085 git --exec-path=. commit --amend &&
Adam Robenef0c2ab2007-07-19 22:09:35 -070086 git show -s --pretty=oneline |
87 sed -e "s/^[0-9a-f]* //" >actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -070088 test_cmp expect actual
Adam Robenef0c2ab2007-07-19 22:09:35 -070089 '
90done
91
92unset EDITOR VISUAL GIT_EDITOR
93git config --unset-all core.editor
Jonathan Nieder8f4b5762009-10-30 20:44:41 -050094for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
Adam Robenef0c2ab2007-07-19 22:09:35 -070095do
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)" '
Björn Steinbrinke70f3202007-11-11 18:38:11 +0100107 git --exec-path=. commit --amend &&
Adam Robenef0c2ab2007-07-19 22:09:35 -0700108 git show -s --pretty=oneline |
109 sed -e "s/^[0-9a-f]* //" >actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -0700110 test_cmp expect actual
Adam Robenef0c2ab2007-07-19 22:09:35 -0700111 '
112done
113
SZEDER Gábor4362da02018-05-14 12:28:12 +0200114test_expect_success 'editor with a space' '
115 echo "echo space >\$1" >"e space.sh" &&
Johannes Sixt5b46a422009-03-17 22:45:22 +0100116 chmod a+x "e space.sh" &&
117 GIT_EDITOR="./e\ space.sh" git commit --amend &&
118 test space = "$(git show -s --pretty=format:%s)"
Johannes Schindelinfc994692008-03-11 10:56:30 +0100119
120'
121
122unset GIT_EDITOR
SZEDER Gábor4362da02018-05-14 12:28:12 +0200123test_expect_success 'core.editor with a space' '
Johannes Schindelinfc994692008-03-11 10:56:30 +0100124
Johannes Sixt5b46a422009-03-17 22:45:22 +0100125 git config core.editor \"./e\ space.sh\" &&
126 git commit --amend &&
127 test space = "$(git show -s --pretty=format:%s)"
Johannes Schindelinfc994692008-03-11 10:56:30 +0100128
129'
130
Adam Robenef0c2ab2007-07-19 22:09:35 -0700131test_done