Advertise the ability to abort a commit
[git/jnareb-git.git] / t / t7502-commit.sh
blobf1112639b698faca38b2c8fc743e422d14dc15f6
1 #!/bin/sh
3 test_description='git commit porcelain-ish'
5 . ./test-lib.sh
7 test_expect_success 'the basics' '
9 echo doing partial >"commit is" &&
10 mkdir not &&
11 echo very much encouraged but we should >not/forbid &&
12 git add "commit is" not &&
13 echo update added "commit is" file >"commit is" &&
14 echo also update another >not/forbid &&
15 test_tick &&
16 git commit -a -m "initial with -a" &&
18 git cat-file blob HEAD:"commit is" >current.1 &&
19 git cat-file blob HEAD:not/forbid >current.2 &&
21 cmp current.1 "commit is" &&
22 cmp current.2 not/forbid
26 test_expect_success 'partial' '
28 echo another >"commit is" &&
29 echo another >not/forbid &&
30 test_tick &&
31 git commit -m "partial commit to handle a file" "commit is" &&
33 changed=$(git diff-tree --name-only HEAD^ HEAD) &&
34 test "$changed" = "commit is"
38 test_expect_success 'partial modification in a subdirecotry' '
40 test_tick &&
41 git commit -m "partial commit to subdirectory" not &&
43 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
44 test "$changed" = "not/forbid"
48 test_expect_success 'partial removal' '
50 git rm not/forbid &&
51 git commit -m "partial commit to remove not/forbid" not &&
53 changed=$(git diff-tree -r --name-only HEAD^ HEAD) &&
54 test "$changed" = "not/forbid" &&
55 remain=$(git ls-tree -r --name-only HEAD) &&
56 test "$remain" = "commit is"
60 test_expect_success 'sign off' '
62 >positive &&
63 git add positive &&
64 git commit -s -m "thank you" &&
65 actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") &&
66 expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") &&
67 test "z$actual" = "z$expected"
71 test_expect_success 'multiple -m' '
73 >negative &&
74 git add negative &&
75 git commit -m "one" -m "two" -m "three" &&
76 actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") &&
77 expected=$(echo one; echo; echo two; echo; echo three) &&
78 test "z$actual" = "z$expected"
82 test_expect_success 'verbose' '
84 echo minus >negative &&
85 git add negative &&
86 git status -v | sed -ne "/^diff --git /p" >actual &&
87 echo "diff --git a/negative b/negative" >expect &&
88 test_cmp expect actual
92 test_expect_success 'cleanup commit messages (verbatim,-t)' '
94 echo >>negative &&
95 { echo;echo "# text";echo; } >expect &&
96 git commit --cleanup=verbatim -t expect -a &&
97 git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual &&
98 test_cmp expect actual
102 test_expect_success 'cleanup commit messages (verbatim,-F)' '
104 echo >>negative &&
105 git commit --cleanup=verbatim -F expect -a &&
106 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
107 test_cmp expect actual
111 test_expect_success 'cleanup commit messages (verbatim,-m)' '
113 echo >>negative &&
114 git commit --cleanup=verbatim -m "$(cat expect)" -a &&
115 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
116 test_cmp expect actual
120 test_expect_success 'cleanup commit messages (whitespace,-F)' '
122 echo >>negative &&
123 { echo;echo "# text";echo; } >text &&
124 echo "# text" >expect &&
125 git commit --cleanup=whitespace -F text -a &&
126 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
127 test_cmp expect actual
131 test_expect_success 'cleanup commit messages (strip,-F)' '
133 echo >>negative &&
134 { echo;echo "# text";echo sample;echo; } >text &&
135 echo sample >expect &&
136 git commit --cleanup=strip -F text -a &&
137 git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
138 test_cmp expect actual
142 echo "sample
144 # Please enter the commit message for your changes.
145 # To abort the commit, use an empty commit message.
146 # (Comment lines starting with '#' will not be included)" >expect
148 test_expect_success 'cleanup commit messages (strip,-F,-e)' '
150 echo >>negative &&
151 { echo;echo sample;echo; } >text &&
152 git commit -e -F text -a &&
153 head -n 5 .git/COMMIT_EDITMSG >actual &&
154 test_cmp expect actual
158 echo "#
159 # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
160 #" >> expect
162 test_expect_success 'author different from committer' '
164 echo >>negative &&
165 git commit -e -m "sample"
166 head -n 8 .git/COMMIT_EDITMSG >actual &&
167 test_cmp expect actual
170 mv expect expect.tmp
171 sed '$d' < expect.tmp > expect
172 rm -f expect.tmp
173 echo "# Committer:
174 #" >> expect
176 test_expect_success 'committer is automatic' '
178 echo >>negative &&
180 unset GIT_COMMITTER_EMAIL
181 unset GIT_COMMITTER_NAME
182 # must fail because there is no change
183 test_must_fail git commit -e -m "sample"
184 ) &&
185 head -n 9 .git/COMMIT_EDITMSG | \
186 sed "s/^# Committer: .*/# Committer:/" >actual &&
187 test_cmp expect actual
190 pwd=`pwd`
191 cat >> .git/FAKE_EDITOR << EOF
192 #! /bin/sh
193 echo editor started > "$pwd/.git/result"
194 exit 0
196 chmod +x .git/FAKE_EDITOR
198 test_expect_success 'do not fire editor in the presence of conflicts' '
200 git clean -f &&
201 echo f >g &&
202 git add g &&
203 git commit -m "add g" &&
204 git branch second &&
205 echo master >g &&
206 echo g >h &&
207 git add g h &&
208 git commit -m "modify g and add h" &&
209 git checkout second &&
210 echo second >g &&
211 git add g &&
212 git commit -m second &&
213 # Must fail due to conflict
214 test_must_fail git cherry-pick -n master &&
215 echo "editor not started" >.git/result &&
217 GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" &&
218 export GIT_EDITOR &&
219 test_must_fail git commit
220 ) &&
221 test "$(cat .git/result)" = "editor not started"
224 pwd=`pwd`
225 cat >.git/FAKE_EDITOR <<EOF
226 #! $SHELL_PATH
227 # kill -TERM command added below.
230 test_expect_success 'a SIGTERM should break locks' '
231 echo >>negative &&
232 ! "$SHELL_PATH" -c '\''
233 echo kill -TERM $$ >> .git/FAKE_EDITOR
234 GIT_EDITOR=.git/FAKE_EDITOR
235 export GIT_EDITOR
236 exec git commit -a'\'' &&
237 test ! -f .git/index.lock
240 rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG
241 git reset -q --hard
243 test_expect_success 'Hand committing of a redundant merge removes dups' '
245 git rev-parse second master >expect &&
246 test_must_fail git merge second master &&
247 git checkout master g &&
248 EDITOR=: git commit -a &&
249 git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual &&
250 test_cmp expect actual
254 test_done