Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Christian Couder |
| 4 | # |
| 5 | test_description='Tests replace refs functionality' |
| 6 | |
| 7 | exec </dev/null |
| 8 | |
| 9 | . ./test-lib.sh |
Christian Couder | 60e2f5a | 2014-07-19 17:01:13 +0200 | [diff] [blame] | 10 | . "$TEST_DIRECTORY/lib-gpg.sh" |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 11 | |
Christian Couder | adf8e54 | 2014-07-19 17:01:09 +0200 | [diff] [blame] | 12 | add_and_commit_file () |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 13 | { |
| 14 | _file="$1" |
| 15 | _msg="$2" |
| 16 | |
| 17 | git add $_file || return $? |
| 18 | test_tick || return $? |
| 19 | git commit --quiet -m "$_file: $_msg" |
| 20 | } |
| 21 | |
Christian Couder | adf8e54 | 2014-07-19 17:01:09 +0200 | [diff] [blame] | 22 | commit_buffer_contains_parents () |
| 23 | { |
| 24 | git cat-file commit "$1" >payload && |
| 25 | sed -n -e '/^$/q' -e '/^parent /p' <payload >actual && |
| 26 | shift && |
| 27 | for _parent |
| 28 | do |
| 29 | echo "parent $_parent" |
| 30 | done >expected && |
| 31 | test_cmp expected actual |
| 32 | } |
| 33 | |
| 34 | commit_peeling_shows_parents () |
| 35 | { |
| 36 | _parent_number=1 |
| 37 | _commit="$1" |
| 38 | shift && |
| 39 | for _parent |
| 40 | do |
| 41 | _found=$(git rev-parse --verify $_commit^$_parent_number) || return 1 |
| 42 | test "$_found" = "$_parent" || return 1 |
| 43 | _parent_number=$(( $_parent_number + 1 )) |
| 44 | done && |
| 45 | test_must_fail git rev-parse --verify $_commit^$_parent_number |
| 46 | } |
| 47 | |
| 48 | commit_has_parents () |
| 49 | { |
| 50 | commit_buffer_contains_parents "$@" && |
| 51 | commit_peeling_shows_parents "$@" |
| 52 | } |
| 53 | |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 54 | HASH1= |
| 55 | HASH2= |
| 56 | HASH3= |
| 57 | HASH4= |
| 58 | HASH5= |
| 59 | HASH6= |
| 60 | HASH7= |
| 61 | |
| 62 | test_expect_success 'set up buggy branch' ' |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 63 | echo "line 1" >>hello && |
| 64 | echo "line 2" >>hello && |
| 65 | echo "line 3" >>hello && |
| 66 | echo "line 4" >>hello && |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 67 | add_and_commit_file hello "4 lines" && |
| 68 | HASH1=$(git rev-parse --verify HEAD) && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 69 | echo "line BUG" >>hello && |
| 70 | echo "line 6" >>hello && |
| 71 | echo "line 7" >>hello && |
| 72 | echo "line 8" >>hello && |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 73 | add_and_commit_file hello "4 more lines with a BUG" && |
| 74 | HASH2=$(git rev-parse --verify HEAD) && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 75 | echo "line 9" >>hello && |
| 76 | echo "line 10" >>hello && |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 77 | add_and_commit_file hello "2 more lines" && |
| 78 | HASH3=$(git rev-parse --verify HEAD) && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 79 | echo "line 11" >>hello && |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 80 | add_and_commit_file hello "1 more line" && |
| 81 | HASH4=$(git rev-parse --verify HEAD) && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 82 | sed -e "s/BUG/5/" hello >hello.new && |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 83 | mv hello.new hello && |
| 84 | add_and_commit_file hello "BUG fixed" && |
| 85 | HASH5=$(git rev-parse --verify HEAD) && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 86 | echo "line 12" >>hello && |
| 87 | echo "line 13" >>hello && |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 88 | add_and_commit_file hello "2 more lines" && |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 89 | HASH6=$(git rev-parse --verify HEAD) && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 90 | echo "line 14" >>hello && |
| 91 | echo "line 15" >>hello && |
| 92 | echo "line 16" >>hello && |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 93 | add_and_commit_file hello "again 3 more lines" && |
| 94 | HASH7=$(git rev-parse --verify HEAD) |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'replace the author' ' |
| 98 | git cat-file commit $HASH2 | grep "author A U Thor" && |
| 99 | R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) && |
| 100 | git cat-file commit $R | grep "author O Thor" && |
| 101 | git update-ref refs/replace/$HASH2 $R && |
| 102 | git show HEAD~5 | grep "O Thor" && |
| 103 | git show $HASH2 | grep "O Thor" |
| 104 | ' |
| 105 | |
Christian Couder | b0fa7ab | 2009-10-12 22:30:32 +0200 | [diff] [blame] | 106 | test_expect_success 'test --no-replace-objects option' ' |
| 107 | git cat-file commit $HASH2 | grep "author O Thor" && |
| 108 | git --no-replace-objects cat-file commit $HASH2 | grep "author A U Thor" && |
| 109 | git show $HASH2 | grep "O Thor" && |
| 110 | git --no-replace-objects show $HASH2 | grep "A U Thor" |
| 111 | ' |
| 112 | |
Christian Couder | 6476b38 | 2009-11-18 07:50:58 +0100 | [diff] [blame] | 113 | test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' ' |
| 114 | GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 | grep "author A U Thor" && |
| 115 | GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor" |
| 116 | ' |
| 117 | |
Christian Couder | cc400f5 | 2009-01-23 10:07:26 +0100 | [diff] [blame] | 118 | cat >tag.sig <<EOF |
| 119 | object $HASH2 |
| 120 | type commit |
| 121 | tag mytag |
| 122 | tagger T A Gger <> 0 +0000 |
| 123 | |
| 124 | EOF |
| 125 | |
| 126 | test_expect_success 'tag replaced commit' ' |
| 127 | git mktag <tag.sig >.git/refs/tags/mytag 2>message |
| 128 | ' |
| 129 | |
Christian Couder | dae556b | 2009-01-23 10:07:46 +0100 | [diff] [blame] | 130 | test_expect_success '"git fsck" works' ' |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 131 | git fsck master >fsck_master.out && |
Christian Couder | dae556b | 2009-01-23 10:07:46 +0100 | [diff] [blame] | 132 | grep "dangling commit $R" fsck_master.out && |
| 133 | grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && |
| 134 | test -z "$(git fsck)" |
| 135 | ' |
| 136 | |
| 137 | test_expect_success 'repack, clone and fetch work' ' |
| 138 | git repack -a -d && |
| 139 | git clone --no-hardlinks . clone_dir && |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 140 | ( |
| 141 | cd clone_dir && |
| 142 | git show HEAD~5 | grep "A U Thor" && |
| 143 | git show $HASH2 | grep "A U Thor" && |
| 144 | git cat-file commit $R && |
| 145 | git repack -a -d && |
| 146 | test_must_fail git cat-file commit $R && |
| 147 | git fetch ../ "refs/replace/*:refs/replace/*" && |
| 148 | git show HEAD~5 | grep "O Thor" && |
| 149 | git show $HASH2 | grep "O Thor" && |
| 150 | git cat-file commit $R |
Jens Lehmann | fd4ec4f | 2010-09-06 20:39:54 +0200 | [diff] [blame] | 151 | ) |
Christian Couder | dae556b | 2009-01-23 10:07:46 +0100 | [diff] [blame] | 152 | ' |
| 153 | |
Christian Couder | 54b0c1e | 2009-02-02 06:12:44 +0100 | [diff] [blame] | 154 | test_expect_success '"git replace" listing and deleting' ' |
| 155 | test "$HASH2" = "$(git replace -l)" && |
| 156 | test "$HASH2" = "$(git replace)" && |
| 157 | aa=${HASH2%??????????????????????????????????????} && |
Christian Couder | b1ecd8c | 2013-09-06 07:10:59 +0200 | [diff] [blame] | 158 | test "$HASH2" = "$(git replace --list "$aa*")" && |
Christian Couder | 54b0c1e | 2009-02-02 06:12:44 +0100 | [diff] [blame] | 159 | test_must_fail git replace -d $R && |
Christian Couder | b1ecd8c | 2013-09-06 07:10:59 +0200 | [diff] [blame] | 160 | test_must_fail git replace --delete && |
Christian Couder | 54b0c1e | 2009-02-02 06:12:44 +0100 | [diff] [blame] | 161 | test_must_fail git replace -l -d $HASH2 && |
| 162 | git replace -d $HASH2 && |
Christian Couder | bebdd27 | 2009-02-02 06:12:53 +0100 | [diff] [blame] | 163 | git show $HASH2 | grep "A U Thor" && |
Christian Couder | 54b0c1e | 2009-02-02 06:12:44 +0100 | [diff] [blame] | 164 | test -z "$(git replace -l)" |
| 165 | ' |
| 166 | |
Christian Couder | bebdd27 | 2009-02-02 06:12:53 +0100 | [diff] [blame] | 167 | test_expect_success '"git replace" replacing' ' |
| 168 | git replace $HASH2 $R && |
| 169 | git show $HASH2 | grep "O Thor" && |
| 170 | test_must_fail git replace $HASH2 $R && |
| 171 | git replace -f $HASH2 $R && |
| 172 | test_must_fail git replace -f && |
| 173 | test "$HASH2" = "$(git replace)" |
| 174 | ' |
| 175 | |
Michael J Gruber | 9dfc368 | 2012-11-13 11:34:11 +0100 | [diff] [blame] | 176 | test_expect_success '"git replace" resolves sha1' ' |
| 177 | SHORTHASH2=$(git rev-parse --short=8 $HASH2) && |
| 178 | git replace -d $SHORTHASH2 && |
| 179 | git replace $SHORTHASH2 $R && |
| 180 | git show $HASH2 | grep "O Thor" && |
| 181 | test_must_fail git replace $HASH2 $R && |
| 182 | git replace -f $HASH2 $R && |
Christian Couder | b1ecd8c | 2013-09-06 07:10:59 +0200 | [diff] [blame] | 183 | test_must_fail git replace --force && |
Michael J Gruber | 9dfc368 | 2012-11-13 11:34:11 +0100 | [diff] [blame] | 184 | test "$HASH2" = "$(git replace)" |
| 185 | ' |
| 186 | |
Christian Couder | 4e65b53 | 2009-05-27 07:14:09 +0200 | [diff] [blame] | 187 | # This creates a side branch where the bug in H2 |
| 188 | # does not appear because P2 is created by applying |
| 189 | # H2 and squashing H5 into it. |
| 190 | # P3, P4 and P6 are created by cherry-picking H3, H4 |
| 191 | # and H6 respectively. |
| 192 | # |
| 193 | # At this point, we should have the following: |
| 194 | # |
| 195 | # P2--P3--P4--P6 |
| 196 | # / |
| 197 | # H1-H2-H3-H4-H5-H6-H7 |
| 198 | # |
| 199 | # Then we replace H6 with P6. |
| 200 | # |
| 201 | test_expect_success 'create parallel branch without the bug' ' |
| 202 | git replace -d $HASH2 && |
| 203 | git show $HASH2 | grep "A U Thor" && |
| 204 | git checkout $HASH1 && |
| 205 | git cherry-pick $HASH2 && |
| 206 | git show $HASH5 | git apply && |
| 207 | git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello && |
| 208 | PARA2=$(git rev-parse --verify HEAD) && |
| 209 | git cherry-pick $HASH3 && |
| 210 | PARA3=$(git rev-parse --verify HEAD) && |
| 211 | git cherry-pick $HASH4 && |
| 212 | PARA4=$(git rev-parse --verify HEAD) && |
| 213 | git cherry-pick $HASH6 && |
| 214 | PARA6=$(git rev-parse --verify HEAD) && |
| 215 | git replace $HASH6 $PARA6 && |
| 216 | git checkout master && |
| 217 | cur=$(git rev-parse --verify HEAD) && |
| 218 | test "$cur" = "$HASH7" && |
| 219 | git log --pretty=oneline | grep $PARA2 && |
| 220 | git remote add cloned ./clone_dir |
| 221 | ' |
| 222 | |
| 223 | test_expect_success 'push to cloned repo' ' |
| 224 | git push cloned $HASH6^:refs/heads/parallel && |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 225 | ( |
| 226 | cd clone_dir && |
| 227 | git checkout parallel && |
| 228 | git log --pretty=oneline | grep $PARA2 |
Jens Lehmann | fd4ec4f | 2010-09-06 20:39:54 +0200 | [diff] [blame] | 229 | ) |
Christian Couder | 4e65b53 | 2009-05-27 07:14:09 +0200 | [diff] [blame] | 230 | ' |
| 231 | |
| 232 | test_expect_success 'push branch with replacement' ' |
| 233 | git cat-file commit $PARA3 | grep "author A U Thor" && |
| 234 | S=$(git cat-file commit $PARA3 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) && |
| 235 | git cat-file commit $S | grep "author O Thor" && |
| 236 | git replace $PARA3 $S && |
| 237 | git show $HASH6~2 | grep "O Thor" && |
| 238 | git show $PARA3 | grep "O Thor" && |
| 239 | git push cloned $HASH6^:refs/heads/parallel2 && |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 240 | ( |
| 241 | cd clone_dir && |
| 242 | git checkout parallel2 && |
| 243 | git log --pretty=oneline | grep $PARA3 && |
| 244 | git show $PARA3 | grep "A U Thor" |
Jens Lehmann | fd4ec4f | 2010-09-06 20:39:54 +0200 | [diff] [blame] | 245 | ) |
Christian Couder | 4e65b53 | 2009-05-27 07:14:09 +0200 | [diff] [blame] | 246 | ' |
| 247 | |
| 248 | test_expect_success 'fetch branch with replacement' ' |
| 249 | git branch tofetch $HASH6 && |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 250 | ( |
| 251 | cd clone_dir && |
Christian Couder | d212cef | 2010-09-26 07:20:18 +0200 | [diff] [blame] | 252 | git fetch origin refs/heads/tofetch:refs/heads/parallel3 && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 253 | git log --pretty=oneline parallel3 >output.txt && |
Christian Couder | d212cef | 2010-09-26 07:20:18 +0200 | [diff] [blame] | 254 | ! grep $PARA3 output.txt && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 255 | git show $PARA3 >para3.txt && |
Christian Couder | d212cef | 2010-09-26 07:20:18 +0200 | [diff] [blame] | 256 | grep "A U Thor" para3.txt && |
| 257 | git fetch origin "refs/replace/*:refs/replace/*" && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 258 | git log --pretty=oneline parallel3 >output.txt && |
Christian Couder | d212cef | 2010-09-26 07:20:18 +0200 | [diff] [blame] | 259 | grep $PARA3 output.txt && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 260 | git show $PARA3 >para3.txt && |
Christian Couder | d212cef | 2010-09-26 07:20:18 +0200 | [diff] [blame] | 261 | grep "O Thor" para3.txt |
Jens Lehmann | fd4ec4f | 2010-09-06 20:39:54 +0200 | [diff] [blame] | 262 | ) |
Christian Couder | 4e65b53 | 2009-05-27 07:14:09 +0200 | [diff] [blame] | 263 | ' |
| 264 | |
Christian Couder | 6476b38 | 2009-11-18 07:50:58 +0100 | [diff] [blame] | 265 | test_expect_success 'bisect and replacements' ' |
| 266 | git bisect start $HASH7 $HASH1 && |
Nguyễn Thái Ngọc Duy | 2e3400c | 2010-09-03 22:51:53 +0200 | [diff] [blame] | 267 | test "$PARA3" = "$(git rev-parse --verify HEAD)" && |
Christian Couder | 6476b38 | 2009-11-18 07:50:58 +0100 | [diff] [blame] | 268 | git bisect reset && |
| 269 | GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 && |
| 270 | test "$HASH4" = "$(git rev-parse --verify HEAD)" && |
| 271 | git bisect reset && |
| 272 | git --no-replace-objects bisect start $HASH7 $HASH1 && |
| 273 | test "$HASH4" = "$(git rev-parse --verify HEAD)" && |
| 274 | git bisect reset |
| 275 | ' |
| 276 | |
Nelson Elhage | 6e2a09d | 2010-08-12 10:18:12 -0400 | [diff] [blame] | 277 | test_expect_success 'index-pack and replacements' ' |
| 278 | git --no-replace-objects rev-list --objects HEAD | |
| 279 | git --no-replace-objects pack-objects test- && |
| 280 | git index-pack test-*.pack |
| 281 | ' |
| 282 | |
Junio C Hamano | abb25ac | 2011-05-15 12:54:51 -0700 | [diff] [blame] | 283 | test_expect_success 'not just commits' ' |
| 284 | echo replaced >file && |
| 285 | git add file && |
| 286 | REPLACED=$(git rev-parse :file) && |
| 287 | mv file file.replaced && |
| 288 | |
| 289 | echo original >file && |
| 290 | git add file && |
| 291 | ORIGINAL=$(git rev-parse :file) && |
| 292 | git update-ref refs/replace/$ORIGINAL $REPLACED && |
| 293 | mv file file.original && |
| 294 | |
| 295 | git checkout file && |
| 296 | test_cmp file.replaced file |
| 297 | ' |
| 298 | |
Christian Couder | 3e625c8 | 2013-09-06 07:10:55 +0200 | [diff] [blame] | 299 | test_expect_success 'replaced and replacement objects must be of the same type' ' |
| 300 | test_must_fail git replace mytag $HASH1 && |
| 301 | test_must_fail git replace HEAD^{tree} HEAD~1 && |
| 302 | BLOB=$(git rev-parse :file) && |
| 303 | test_must_fail git replace HEAD^ $BLOB |
| 304 | ' |
| 305 | |
| 306 | test_expect_success '-f option bypasses the type check' ' |
| 307 | git replace -f mytag $HASH1 && |
Christian Couder | b1ecd8c | 2013-09-06 07:10:59 +0200 | [diff] [blame] | 308 | git replace --force HEAD^{tree} HEAD~1 && |
Christian Couder | 3e625c8 | 2013-09-06 07:10:55 +0200 | [diff] [blame] | 309 | git replace -f HEAD^ $BLOB |
| 310 | ' |
| 311 | |
Christian Couder | 1f7117e | 2013-12-11 08:46:09 +0100 | [diff] [blame] | 312 | test_expect_success 'git cat-file --batch works on replace objects' ' |
Christian Couder | 303c5d6 | 2013-12-11 08:46:08 +0100 | [diff] [blame] | 313 | git replace | grep $PARA3 && |
| 314 | echo $PARA3 | git cat-file --batch |
| 315 | ' |
| 316 | |
Christian Couder | bbbb4af | 2013-12-11 08:46:11 +0100 | [diff] [blame] | 317 | test_expect_success 'test --format bogus' ' |
| 318 | test_must_fail git replace --format bogus >/dev/null 2>&1 |
| 319 | ' |
| 320 | |
| 321 | test_expect_success 'test --format short' ' |
| 322 | git replace --format=short >actual && |
| 323 | git replace >expected && |
| 324 | test_cmp expected actual |
| 325 | ' |
| 326 | |
| 327 | test_expect_success 'test --format medium' ' |
| 328 | H1=$(git --no-replace-objects rev-parse HEAD~1) && |
| 329 | HT=$(git --no-replace-objects rev-parse HEAD^{tree}) && |
| 330 | MYTAG=$(git --no-replace-objects rev-parse mytag) && |
| 331 | { |
| 332 | echo "$H1 -> $BLOB" && |
| 333 | echo "$BLOB -> $REPLACED" && |
| 334 | echo "$HT -> $H1" && |
| 335 | echo "$PARA3 -> $S" && |
| 336 | echo "$MYTAG -> $HASH1" |
| 337 | } | sort >expected && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 338 | git replace -l --format medium | sort >actual && |
Christian Couder | bbbb4af | 2013-12-11 08:46:11 +0100 | [diff] [blame] | 339 | test_cmp expected actual |
| 340 | ' |
| 341 | |
Christian Couder | 663a856 | 2013-12-28 12:00:05 +0100 | [diff] [blame] | 342 | test_expect_success 'test --format long' ' |
Christian Couder | bbbb4af | 2013-12-11 08:46:11 +0100 | [diff] [blame] | 343 | { |
| 344 | echo "$H1 (commit) -> $BLOB (blob)" && |
| 345 | echo "$BLOB (blob) -> $REPLACED (blob)" && |
| 346 | echo "$HT (tree) -> $H1 (commit)" && |
| 347 | echo "$PARA3 (commit) -> $S (commit)" && |
| 348 | echo "$MYTAG (tag) -> $HASH1 (commit)" |
| 349 | } | sort >expected && |
Christian Couder | 1c2828c | 2014-07-07 08:35:30 +0200 | [diff] [blame] | 350 | git replace --format=long | sort >actual && |
Christian Couder | bbbb4af | 2013-12-11 08:46:11 +0100 | [diff] [blame] | 351 | test_cmp expected actual |
| 352 | ' |
| 353 | |
Christian Couder | 85f98fc | 2014-05-17 14:16:37 +0200 | [diff] [blame] | 354 | test_expect_success 'setup a fake editor' ' |
| 355 | write_script fakeeditor <<-\EOF |
| 356 | sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new" |
| 357 | mv "$1.new" "$1" |
| 358 | EOF |
| 359 | ' |
| 360 | |
| 361 | test_expect_success '--edit with and without already replaced object' ' |
| 362 | test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && |
| 363 | GIT_EDITOR=./fakeeditor git replace --force --edit "$PARA3" && |
| 364 | git replace -l | grep "$PARA3" && |
| 365 | git cat-file commit "$PARA3" | grep "A fake Thor" && |
| 366 | git replace -d "$PARA3" && |
| 367 | GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && |
| 368 | git replace -l | grep "$PARA3" && |
| 369 | git cat-file commit "$PARA3" | grep "A fake Thor" |
| 370 | ' |
| 371 | |
| 372 | test_expect_success '--edit and change nothing or command failed' ' |
| 373 | git replace -d "$PARA3" && |
| 374 | test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" && |
| 375 | test_must_fail env GIT_EDITOR="./fakeeditor;false" git replace --edit "$PARA3" && |
| 376 | GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && |
| 377 | git replace -l | grep "$PARA3" && |
| 378 | git cat-file commit "$PARA3" | grep "A fake Thor" |
| 379 | ' |
| 380 | |
Christian Couder | 11aec95 | 2013-09-06 07:10:56 +0200 | [diff] [blame] | 381 | test_expect_success 'replace ref cleanup' ' |
| 382 | test -n "$(git replace)" && |
| 383 | git replace -d $(git replace) && |
| 384 | test -z "$(git replace)" |
| 385 | ' |
| 386 | |
Christian Couder | adf8e54 | 2014-07-19 17:01:09 +0200 | [diff] [blame] | 387 | test_expect_success '--graft with and without already replaced object' ' |
| 388 | test $(git log --oneline | wc -l) = 7 && |
| 389 | git replace --graft $HASH5 && |
| 390 | test $(git log --oneline | wc -l) = 3 && |
| 391 | commit_has_parents $HASH5 && |
| 392 | test_must_fail git replace --graft $HASH5 $HASH4 $HASH3 && |
| 393 | git replace --force -g $HASH5 $HASH4 $HASH3 && |
| 394 | commit_has_parents $HASH5 $HASH4 $HASH3 && |
| 395 | git replace -d $HASH5 |
| 396 | ' |
| 397 | |
Christian Couder | 60e2f5a | 2014-07-19 17:01:13 +0200 | [diff] [blame] | 398 | test_expect_success GPG 'set up a signed commit' ' |
| 399 | echo "line 17" >>hello && |
| 400 | echo "line 18" >>hello && |
| 401 | git add hello && |
| 402 | test_tick && |
| 403 | git commit --quiet -S -m "hello: 2 more lines in a signed commit" && |
| 404 | HASH8=$(git rev-parse --verify HEAD) && |
| 405 | git verify-commit $HASH8 |
| 406 | ' |
| 407 | |
| 408 | test_expect_success GPG '--graft with a signed commit' ' |
| 409 | git cat-file commit $HASH8 >orig && |
| 410 | git replace --graft $HASH8 && |
| 411 | git cat-file commit $HASH8 >repl && |
| 412 | commit_has_parents $HASH8 && |
| 413 | test_must_fail git verify-commit $HASH8 && |
| 414 | sed -n -e "/^tree /p" -e "/^author /p" -e "/^committer /p" orig >expected && |
| 415 | echo >>expected && |
| 416 | sed -e "/^$/q" repl >actual && |
| 417 | test_cmp expected actual && |
| 418 | git replace -d $HASH8 |
| 419 | ' |
| 420 | |
Christian Couder | 3fa1025 | 2014-07-19 17:01:15 +0200 | [diff] [blame] | 421 | test_expect_success GPG 'set up a merge commit with a mergetag' ' |
| 422 | git reset --hard HEAD && |
| 423 | git checkout -b test_branch HEAD~2 && |
| 424 | echo "line 1 from test branch" >>hello && |
| 425 | echo "line 2 from test branch" >>hello && |
| 426 | git add hello && |
| 427 | test_tick && |
| 428 | git commit -m "hello: 2 more lines from a test branch" && |
| 429 | HASH9=$(git rev-parse --verify HEAD) && |
| 430 | git tag -s -m "tag for testing with a mergetag" test_tag HEAD && |
| 431 | git checkout master && |
| 432 | git merge -s ours test_tag && |
| 433 | HASH10=$(git rev-parse --verify HEAD) && |
| 434 | git cat-file commit $HASH10 | grep "^mergetag object" |
| 435 | ' |
| 436 | |
| 437 | test_expect_success GPG '--graft on a commit with a mergetag' ' |
| 438 | test_must_fail git replace --graft $HASH10 $HASH8^1 && |
| 439 | git replace --graft $HASH10 $HASH8^1 $HASH9 && |
| 440 | git replace -d $HASH10 |
| 441 | ' |
| 442 | |
Christian Couder | a3e8267 | 2009-01-23 10:07:18 +0100 | [diff] [blame] | 443 | test_done |