Make test scripts executable.
[git/git.git] / t / t7501-commit.sh
CommitLineData
12ace0b2
KH
1#!/bin/sh
2#
3# Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
4#
5
6# FIXME: Test the various index usages, -i and -o, test reflog,
7# signoff, hooks
8
9test_description='git-commit'
10. ./test-lib.sh
11
12test_tick
13
14test_expect_success \
15 "initial status" \
16 "echo 'bongo bongo' >file &&
17 git-add file && \
18 git-status | grep 'Initial commit'"
19
20test_expect_failure \
21 "fail initial amend" \
22 "git-commit --amend"
23
24test_expect_success \
25 "initial commit" \
26 "git-commit -m initial"
27
28test_expect_failure \
29 "invalid options 1" \
6d4bbebd 30 "git-commit -m foo -m bar -F file"
12ace0b2
KH
31
32test_expect_failure \
33 "invalid options 2" \
34 "git-commit -C HEAD -m illegal"
35
36test_expect_failure \
37 "using invalid commit with -C" \
38 "git-commit -C bogus"
39
40test_expect_failure \
41 "testing nothing to commit" \
42 "git-commit -m initial"
43
44test_expect_success \
45 "next commit" \
46 "echo 'bongo bongo bongo' >file \
47 git-commit -m next -a"
48
49test_expect_failure \
50 "commit message from non-existing file" \
51 "echo 'more bongo: bongo bongo bongo bongo' >file && \
52 git-commit -F gah -a"
53
54# Empty except stray tabs and spaces on a few lines.
55sed -e 's/@$//' >msg <<EOF
56 @
57
58 @
59Signed-off-by: hula
60EOF
61test_expect_failure \
62 "empty commit message" \
63 "git-commit -F msg -a"
64
65test_expect_success \
66 "commit message from file" \
67 "echo 'this is the commit message, coming from a file' >msg && \
68 git-commit -F msg -a"
69
70cat >editor <<\EOF
71#!/bin/sh
72sed -i -e "s/a file/an amend commit/g" $1
73EOF
74chmod 755 editor
75
76test_expect_success \
77 "amend commit" \
78 "VISUAL=./editor git-commit --amend"
79
80test_expect_failure \
6d4bbebd 81 "passing -m and -F" \
12ace0b2 82 "echo 'enough with the bongos' >file && \
6d4bbebd 83 git-commit -F msg -m amending ."
12ace0b2
KH
84
85test_expect_success \
86 "using message from other commit" \
87 "git-commit -C HEAD^ ."
88
89cat >editor <<\EOF
90#!/bin/sh
91sed -i -e "s/amend/older/g" $1
92EOF
93chmod 755 editor
94
95test_expect_success \
96 "editing message from other commit" \
97 "echo 'hula hula' >file && \
98 VISUAL=./editor git-commit -c HEAD^ -a"
99
100test_expect_success \
101 "message from stdin" \
102 "echo 'silly new contents' >file && \
103 echo commit message from stdin | git-commit -F - -a"
104
105test_expect_success \
106 "overriding author from command line" \
107 "echo 'gak' >file && \
108 git-commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a"
109
110test_expect_success \
111 "interactive add" \
112 "echo 7 | git-commit --interactive | grep 'What now'"
113
114test_expect_success \
115 "showing committed revisions" \
116 "git-rev-list HEAD >current"
117
118# We could just check the head sha1, but checking each commit makes it
119# easier to isolate bugs.
120
121cat >expected <<\EOF
12272c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
1239b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
1243536bbb352c3a1ef9a420f5b4242d48578b92aa7
125d381ac431806e53f3dd7ac2f1ae0534f36d738b9
1264fd44095ad6334f3ef72e4c5ec8ddf108174b54a
127402702b49136e7587daa9280e91e4bb7cb2179f7
128EOF
129
130test_expect_success \
131 'validate git-rev-list output.' \
132 'diff current expected'
133
cba8d489 134test_expect_success 'partial commit that involves removal (1)' '
64586e75
JH
135
136 git rm --cached file &&
137 mv file elif &&
138 git add elif &&
139 git commit -m "Partial: add elif" elif &&
140 git diff-tree --name-status HEAD^ HEAD >current &&
141 echo "A elif" >expected &&
142 diff expected current
143
144'
145
cba8d489 146test_expect_success 'partial commit that involves removal (2)' '
64586e75
JH
147
148 git commit -m "Partial: remove file" file &&
149 git diff-tree --name-status HEAD^ HEAD >current &&
150 echo "D file" >expected &&
151 diff expected current
152
153'
154
cba8d489
JH
155test_expect_success 'partial commit that involves removal (3)' '
156
157 git rm --cached elif &&
158 echo elif >elif &&
159 git commit -m "Partial: modify elif" elif &&
160 git diff-tree --name-status HEAD^ HEAD >current &&
161 echo "M elif" >expected &&
162 diff expected current
163
164'
165
12ace0b2 166test_done