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 |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 11 | . "$TEST_DIRECTORY/diff-lib.sh" |
| 12 | |
| 13 | author='The Real Author <someguy@his.email.org>' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 14 | |
| 15 | test_tick |
| 16 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 17 | test_expect_success 'initial status' ' |
| 18 | echo bongo bongo >file && |
| 19 | git add file && |
Junio C Hamano | 32177ba | 2011-04-13 16:17:29 -0700 | [diff] [blame] | 20 | git status >actual && |
| 21 | test_i18ngrep "Initial commit" actual |
| 22 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 23 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 24 | test_expect_success 'fail initial amend' ' |
| 25 | test_must_fail git commit --amend |
| 26 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 27 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 28 | test_expect_success 'setup: initial commit' ' |
| 29 | git commit -m initial |
| 30 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 31 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 32 | test_expect_success '-m and -F do not mix' ' |
Junio C Hamano | c65dc35 | 2012-03-30 11:04:08 -0700 | [diff] [blame] | 33 | git checkout HEAD file && echo >>file && git add file && |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 34 | test_must_fail git commit -m foo -m bar -F file |
| 35 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 36 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 37 | test_expect_success '-m and -C do not mix' ' |
Junio C Hamano | c65dc35 | 2012-03-30 11:04:08 -0700 | [diff] [blame] | 38 | git checkout HEAD file && echo >>file && git add file && |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 39 | test_must_fail git commit -C HEAD -m illegal |
| 40 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 41 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 42 | test_expect_success 'paths and -a do not mix' ' |
| 43 | echo King of the bongo >file && |
| 44 | test_must_fail git commit -m foo -a file |
| 45 | ' |
Björn Steinbrink | 9d87442 | 2007-11-12 16:15:39 +0100 | [diff] [blame] | 46 | |
Conrad Irwin | e41fcfe | 2011-05-06 23:00:00 -0700 | [diff] [blame] | 47 | test_expect_success PERL 'can use paths with --interactive' ' |
Jeff King | 587ac8c | 2011-05-09 16:53:00 -0700 | [diff] [blame] | 48 | echo bong-o-bong >file && |
| 49 | # 2: update, 1:st path, that is all, 7: quit |
| 50 | ( echo 2; echo 1; echo; echo 7 ) | |
Conrad Irwin | e41fcfe | 2011-05-06 23:00:00 -0700 | [diff] [blame] | 51 | git commit -m foo --interactive file && |
| 52 | git reset --hard HEAD^ |
Jeff King | 587ac8c | 2011-05-09 16:53:00 -0700 | [diff] [blame] | 53 | ' |
Björn Steinbrink | 9d87442 | 2007-11-12 16:15:39 +0100 | [diff] [blame] | 54 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 55 | test_expect_success 'using invalid commit with -C' ' |
Kacper Kornet | 0bb0c15 | 2013-08-24 06:01:44 +0200 | [diff] [blame] | 56 | test_must_fail git commit --allow-empty -C bogus |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 57 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 58 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 59 | test_expect_success 'nothing to commit' ' |
Jeff King | 088304b | 2014-01-23 14:54:57 -0500 | [diff] [blame] | 60 | git reset --hard && |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 61 | test_must_fail git commit -m initial |
| 62 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 63 | |
Tay Ray Chuan | 9cbcc2a | 2014-02-22 03:16:54 +0800 | [diff] [blame] | 64 | test_expect_success '--dry-run fails with nothing to commit' ' |
| 65 | test_must_fail git commit -m initial --dry-run |
| 66 | ' |
| 67 | |
| 68 | test_expect_success '--short fails with nothing to commit' ' |
| 69 | test_must_fail git commit -m initial --short |
| 70 | ' |
| 71 | |
| 72 | test_expect_success '--porcelain fails with nothing to commit' ' |
| 73 | test_must_fail git commit -m initial --porcelain |
| 74 | ' |
| 75 | |
| 76 | test_expect_success '--long fails with nothing to commit' ' |
| 77 | test_must_fail git commit -m initial --long |
| 78 | ' |
| 79 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 80 | test_expect_success 'setup: non-initial commit' ' |
| 81 | echo bongo bongo bongo >file && |
| 82 | git commit -m next -a |
| 83 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 84 | |
Tay Ray Chuan | 9cbcc2a | 2014-02-22 03:16:54 +0800 | [diff] [blame] | 85 | test_expect_success '--dry-run with stuff to commit returns ok' ' |
| 86 | echo bongo bongo bongo >>file && |
| 87 | git commit -m next -a --dry-run |
| 88 | ' |
| 89 | |
| 90 | test_expect_failure '--short with stuff to commit returns ok' ' |
| 91 | echo bongo bongo bongo >>file && |
| 92 | git commit -m next -a --short |
| 93 | ' |
| 94 | |
| 95 | test_expect_failure '--porcelain with stuff to commit returns ok' ' |
| 96 | echo bongo bongo bongo >>file && |
| 97 | git commit -m next -a --porcelain |
| 98 | ' |
| 99 | |
| 100 | test_expect_success '--long with stuff to commit returns ok' ' |
| 101 | echo bongo bongo bongo >>file && |
| 102 | git commit -m next -a --long |
| 103 | ' |
| 104 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 105 | test_expect_success 'commit message from non-existing file' ' |
| 106 | echo more bongo: bongo bongo bongo bongo >file && |
| 107 | test_must_fail git commit -F gah -a |
| 108 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 109 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 110 | test_expect_success 'empty commit message' ' |
| 111 | # Empty except stray tabs and spaces on a few lines. |
| 112 | sed -e "s/@//g" >msg <<-\EOF && |
| 113 | @ @ |
| 114 | @@ |
| 115 | @ @ |
| 116 | @Signed-off-by: hula@ |
| 117 | EOF |
| 118 | test_must_fail git commit -F msg -a |
| 119 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 120 | |
Junio C Hamano | 010c7db | 2012-03-30 11:30:59 -0700 | [diff] [blame] | 121 | test_expect_success 'template "emptyness" check does not kick in with -F' ' |
| 122 | git checkout HEAD file && echo >>file && git add file && |
| 123 | git commit -t file -F file |
| 124 | ' |
| 125 | |
Junio C Hamano | b2eda9b | 2012-03-30 12:14:33 -0700 | [diff] [blame] | 126 | test_expect_success 'template "emptyness" check' ' |
| 127 | git checkout HEAD file && echo >>file && git add file && |
| 128 | test_must_fail git commit -t file 2>err && |
| 129 | test_i18ngrep "did not edit" err |
| 130 | ' |
| 131 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 132 | test_expect_success 'setup: commit message from file' ' |
Junio C Hamano | 010c7db | 2012-03-30 11:30:59 -0700 | [diff] [blame] | 133 | git checkout HEAD file && echo >>file && git add file && |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 134 | echo this is the commit message, coming from a file >msg && |
| 135 | git commit -F msg -a |
| 136 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 137 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 138 | test_expect_success 'amend commit' ' |
| 139 | cat >editor <<-\EOF && |
| 140 | #!/bin/sh |
| 141 | sed -e "s/a file/an amend commit/g" < "$1" > "$1-" |
| 142 | mv "$1-" "$1" |
| 143 | EOF |
| 144 | chmod 755 editor && |
| 145 | EDITOR=./editor git commit --amend |
| 146 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 147 | |
Jeff King | ea2d4ed | 2012-07-10 16:40:29 -0400 | [diff] [blame] | 148 | test_expect_success 'amend --only ignores staged contents' ' |
| 149 | cp file file.expect && |
| 150 | echo changed >file && |
| 151 | git add file && |
| 152 | git commit --no-edit --amend --only && |
| 153 | git cat-file blob HEAD:file >file.actual && |
| 154 | test_cmp file.expect file.actual && |
| 155 | git diff --exit-code |
| 156 | ' |
| 157 | |
Andreas Krey | 319d835 | 2016-12-02 23:15:13 +0100 | [diff] [blame] | 158 | test_expect_success 'allow-empty --only ignores staged contents' ' |
| 159 | echo changed-again >file && |
| 160 | git add file && |
| 161 | git commit --allow-empty --only -m "empty" && |
| 162 | git cat-file blob HEAD:file >file.actual && |
| 163 | test_cmp file.expect file.actual && |
| 164 | git diff --exit-code |
| 165 | ' |
| 166 | |
Jonathan Nieder | bc82189 | 2011-12-07 08:54:14 -0600 | [diff] [blame] | 167 | test_expect_success 'set up editor' ' |
| 168 | cat >editor <<-\EOF && |
| 169 | #!/bin/sh |
| 170 | sed -e "s/unamended/amended/g" <"$1" >"$1-" |
| 171 | mv "$1-" "$1" |
| 172 | EOF |
| 173 | chmod 755 editor |
| 174 | ' |
| 175 | |
| 176 | test_expect_success 'amend without launching editor' ' |
| 177 | echo unamended >expect && |
| 178 | git commit --allow-empty -m "unamended" && |
| 179 | echo needs more bongo >file && |
| 180 | git add file && |
| 181 | EDITOR=./editor git commit --no-edit --amend && |
| 182 | git diff --exit-code HEAD -- file && |
| 183 | git diff-tree -s --format=%s HEAD >msg && |
| 184 | test_cmp expect msg |
| 185 | ' |
| 186 | |
| 187 | test_expect_success '--amend --edit' ' |
| 188 | echo amended >expect && |
| 189 | git commit --allow-empty -m "unamended" && |
| 190 | echo bongo again >file && |
| 191 | git add file && |
| 192 | EDITOR=./editor git commit --edit --amend && |
| 193 | git diff-tree -s --format=%s HEAD >msg && |
| 194 | test_cmp expect msg |
| 195 | ' |
| 196 | |
Chris Webb | d9a9357 | 2012-07-09 19:53:26 +0100 | [diff] [blame] | 197 | test_expect_success '--amend --edit of empty message' ' |
| 198 | cat >replace <<-\EOF && |
| 199 | #!/bin/sh |
| 200 | echo "amended" >"$1" |
| 201 | EOF |
| 202 | chmod 755 replace && |
| 203 | git commit --allow-empty --allow-empty-message -m "" && |
| 204 | echo more bongo >file && |
| 205 | git add file && |
| 206 | EDITOR=./replace git commit --edit --amend && |
| 207 | git diff-tree -s --format=%s HEAD >msg && |
| 208 | ./replace expect && |
| 209 | test_cmp expect msg |
| 210 | ' |
| 211 | |
Jeff King | 27014cb | 2016-04-07 12:56:26 -0700 | [diff] [blame] | 212 | test_expect_success '--amend to set message to empty' ' |
| 213 | echo bata >file && |
Adam Dinwoodie | 178e814 | 2016-04-06 18:15:03 +0100 | [diff] [blame] | 214 | git add file && |
| 215 | git commit -m "unamended" && |
| 216 | git commit --amend --allow-empty-message -m "" && |
| 217 | git diff-tree -s --format=%s HEAD >msg && |
| 218 | echo "" >expect && |
| 219 | test_cmp expect msg |
| 220 | ' |
| 221 | |
Jeff King | 27014cb | 2016-04-07 12:56:26 -0700 | [diff] [blame] | 222 | test_expect_success '--amend to set empty message needs --allow-empty-message' ' |
Adam Dinwoodie | 178e814 | 2016-04-06 18:15:03 +0100 | [diff] [blame] | 223 | echo conga >file && |
| 224 | git add file && |
| 225 | git commit -m "unamended" && |
| 226 | test_must_fail git commit --amend -m "" && |
| 227 | git diff-tree -s --format=%s HEAD >msg && |
| 228 | echo "unamended" >expect && |
| 229 | test_cmp expect msg |
| 230 | ' |
| 231 | |
Jonathan Nieder | bc82189 | 2011-12-07 08:54:14 -0600 | [diff] [blame] | 232 | test_expect_success '-m --edit' ' |
| 233 | echo amended >expect && |
| 234 | git commit --allow-empty -m buffer && |
| 235 | echo bongo bongo >file && |
| 236 | git add file && |
| 237 | EDITOR=./editor git commit -m unamended --edit && |
| 238 | git diff-tree -s --format=%s HEAD >msg && |
| 239 | test_cmp expect msg |
| 240 | ' |
| 241 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 242 | test_expect_success '-m and -F do not mix' ' |
| 243 | echo enough with the bongos >file && |
| 244 | test_must_fail git commit -F msg -m amending . |
| 245 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 246 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 247 | test_expect_success 'using message from other commit' ' |
| 248 | git commit -C HEAD^ . |
| 249 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 250 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 251 | test_expect_success 'editing message from other commit' ' |
| 252 | cat >editor <<-\EOF && |
| 253 | #!/bin/sh |
| 254 | sed -e "s/amend/older/g" < "$1" > "$1-" |
| 255 | mv "$1-" "$1" |
| 256 | EOF |
| 257 | chmod 755 editor && |
| 258 | echo hula hula >file && |
| 259 | EDITOR=./editor git commit -c HEAD^ -a |
| 260 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 261 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 262 | test_expect_success 'message from stdin' ' |
| 263 | echo silly new contents >file && |
| 264 | echo commit message from stdin | |
| 265 | git commit -F - -a |
| 266 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 267 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 268 | test_expect_success 'overriding author from command line' ' |
| 269 | echo gak >file && |
| 270 | git commit -m author \ |
| 271 | --author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 && |
| 272 | grep Rubber.Duck output |
| 273 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 274 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 275 | test_expect_success PERL 'interactive add' ' |
| 276 | echo 7 | |
| 277 | git commit --interactive | |
| 278 | grep "What now" |
| 279 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 280 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 281 | test_expect_success PERL "commit --interactive doesn't change index if editor aborts" ' |
| 282 | echo zoo >file && |
Conrad Irwin | 02a481f | 2011-05-10 12:12:31 -0700 | [diff] [blame] | 283 | test_must_fail git diff --exit-code >diff1 && |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 284 | (echo u ; echo "*" ; echo q) | |
| 285 | ( |
| 286 | EDITOR=: && |
| 287 | export EDITOR && |
| 288 | test_must_fail git commit --interactive |
| 289 | ) && |
Conrad Irwin | 02a481f | 2011-05-10 12:12:31 -0700 | [diff] [blame] | 290 | git diff >diff2 && |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 291 | compare_diff_patch diff1 diff2 |
| 292 | ' |
Conrad Irwin | 02a481f | 2011-05-10 12:12:31 -0700 | [diff] [blame] | 293 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 294 | test_expect_success 'editor not invoked if -F is given' ' |
| 295 | cat >editor <<-\EOF && |
| 296 | #!/bin/sh |
| 297 | sed -e s/good/bad/g <"$1" >"$1-" |
| 298 | mv "$1-" "$1" |
| 299 | EOF |
| 300 | chmod 755 editor && |
Adeodato Simó | 7eb5bbd | 2009-01-09 18:30:05 +0100 | [diff] [blame] | 301 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 302 | echo A good commit message. >msg && |
| 303 | echo moo >file && |
Adeodato Simó | 7eb5bbd | 2009-01-09 18:30:05 +0100 | [diff] [blame] | 304 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 305 | EDITOR=./editor git commit -a -F msg && |
| 306 | git show -s --pretty=format:%s >subject && |
| 307 | grep -q good subject && |
| 308 | |
| 309 | echo quack >file && |
| 310 | echo Another good message. | |
| 311 | EDITOR=./editor git commit -a -F - && |
| 312 | git show -s --pretty=format:%s >subject && |
| 313 | grep -q good subject |
| 314 | ' |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 315 | |
Junio C Hamano | db33af0 | 2007-09-14 16:53:58 -0700 | [diff] [blame] | 316 | test_expect_success 'partial commit that involves removal (1)' ' |
Junio C Hamano | 80bffaf | 2007-09-12 16:04:22 -0700 | [diff] [blame] | 317 | |
| 318 | git rm --cached file && |
| 319 | mv file elif && |
| 320 | git add elif && |
| 321 | git commit -m "Partial: add elif" elif && |
| 322 | git diff-tree --name-status HEAD^ HEAD >current && |
| 323 | echo "A elif" >expected && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 324 | test_cmp expected current |
Junio C Hamano | 80bffaf | 2007-09-12 16:04:22 -0700 | [diff] [blame] | 325 | |
| 326 | ' |
| 327 | |
Junio C Hamano | db33af0 | 2007-09-14 16:53:58 -0700 | [diff] [blame] | 328 | test_expect_success 'partial commit that involves removal (2)' ' |
Junio C Hamano | 80bffaf | 2007-09-12 16:04:22 -0700 | [diff] [blame] | 329 | |
| 330 | git commit -m "Partial: remove file" file && |
| 331 | git diff-tree --name-status HEAD^ HEAD >current && |
| 332 | echo "D file" >expected && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 333 | test_cmp expected current |
Junio C Hamano | 80bffaf | 2007-09-12 16:04:22 -0700 | [diff] [blame] | 334 | |
| 335 | ' |
| 336 | |
Junio C Hamano | db33af0 | 2007-09-14 16:53:58 -0700 | [diff] [blame] | 337 | test_expect_success 'partial commit that involves removal (3)' ' |
| 338 | |
| 339 | git rm --cached elif && |
| 340 | echo elif >elif && |
| 341 | git commit -m "Partial: modify elif" elif && |
| 342 | git diff-tree --name-status HEAD^ HEAD >current && |
| 343 | echo "M elif" >expected && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 344 | test_cmp expected current |
Junio C Hamano | db33af0 | 2007-09-14 16:53:58 -0700 | [diff] [blame] | 345 | |
| 346 | ' |
| 347 | |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 348 | test_expect_success 'amend commit to fix author' ' |
| 349 | |
| 350 | oldtick=$GIT_AUTHOR_DATE && |
| 351 | test_tick && |
| 352 | git reset --hard && |
| 353 | git cat-file -p HEAD | |
| 354 | sed -e "s/author.*/author $author $oldtick/" \ |
| 355 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ |
| 356 | expected && |
| 357 | git commit --amend --author="$author" && |
| 358 | git cat-file -p HEAD > current && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 359 | test_cmp expected current |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 360 | |
| 361 | ' |
| 362 | |
Miklos Vajna | 02b47cd | 2009-12-02 23:16:18 +0100 | [diff] [blame] | 363 | test_expect_success 'amend commit to fix date' ' |
| 364 | |
| 365 | test_tick && |
| 366 | newtick=$GIT_AUTHOR_DATE && |
| 367 | git reset --hard && |
| 368 | git cat-file -p HEAD | |
| 369 | sed -e "s/author.*/author $author $newtick/" \ |
| 370 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ |
| 371 | expected && |
| 372 | git commit --amend --date="$newtick" && |
| 373 | git cat-file -p HEAD > current && |
| 374 | test_cmp expected current |
| 375 | |
| 376 | ' |
| 377 | |
Jeff King | b7242b8 | 2014-05-01 21:10:01 -0400 | [diff] [blame] | 378 | test_expect_success 'commit mentions forced date in output' ' |
| 379 | git commit --amend --date=2010-01-02T03:04:05 >output && |
| 380 | grep "Date: *Sat Jan 2 03:04:05 2010" output |
| 381 | ' |
| 382 | |
Jeff King | 14ac286 | 2014-05-01 21:12:42 -0400 | [diff] [blame] | 383 | test_expect_success 'commit complains about completely bogus dates' ' |
| 384 | test_must_fail git commit --amend --date=seventeen |
| 385 | ' |
| 386 | |
| 387 | test_expect_success 'commit --date allows approxidate' ' |
| 388 | git commit --amend \ |
| 389 | --date="midnight the 12th of october, anno domini 1979" && |
| 390 | echo "Fri Oct 12 00:00:00 1979 +0000" >expect && |
| 391 | git log -1 --format=%ad >actual && |
| 392 | test_cmp expect actual |
Jeff King | 4579bb4 | 2010-12-13 12:02:25 -0500 | [diff] [blame] | 393 | ' |
| 394 | |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 395 | test_expect_success 'sign off (1)' ' |
| 396 | |
| 397 | echo 1 >positive && |
| 398 | git add positive && |
| 399 | git commit -s -m "thank you" && |
| 400 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && |
| 401 | ( |
| 402 | echo thank you |
| 403 | echo |
| 404 | git var GIT_COMMITTER_IDENT | |
| 405 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" |
| 406 | ) >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 407 | test_cmp expected actual |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 408 | |
| 409 | ' |
| 410 | |
| 411 | test_expect_success 'sign off (2)' ' |
| 412 | |
| 413 | echo 2 >positive && |
| 414 | git add positive && |
| 415 | existing="Signed-off-by: Watch This <watchthis@example.com>" && |
| 416 | git commit -s -m "thank you |
| 417 | |
| 418 | $existing" && |
| 419 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && |
| 420 | ( |
| 421 | echo thank you |
| 422 | echo |
| 423 | echo $existing |
| 424 | git var GIT_COMMITTER_IDENT | |
| 425 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" |
| 426 | ) >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 427 | test_cmp expected actual |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 428 | |
| 429 | ' |
| 430 | |
David Brown | c1e01b0 | 2009-10-28 10:13:44 -0700 | [diff] [blame] | 431 | test_expect_success 'signoff gap' ' |
| 432 | |
| 433 | echo 3 >positive && |
| 434 | git add positive && |
| 435 | alt="Alt-RFC-822-Header: Value" && |
| 436 | git commit -s -m "welcome |
| 437 | |
| 438 | $alt" && |
| 439 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && |
| 440 | ( |
| 441 | echo welcome |
| 442 | echo |
| 443 | echo $alt |
| 444 | git var GIT_COMMITTER_IDENT | |
| 445 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" |
| 446 | ) >expected && |
| 447 | test_cmp expected actual |
| 448 | ' |
| 449 | |
| 450 | test_expect_success 'signoff gap 2' ' |
| 451 | |
| 452 | echo 4 >positive && |
| 453 | git add positive && |
| 454 | alt="fixed: 34" && |
| 455 | git commit -s -m "welcome |
| 456 | |
| 457 | We have now |
| 458 | $alt" && |
| 459 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && |
| 460 | ( |
| 461 | echo welcome |
| 462 | echo |
| 463 | echo We have now |
| 464 | echo $alt |
| 465 | echo |
| 466 | git var GIT_COMMITTER_IDENT | |
| 467 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" |
| 468 | ) >expected && |
| 469 | test_cmp expected actual |
| 470 | ' |
| 471 | |
Jonathan Tan | 967dfd4 | 2016-11-02 10:29:20 -0700 | [diff] [blame] | 472 | test_expect_success 'signoff respects trailer config' ' |
| 473 | |
| 474 | echo 5 >positive && |
| 475 | git add positive && |
| 476 | git commit -s -m "subject |
| 477 | |
| 478 | non-trailer line |
| 479 | Myfooter: x" && |
| 480 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && |
| 481 | ( |
| 482 | echo subject |
| 483 | echo |
| 484 | echo non-trailer line |
| 485 | echo Myfooter: x |
| 486 | echo |
| 487 | echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" |
| 488 | ) >expected && |
| 489 | test_cmp expected actual && |
| 490 | |
| 491 | echo 6 >positive && |
| 492 | git add positive && |
| 493 | git -c "trailer.Myfooter.ifexists=add" commit -s -m "subject |
| 494 | |
| 495 | non-trailer line |
| 496 | Myfooter: x" && |
| 497 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && |
| 498 | ( |
| 499 | echo subject |
| 500 | echo |
| 501 | echo non-trailer line |
| 502 | echo Myfooter: x |
| 503 | echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" |
| 504 | ) >expected && |
| 505 | test_cmp expected actual |
| 506 | ' |
| 507 | |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 508 | test_expect_success 'multiple -m' ' |
| 509 | |
| 510 | >negative && |
| 511 | git add negative && |
| 512 | git commit -m "one" -m "two" -m "three" && |
| 513 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && |
| 514 | ( |
| 515 | echo one |
| 516 | echo |
| 517 | echo two |
| 518 | echo |
| 519 | echo three |
| 520 | ) >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 521 | test_cmp expected actual |
Junio C Hamano | 5aa5cd4 | 2007-11-10 01:49:34 -0800 | [diff] [blame] | 522 | |
| 523 | ' |
| 524 | |
Kristian Høgsberg | d63c2fd | 2007-11-02 11:33:06 -0400 | [diff] [blame] | 525 | test_expect_success 'amend commit to fix author' ' |
| 526 | |
| 527 | oldtick=$GIT_AUTHOR_DATE && |
| 528 | test_tick && |
| 529 | git reset --hard && |
| 530 | git cat-file -p HEAD | |
| 531 | sed -e "s/author.*/author $author $oldtick/" \ |
| 532 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ |
| 533 | expected && |
| 534 | git commit --amend --author="$author" && |
| 535 | git cat-file -p HEAD > current && |
Miklos Vajna | 1e36868 | 2008-09-10 19:32:44 +0200 | [diff] [blame] | 536 | test_cmp expected current |
Kristian Høgsberg | d63c2fd | 2007-11-02 11:33:06 -0400 | [diff] [blame] | 537 | |
| 538 | ' |
Kristian Høgsberg | 1200993 | 2007-11-15 09:49:58 -0500 | [diff] [blame] | 539 | |
| 540 | test_expect_success 'git commit <file> with dirty index' ' |
| 541 | echo tacocat > elif && |
| 542 | echo tehlulz > chz && |
| 543 | git add chz && |
| 544 | git commit elif -m "tacocat is a palindrome" && |
| 545 | git show --stat | grep elif && |
| 546 | git diff --cached | grep chz |
| 547 | ' |
| 548 | |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 549 | test_expect_success 'same tree (single parent)' ' |
| 550 | |
Jonathan Nieder | 1af524e | 2011-12-07 08:50:23 -0600 | [diff] [blame] | 551 | git reset --hard && |
| 552 | test_must_fail git commit -m empty |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 553 | |
| 554 | ' |
| 555 | |
Junio C Hamano | 36863af | 2007-12-03 00:03:10 -0800 | [diff] [blame] | 556 | test_expect_success 'same tree (single parent) --allow-empty' ' |
| 557 | |
| 558 | git commit --allow-empty -m "forced empty" && |
| 559 | git cat-file commit HEAD | grep forced |
| 560 | |
| 561 | ' |
| 562 | |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 563 | test_expect_success 'same tree (merge and amend merge)' ' |
| 564 | |
| 565 | git checkout -b side HEAD^ && |
| 566 | echo zero >zero && |
| 567 | git add zero && |
| 568 | git commit -m "add zero" && |
| 569 | git checkout master && |
| 570 | |
| 571 | git merge -s ours side -m "empty ok" && |
| 572 | git diff HEAD^ HEAD >actual && |
| 573 | : >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 574 | test_cmp expected actual && |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 575 | |
| 576 | git commit --amend -m "empty really ok" && |
| 577 | git diff HEAD^ HEAD >actual && |
| 578 | : >expected && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 579 | test_cmp expected actual |
Johannes Sixt | 13aba1e | 2007-12-03 08:24:50 +0100 | [diff] [blame] | 580 | |
| 581 | ' |
| 582 | |
Junio C Hamano | 1eb1e9e | 2007-12-14 11:57:22 -0800 | [diff] [blame] | 583 | test_expect_success 'amend using the message from another commit' ' |
| 584 | |
| 585 | git reset --hard && |
| 586 | test_tick && |
| 587 | git commit --allow-empty -m "old commit" && |
| 588 | old=$(git rev-parse --verify HEAD) && |
| 589 | test_tick && |
| 590 | git commit --allow-empty -m "new commit" && |
| 591 | new=$(git rev-parse --verify HEAD) && |
| 592 | test_tick && |
| 593 | git commit --allow-empty --amend -C "$old" && |
| 594 | git show --pretty="format:%ad %s" "$old" >expected && |
| 595 | git show --pretty="format:%ad %s" HEAD >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 596 | test_cmp expected actual |
Junio C Hamano | 1eb1e9e | 2007-12-14 11:57:22 -0800 | [diff] [blame] | 597 | |
| 598 | ' |
| 599 | |
Junio C Hamano | 8a2f873 | 2008-02-03 00:00:09 -0800 | [diff] [blame] | 600 | test_expect_success 'amend using the message from a commit named with tag' ' |
| 601 | |
| 602 | git reset --hard && |
| 603 | test_tick && |
| 604 | git commit --allow-empty -m "old commit" && |
| 605 | old=$(git rev-parse --verify HEAD) && |
| 606 | git tag -a -m "tag on old" tagged-old HEAD && |
| 607 | test_tick && |
| 608 | git commit --allow-empty -m "new commit" && |
| 609 | new=$(git rev-parse --verify HEAD) && |
| 610 | test_tick && |
| 611 | git commit --allow-empty --amend -C tagged-old && |
| 612 | git show --pretty="format:%ad %s" "$old" >expected && |
| 613 | git show --pretty="format:%ad %s" HEAD >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 614 | test_cmp expected actual |
Junio C Hamano | 8a2f873 | 2008-02-03 00:00:09 -0800 | [diff] [blame] | 615 | |
| 616 | ' |
| 617 | |
Thomas Rast | 6360d34 | 2010-03-12 18:04:34 +0100 | [diff] [blame] | 618 | test_expect_success 'amend can copy notes' ' |
| 619 | |
| 620 | git config notes.rewrite.amend true && |
| 621 | git config notes.rewriteRef "refs/notes/*" && |
| 622 | test_commit foo && |
| 623 | git notes add -m"a note" && |
| 624 | test_tick && |
| 625 | git commit --amend -m"new foo" && |
| 626 | test "$(git notes show)" = "a note" |
| 627 | |
| 628 | ' |
| 629 | |
Junio C Hamano | 4682d85 | 2012-06-27 20:14:47 -0700 | [diff] [blame] | 630 | test_expect_success 'commit a file whose name is a dash' ' |
| 631 | git reset --hard && |
| 632 | for i in 1 2 3 4 5 |
| 633 | do |
| 634 | echo $i |
| 635 | done >./- && |
| 636 | git add ./- && |
| 637 | test_tick && |
| 638 | git commit -m "add dash" >output </dev/null && |
| 639 | test_i18ngrep " changed, 5 insertions" output |
| 640 | ' |
| 641 | |
Thomas Rast | f0c7320 | 2013-06-01 13:02:00 +0200 | [diff] [blame] | 642 | test_expect_success '--only works on to-be-born branch' ' |
| 643 | # This test relies on having something in the index, as it |
| 644 | # would not otherwise actually prove much. So check this. |
| 645 | test -n "$(git ls-files)" && |
| 646 | git checkout --orphan orphan && |
| 647 | echo foo >newfile && |
| 648 | git add newfile && |
| 649 | git commit --only newfile -m"--only on unborn branch" && |
| 650 | echo newfile >expected && |
| 651 | git ls-tree -r --name-only HEAD >actual && |
| 652 | test_cmp expected actual |
| 653 | ' |
| 654 | |
Stephen P. Smith | 8dc874b | 2016-02-15 19:38:25 -0700 | [diff] [blame] | 655 | test_expect_success '--dry-run with conflicts fixed from a merge' ' |
| 656 | # setup two branches with conflicting information |
| 657 | # in the same file, resolve the conflict, |
| 658 | # call commit with --dry-run |
| 659 | echo "Initial contents, unimportant" >test-file && |
| 660 | git add test-file && |
| 661 | git commit -m "Initial commit" && |
| 662 | echo "commit-1-state" >test-file && |
| 663 | git commit -m "commit 1" -i test-file && |
| 664 | git tag commit-1 && |
| 665 | git checkout -b branch-2 HEAD^1 && |
| 666 | echo "commit-2-state" >test-file && |
| 667 | git commit -m "commit 2" -i test-file && |
| 668 | ! $(git merge --no-commit commit-1) && |
| 669 | echo "commit-2-state" >test-file && |
| 670 | git add test-file && |
| 671 | git commit --dry-run && |
| 672 | git commit -m "conflicts fixed from merge." |
| 673 | ' |
| 674 | |
Kristian Høgsberg | 12ace0b | 2007-07-31 15:37:30 -0400 | [diff] [blame] | 675 | test_done |