Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 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, |
Wincent Colaiuta | 264474f | 2007-12-08 13:29:47 +0100 | [diff] [blame] | 7 | # signoff |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 8 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 9 | test_description='git commit' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 10 | . ./test-lib.sh |
| 11 | |
| 12 | test_tick |
| 13 | |
| 14 | test_expect_success \ |
| 15 | "initial status" \ |
| 16 | "echo 'bongo bongo' >file && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 17 | git add file && \ |
| 18 | git status | grep 'Initial commit'" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 19 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 20 | test_expect_success \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 21 | "fail initial amend" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 22 | "test_must_fail git commit --amend" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 23 | |
| 24 | test_expect_success \ |
| 25 | "initial commit" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 26 | "git commit -m initial" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 27 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 28 | test_expect_success \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 29 | "invalid options 1" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 30 | "test_must_fail git commit -m foo -m bar -F file" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 31 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 32 | test_expect_success \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 33 | "invalid options 2" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 34 | "test_must_fail git commit -C HEAD -m illegal" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 35 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 36 | test_expect_success \ |
Björn Steinbrink | 9d87442 | 2007-11-12 16:15:39 +0100 | [diff] [blame] | 37 | "using paths with -a" \ |
| 38 | "echo King of the bongo >file && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 39 | test_must_fail git commit -m foo -a file" |
Björn Steinbrink | 9d87442 | 2007-11-12 16:15:39 +0100 | [diff] [blame] | 40 | |
Jeff King | 1b19ccd | 2009-04-03 15:33:59 -0400 | [diff] [blame] | 41 | test_expect_success PERL \ |
Björn Steinbrink | 9d87442 | 2007-11-12 16:15:39 +0100 | [diff] [blame] | 42 | "using paths with --interactive" \ |
| 43 | "echo bong-o-bong >file && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 44 | ! (echo 7 | git commit -m foo --interactive file)" |
Björn Steinbrink | 9d87442 | 2007-11-12 16:15:39 +0100 | [diff] [blame] | 45 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 46 | test_expect_success \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 47 | "using invalid commit with -C" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 48 | "test_must_fail git commit -C bogus" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 49 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 50 | test_expect_success \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 51 | "testing nothing to commit" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 52 | "test_must_fail git commit -m initial" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 53 | |
| 54 | test_expect_success \ |
| 55 | "next commit" \ |
| 56 | "echo 'bongo bongo bongo' >file \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 57 | git commit -m next -a" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 58 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 59 | test_expect_success \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 60 | "commit message from non-existing file" \ |
| 61 | "echo 'more bongo: bongo bongo bongo bongo' >file && \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 62 | test_must_fail git commit -F gah -a" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 63 | |
| 64 | # Empty except stray tabs and spaces on a few lines. |
| 65 | sed -e 's/@$//' >msg <<EOF |
| 66 | @ |
| 67 | |
| 68 | @ |
| 69 | Signed-off-by: hula |
| 70 | EOF |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 71 | test_expect_success \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 72 | "empty commit message" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 73 | "test_must_fail git commit -F msg -a" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 74 | |
| 75 | test_expect_success \ |
| 76 | "commit message from file" \ |
| 77 | "echo 'this is the commit message, coming from a file' >msg && \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 78 | git commit -F msg -a" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 79 | |
| 80 | cat >editor <<\EOF |
| 81 | #!/bin/sh |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 82 | sed -e "s/a file/an amend commit/g" < "$1" > "$1-" |
| 83 | mv "$1-" "$1" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 84 | EOF |
| 85 | chmod 755 editor |
| 86 | |
| 87 | test_expect_success \ |
| 88 | "amend commit" \ |
Jonathan Nieder | d33738d | 2009-11-11 17:56:07 -0600 | [diff] [blame] | 89 | "EDITOR=./editor git commit --amend" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 90 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 91 | test_expect_success \ |
Junio C Hamano | 6d4bbeb | 2007-08-01 18:14:41 -0700 | [diff] [blame] | 92 | "passing -m and -F" \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 93 | "echo 'enough with the bongos' >file && \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 94 | test_must_fail git commit -F msg -m amending ." |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 95 | |
| 96 | test_expect_success \ |
| 97 | "using message from other commit" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 98 | "git commit -C HEAD^ ." |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 99 | |
| 100 | cat >editor <<\EOF |
| 101 | #!/bin/sh |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 102 | sed -e "s/amend/older/g" < "$1" > "$1-" |
| 103 | mv "$1-" "$1" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 104 | EOF |
| 105 | chmod 755 editor |
| 106 | |
| 107 | test_expect_success \ |
| 108 | "editing message from other commit" \ |
| 109 | "echo 'hula hula' >file && \ |
Jonathan Nieder | d33738d | 2009-11-11 17:56:07 -0600 | [diff] [blame] | 110 | EDITOR=./editor git commit -c HEAD^ -a" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 111 | |
| 112 | test_expect_success \ |
| 113 | "message from stdin" \ |
| 114 | "echo 'silly new contents' >file && \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 115 | echo commit message from stdin | git commit -F - -a" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 116 | |
| 117 | test_expect_success \ |
| 118 | "overriding author from command line" \ |
| 119 | "echo 'gak' >file && \ |
Jeff King | 49ff9a7 | 2010-01-13 12:39:51 -0500 | [diff] [blame] | 120 | git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1" |
| 121 | |
| 122 | test_expect_success \ |
| 123 | "commit --author output mentions author" \ |
| 124 | "grep Rubber.Duck output" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 125 | |
Jeff King | 1b19ccd | 2009-04-03 15:33:59 -0400 | [diff] [blame] | 126 | test_expect_success PERL \ |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 127 | "interactive add" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 128 | "echo 7 | git commit --interactive | grep 'What now'" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 129 | |
| 130 | test_expect_success \ |
| 131 | "showing committed revisions" \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 132 | "git rev-list HEAD >current" |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 133 | |
Adeodato Simó | 7eb5bbd | 2009-01-09 18:30:05 +0100 | [diff] [blame] | 134 | cat >editor <<\EOF |
| 135 | #!/bin/sh |
| 136 | sed -e "s/good/bad/g" < "$1" > "$1-" |
| 137 | mv "$1-" "$1" |
| 138 | EOF |
| 139 | chmod 755 editor |
| 140 | |
| 141 | cat >msg <<EOF |
| 142 | A good commit message. |
| 143 | EOF |
| 144 | |
| 145 | test_expect_success \ |
| 146 | 'editor not invoked if -F is given' ' |
| 147 | echo "moo" >file && |
Jonathan Nieder | d33738d | 2009-11-11 17:56:07 -0600 | [diff] [blame] | 148 | EDITOR=./editor git commit -a -F msg && |
Adeodato Simó | 7eb5bbd | 2009-01-09 18:30:05 +0100 | [diff] [blame] | 149 | git show -s --pretty=format:"%s" | grep -q good && |
| 150 | echo "quack" >file && |
Jonathan Nieder | d33738d | 2009-11-11 17:56:07 -0600 | [diff] [blame] | 151 | echo "Another good message." | EDITOR=./editor git commit -a -F - && |
Adeodato Simó | 7eb5bbd | 2009-01-09 18:30:05 +0100 | [diff] [blame] | 152 | git show -s --pretty=format:"%s" | grep -q good |
| 153 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 154 | # We could just check the head sha1, but checking each commit makes it |
| 155 | # easier to isolate bugs. |
| 156 | |
| 157 | cat >expected <<\EOF |
| 158 | 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca |
| 159 | 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2 |
| 160 | 3536bbb352c3a1ef9a420f5b4242d48578b92aa7 |
| 161 | d381ac431806e53f3dd7ac2f1ae0534f36d738b9 |
| 162 | 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a |
| 163 | 402702b49136e7587daa9280e91e4bb7cb2179f7 |
| 164 | EOF |
| 165 | |
| 166 | test_expect_success \ |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 167 | 'validate git rev-list output.' \ |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 168 | 'test_cmp expected current' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 169 | |
Junio C Hamano | db33af0 | 2007-09-14 16:53:58 -0700 | [diff] [blame] | 170 | test_expect_success 'partial commit that involves removal (1)' ' |
Junio C Hamano | 80bffaf | 2007-09-12 16:04:22 -0700 | [diff] [blame] | 171 | |
| 172 | git rm --cached file && |
| 173 | mv file elif && |
| 174 | git add elif && |
| 175 | git commit -m "Partial: add elif" elif && |
| 176 | git diff-tree --name-status HEAD^ HEAD >current && |
| 177 | echo "A elif" >expected && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 178 | test_cmp expected current |
Junio C Hamano | 80bffaf | 2007-09-12 16:04:22 -0700 | [diff] [blame] | 179 | |
| 180 | ' |
| 181 | |
Junio C Hamano | db33af0 | 2007-09-14 16:53:58 -0700 | [diff] [blame] | 182 | test_expect_success 'partial commit that involves removal (2)' ' |
Junio C Hamano | 80bffaf | 2007-09-12 16:04:22 -0700 | [diff] [blame] | 183 | |
| 184 | git commit -m "Partial: remove file" file && |
| 185 | git diff-tree --name-status HEAD^ HEAD >current && |
| 186 | echo "D file" >expected && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 187 | test_cmp expected current |
Junio C Hamano | 80bffaf | 2007-09-12 16:04:22 -0700 | [diff] [blame] | 188 | |
| 189 | ' |
| 190 | |
Junio C Hamano | db33af0 | 2007-09-14 16:53:58 -0700 | [diff] [blame] | 191 | test_expect_success 'partial commit that involves removal (3)' ' |
| 192 | |
| 193 | git rm --cached elif && |
| 194 | echo elif >elif && |
| 195 | git commit -m "Partial: modify elif" elif && |
| 196 | git diff-tree --name-status HEAD^ HEAD >current && |
| 197 | echo "M elif" >expected && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 198 | test_cmp expected current |
Junio C Hamano | db33af0 | 2007-09-14 16:53:58 -0700 | [diff] [blame] | 199 | |
| 200 | ' |
| 201 | |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 202 | author="The Real Author <someguy@his.email.org>" |
| 203 | test_expect_success 'amend commit to fix author' ' |
| 204 | |
| 205 | oldtick=$GIT_AUTHOR_DATE && |
| 206 | test_tick && |
| 207 | git reset --hard && |
| 208 | git cat-file -p HEAD | |
| 209 | sed -e "s/author.*/author $author $oldtick/" \ |
| 210 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ |
| 211 | expected && |
| 212 | git commit --amend --author="$author" && |
| 213 | git cat-file -p HEAD > current && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 214 | test_cmp expected current |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 215 | |
| 216 | ' |
| 217 | |
Miklos Vajna | 02b47cd | 2009-12-02 23:16:18 +0100 | [diff] [blame] | 218 | test_expect_success 'amend commit to fix date' ' |
| 219 | |
| 220 | test_tick && |
| 221 | newtick=$GIT_AUTHOR_DATE && |
| 222 | git reset --hard && |
| 223 | git cat-file -p HEAD | |
| 224 | sed -e "s/author.*/author $author $newtick/" \ |
| 225 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ |
| 226 | expected && |
| 227 | git commit --amend --date="$newtick" && |
| 228 | git cat-file -p HEAD > current && |
| 229 | test_cmp expected current |
| 230 | |
| 231 | ' |
| 232 | |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 233 | test_expect_success 'sign off (1)' ' |
| 234 | |
| 235 | echo 1 >positive && |
| 236 | git add positive && |
| 237 | git commit -s -m "thank you" && |
| 238 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && |
| 239 | ( |
| 240 | echo thank you |
| 241 | echo |
| 242 | git var GIT_COMMITTER_IDENT | |
| 243 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" |
| 244 | ) >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 245 | test_cmp expected actual |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 246 | |
| 247 | ' |
| 248 | |
| 249 | test_expect_success 'sign off (2)' ' |
| 250 | |
| 251 | echo 2 >positive && |
| 252 | git add positive && |
| 253 | existing="Signed-off-by: Watch This <watchthis@example.com>" && |
| 254 | git commit -s -m "thank you |
| 255 | |
| 256 | $existing" && |
| 257 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && |
| 258 | ( |
| 259 | echo thank you |
| 260 | echo |
| 261 | echo $existing |
| 262 | git var GIT_COMMITTER_IDENT | |
| 263 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" |
| 264 | ) >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 265 | test_cmp expected actual |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 266 | |
| 267 | ' |
| 268 | |
David Brown | c1e01b0 | 2009-10-28 10:13:44 -0700 | [diff] [blame] | 269 | test_expect_success 'signoff gap' ' |
| 270 | |
| 271 | echo 3 >positive && |
| 272 | git add positive && |
| 273 | alt="Alt-RFC-822-Header: Value" && |
| 274 | git commit -s -m "welcome |
| 275 | |
| 276 | $alt" && |
| 277 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && |
| 278 | ( |
| 279 | echo welcome |
| 280 | echo |
| 281 | echo $alt |
| 282 | git var GIT_COMMITTER_IDENT | |
| 283 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" |
| 284 | ) >expected && |
| 285 | test_cmp expected actual |
| 286 | ' |
| 287 | |
| 288 | test_expect_success 'signoff gap 2' ' |
| 289 | |
| 290 | echo 4 >positive && |
| 291 | git add positive && |
| 292 | alt="fixed: 34" && |
| 293 | git commit -s -m "welcome |
| 294 | |
| 295 | We have now |
| 296 | $alt" && |
| 297 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && |
| 298 | ( |
| 299 | echo welcome |
| 300 | echo |
| 301 | echo We have now |
| 302 | echo $alt |
| 303 | echo |
| 304 | git var GIT_COMMITTER_IDENT | |
| 305 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" |
| 306 | ) >expected && |
| 307 | test_cmp expected actual |
| 308 | ' |
| 309 | |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 310 | test_expect_success 'multiple -m' ' |
| 311 | |
| 312 | >negative && |
| 313 | git add negative && |
| 314 | git commit -m "one" -m "two" -m "three" && |
| 315 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && |
| 316 | ( |
| 317 | echo one |
| 318 | echo |
| 319 | echo two |
| 320 | echo |
| 321 | echo three |
| 322 | ) >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 323 | test_cmp expected actual |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 324 | |
| 325 | ' |
| 326 | |
Kristian Høgsberg | d63c2fd | 2007-11-02 11:33:06 -0400 | [diff] [blame] | 327 | author="The Real Author <someguy@his.email.org>" |
| 328 | test_expect_success 'amend commit to fix author' ' |
| 329 | |
| 330 | oldtick=$GIT_AUTHOR_DATE && |
| 331 | test_tick && |
| 332 | git reset --hard && |
| 333 | git cat-file -p HEAD | |
| 334 | sed -e "s/author.*/author $author $oldtick/" \ |
| 335 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ |
| 336 | expected && |
| 337 | git commit --amend --author="$author" && |
| 338 | git cat-file -p HEAD > current && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 339 | test_cmp expected current |
Kristian Høgsberg | d63c2fd | 2007-11-02 11:33:06 -0400 | [diff] [blame] | 340 | |
| 341 | ' |
Kristian Høgsberg | 1200993 | 2007-11-15 09:49:58 -0500 | [diff] [blame] | 342 | |
| 343 | test_expect_success 'git commit <file> with dirty index' ' |
| 344 | echo tacocat > elif && |
| 345 | echo tehlulz > chz && |
| 346 | git add chz && |
| 347 | git commit elif -m "tacocat is a palindrome" && |
| 348 | git show --stat | grep elif && |
| 349 | git diff --cached | grep chz |
| 350 | ' |
| 351 | |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 352 | test_expect_success 'same tree (single parent)' ' |
| 353 | |
Junio C Hamano | 31cbb5d | 2007-12-04 17:16:33 -0800 | [diff] [blame] | 354 | git reset --hard |
| 355 | |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 356 | if git commit -m empty |
| 357 | then |
| 358 | echo oops -- should have complained |
| 359 | false |
| 360 | else |
| 361 | : happy |
| 362 | fi |
| 363 | |
| 364 | ' |
| 365 | |
Junio C Hamano | 36863af | 2007-12-03 00:03:10 -0800 | [diff] [blame] | 366 | test_expect_success 'same tree (single parent) --allow-empty' ' |
| 367 | |
| 368 | git commit --allow-empty -m "forced empty" && |
| 369 | git cat-file commit HEAD | grep forced |
| 370 | |
| 371 | ' |
| 372 | |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 373 | test_expect_success 'same tree (merge and amend merge)' ' |
| 374 | |
| 375 | git checkout -b side HEAD^ && |
| 376 | echo zero >zero && |
| 377 | git add zero && |
| 378 | git commit -m "add zero" && |
| 379 | git checkout master && |
| 380 | |
| 381 | git merge -s ours side -m "empty ok" && |
| 382 | git diff HEAD^ HEAD >actual && |
| 383 | : >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 384 | test_cmp expected actual && |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 385 | |
| 386 | git commit --amend -m "empty really ok" && |
| 387 | git diff HEAD^ HEAD >actual && |
| 388 | : >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 389 | test_cmp expected actual |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 390 | |
| 391 | ' |
| 392 | |
Junio C Hamano | 1eb1e9e | 2007-12-14 11:57:22 -0800 | [diff] [blame] | 393 | test_expect_success 'amend using the message from another commit' ' |
| 394 | |
| 395 | git reset --hard && |
| 396 | test_tick && |
| 397 | git commit --allow-empty -m "old commit" && |
| 398 | old=$(git rev-parse --verify HEAD) && |
| 399 | test_tick && |
| 400 | git commit --allow-empty -m "new commit" && |
| 401 | new=$(git rev-parse --verify HEAD) && |
| 402 | test_tick && |
| 403 | git commit --allow-empty --amend -C "$old" && |
| 404 | git show --pretty="format:%ad %s" "$old" >expected && |
| 405 | git show --pretty="format:%ad %s" HEAD >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 406 | test_cmp expected actual |
Junio C Hamano | 1eb1e9e | 2007-12-14 11:57:22 -0800 | [diff] [blame] | 407 | |
| 408 | ' |
| 409 | |
Junio C Hamano | 8a2f873 | 2008-02-03 00:00:09 -0800 | [diff] [blame] | 410 | test_expect_success 'amend using the message from a commit named with tag' ' |
| 411 | |
| 412 | git reset --hard && |
| 413 | test_tick && |
| 414 | git commit --allow-empty -m "old commit" && |
| 415 | old=$(git rev-parse --verify HEAD) && |
| 416 | git tag -a -m "tag on old" tagged-old HEAD && |
| 417 | test_tick && |
| 418 | git commit --allow-empty -m "new commit" && |
| 419 | new=$(git rev-parse --verify HEAD) && |
| 420 | test_tick && |
| 421 | git commit --allow-empty --amend -C tagged-old && |
| 422 | git show --pretty="format:%ad %s" "$old" >expected && |
| 423 | git show --pretty="format:%ad %s" HEAD >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 424 | test_cmp expected actual |
Junio C Hamano | 8a2f873 | 2008-02-03 00:00:09 -0800 | [diff] [blame] | 425 | |
| 426 | ' |
| 427 | |
Thomas Rast | 6360d34 | 2010-03-12 18:04:34 +0100 | [diff] [blame] | 428 | test_expect_success 'amend can copy notes' ' |
| 429 | |
| 430 | git config notes.rewrite.amend true && |
| 431 | git config notes.rewriteRef "refs/notes/*" && |
| 432 | test_commit foo && |
| 433 | git notes add -m"a note" && |
| 434 | test_tick && |
| 435 | git commit --amend -m"new foo" && |
| 436 | test "$(git notes show)" = "a note" |
| 437 | |
| 438 | ' |
| 439 | |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 440 | test_done |