3 # Copyright (c) 2008 Christian Couder
5 test_description
='Tests replace refs functionality'
16 git add
$_file ||
return $?
17 test_tick ||
return $?
18 git commit
--quiet -m "$_file: $_msg"
29 test_expect_success
'set up buggy branch' '
30 echo "line 1" >> hello &&
31 echo "line 2" >> hello &&
32 echo "line 3" >> hello &&
33 echo "line 4" >> hello &&
34 add_and_commit_file hello "4 lines" &&
35 HASH1=$(git rev-parse --verify HEAD) &&
36 echo "line BUG" >> hello &&
37 echo "line 6" >> hello &&
38 echo "line 7" >> hello &&
39 echo "line 8" >> hello &&
40 add_and_commit_file hello "4 more lines with a BUG" &&
41 HASH2=$(git rev-parse --verify HEAD) &&
42 echo "line 9" >> hello &&
43 echo "line 10" >> hello &&
44 add_and_commit_file hello "2 more lines" &&
45 HASH3=$(git rev-parse --verify HEAD) &&
46 echo "line 11" >> hello &&
47 add_and_commit_file hello "1 more line" &&
48 HASH4=$(git rev-parse --verify HEAD) &&
49 sed -e "s/BUG/5/" hello > hello.new &&
51 add_and_commit_file hello "BUG fixed" &&
52 HASH5=$(git rev-parse --verify HEAD) &&
53 echo "line 12" >> hello &&
54 echo "line 13" >> hello &&
55 add_and_commit_file hello "2 more lines" &&
56 HASH6=$(git rev-parse --verify HEAD)
57 echo "line 14" >> hello &&
58 echo "line 15" >> hello &&
59 echo "line 16" >> hello &&
60 add_and_commit_file hello "again 3 more lines" &&
61 HASH7=$(git rev-parse --verify HEAD)
64 test_expect_success
'replace the author' '
65 git cat-file commit $HASH2 | grep "author A U Thor" &&
66 R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
67 git cat-file commit $R | grep "author O Thor" &&
68 git update-ref refs/replace/$HASH2 $R &&
69 git show HEAD~5 | grep "O Thor" &&
70 git show $HASH2 | grep "O Thor"
77 tagger T A Gger <> 0 +0000
81 test_expect_success
'tag replaced commit' '
82 git mktag <tag.sig >.git/refs/tags/mytag 2>message
85 test_expect_success
'"git fsck" works' '
86 git fsck master > fsck_master.out &&
87 grep "dangling commit $R" fsck_master.out &&
88 grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
92 test_expect_success
'repack, clone and fetch work' '
94 git clone --no-hardlinks . clone_dir &&
96 git show HEAD~5 | grep "A U Thor" &&
97 git show $HASH2 | grep "A U Thor" &&
98 git cat-file commit $R &&
100 test_must_fail git cat-file commit $R &&
101 git fetch ../ "refs/replace/*:refs/replace/*" &&
102 git show HEAD~5 | grep "O Thor" &&
103 git show $HASH2 | grep "O Thor" &&
104 git cat-file commit $R &&
108 test_expect_success
'"git replace" listing and deleting' '
109 test "$HASH2" = "$(git replace -l)" &&
110 test "$HASH2" = "$(git replace)" &&
111 aa=${HASH2%??????????????????????????????????????} &&
112 test "$HASH2" = "$(git replace -l "$aa*")" &&
113 test_must_fail git replace -d $R &&
114 test_must_fail git replace -d &&
115 test_must_fail git replace -l -d $HASH2 &&
116 git replace -d $HASH2 &&
117 git show $HASH2 | grep "A U Thor" &&
118 test -z "$(git replace -l)"
121 test_expect_success
'"git replace" replacing' '
122 git replace $HASH2 $R &&
123 git show $HASH2 | grep "O Thor" &&
124 test_must_fail git replace $HASH2 $R &&
125 git replace -f $HASH2 $R &&
126 test_must_fail git replace -f &&
127 test "$HASH2" = "$(git replace)"