3 # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
6 # FIXME: Test the various index usages, -i and -o, test reflog,
9 test_description
='git-commit'
16 "echo 'bongo bongo' >file &&
18 git-status | grep 'Initial commit'"
21 "fail initial amend" \
26 "git-commit -m initial"
30 "git-commit -m foo -m bar -F file"
34 "git-commit -C HEAD -m illegal"
37 "using paths with -a" \
38 "echo King of the bongo >file &&
39 git-commit -m foo -a file"
42 "using paths with --interactive" \
43 "echo bong-o-bong >file &&
44 echo 7 | git-commit -m foo --interactive file"
47 "using invalid commit with -C" \
51 "testing nothing to commit" \
52 "git-commit -m initial"
56 "echo 'bongo bongo bongo' >file \
57 git-commit -m next -a"
60 "commit message from non-existing file" \
61 "echo 'more bongo: bongo bongo bongo bongo' >file && \
64 # Empty except stray tabs and spaces on a few lines.
65 sed -e 's/@$//' >msg
<<EOF
72 "empty commit message" \
73 "git-commit -F msg -a"
76 "commit message from file" \
77 "echo 'this is the commit message, coming from a file' >msg && \
82 sed -i -e "s/a file/an amend commit/g" $1
88 "VISUAL=./editor git-commit --amend"
92 "echo 'enough with the bongos' >file && \
93 git-commit -F msg -m amending ."
96 "using message from other commit" \
97 "git-commit -C HEAD^ ."
101 sed -i -e "s/amend/older/g" $1
105 test_expect_success \
106 "editing message from other commit" \
107 "echo 'hula hula' >file && \
108 VISUAL=./editor git-commit -c HEAD^ -a"
110 test_expect_success \
111 "message from stdin" \
112 "echo 'silly new contents' >file && \
113 echo commit message from stdin | git-commit -F - -a"
115 test_expect_success \
116 "overriding author from command line" \
117 "echo 'gak' >file && \
118 git-commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a"
120 test_expect_success \
122 "echo 7 | git-commit --interactive | grep 'What now'"
124 test_expect_success \
125 "showing committed revisions" \
126 "git-rev-list HEAD >current"
128 # We could just check the head sha1, but checking each commit makes it
129 # easier to isolate bugs.
132 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca
133 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2
134 3536bbb352c3a1ef9a420f5b4242d48578b92aa7
135 d381ac431806e53f3dd7ac2f1ae0534f36d738b9
136 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a
137 402702b49136e7587daa9280e91e4bb7cb2179f7
140 test_expect_success \
141 'validate git-rev-list output.' \
142 'diff current expected'
144 test_expect_success
'partial commit that involves removal (1)' '
146 git rm --cached file &&
149 git commit -m "Partial: add elif" elif &&
150 git diff-tree --name-status HEAD^ HEAD >current &&
151 echo "A elif" >expected &&
152 diff expected current
156 test_expect_success
'partial commit that involves removal (2)' '
158 git commit -m "Partial: remove file" file &&
159 git diff-tree --name-status HEAD^ HEAD >current &&
160 echo "D file" >expected &&
161 diff expected current
165 test_expect_success
'partial commit that involves removal (3)' '
167 git rm --cached elif &&
169 git commit -m "Partial: modify elif" elif &&
170 git diff-tree --name-status HEAD^ HEAD >current &&
171 echo "M elif" >expected &&
172 diff expected current
176 author
="The Real Author <someguy@his.email.org>"
177 test_expect_success
'amend commit to fix author' '
179 oldtick=$GIT_AUTHOR_DATE &&
182 git cat-file -p HEAD |
183 sed -e "s/author.*/author $author $oldtick/" \
184 -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
186 git commit --amend --author="$author" &&
187 git cat-file -p HEAD > current &&
188 diff expected current
192 test_expect_success
'sign off (1)' '
196 git commit -s -m "thank you" &&
197 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
201 git var GIT_COMMITTER_IDENT |
202 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
204 diff -u expected actual
208 test_expect_success
'sign off (2)' '
212 existing="Signed-off-by: Watch This <watchthis@example.com>" &&
213 git commit -s -m "thank you
216 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
221 git var GIT_COMMITTER_IDENT |
222 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
224 diff -u expected actual
228 test_expect_success
'multiple -m' '
232 git commit -m "one" -m "two" -m "three" &&
233 git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
241 diff -u expected actual