| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test automatic tag following' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | if ! test_have_prereq PERL_TEST_HELPERS |
| 11 | then |
| 12 | skip_all='skipping tagfollow tests; Perl not available' |
| 13 | test_done |
| 14 | fi |
| 15 | |
| 16 | # End state of the repository: |
| 17 | # |
| 18 | # T - tag1 S - tag2 |
| 19 | # / / |
| 20 | # L - A ------ O ------ B |
| 21 | # \ \ \ |
| 22 | # \ C - origin/cat \ |
| 23 | # origin/main main |
| 24 | |
| 25 | test_expect_success setup ' |
| 26 | test_tick && |
| 27 | echo ichi >file && |
| 28 | git add file && |
| 29 | git commit -m L && |
| 30 | L=$(git rev-parse --verify HEAD) && |
| 31 | |
| 32 | ( |
| 33 | mkdir cloned && |
| 34 | cd cloned && |
| 35 | git init-db && |
| 36 | git remote add -f origin .. |
| 37 | ) && |
| 38 | |
| 39 | test_tick && |
| 40 | echo A >file && |
| 41 | git add file && |
| 42 | git commit -m A && |
| 43 | A=$(git rev-parse --verify HEAD) |
| 44 | ' |
| 45 | |
| 46 | U=UPLOAD_LOG |
| 47 | UPATH="$(pwd)/$U" |
| 48 | |
| 49 | test_expect_success 'setup expect' ' |
| 50 | cat - <<EOF >expect |
| 51 | want $A |
| 52 | EOF |
| 53 | ' |
| 54 | |
| 55 | get_needs () { |
| 56 | test -s "$1" && |
| 57 | perl -alne ' |
| 58 | next unless $F[1] eq "upload-pack<"; |
| 59 | next unless $F[2] eq "want"; |
| 60 | print $F[2], " ", $F[3]; |
| 61 | ' "$1" |
| 62 | } |
| 63 | |
| 64 | test_expect_success 'fetch A (new commit : 1 connection)' ' |
| 65 | rm -f $U && |
| 66 | ( |
| 67 | cd cloned && |
| 68 | GIT_TRACE_PACKET=$UPATH git fetch && |
| 69 | test $A = $(git rev-parse --verify origin/main) |
| 70 | ) && |
| 71 | get_needs $U >actual && |
| 72 | test_cmp expect actual |
| 73 | ' |
| 74 | |
| 75 | test_expect_success "create tag T on A, create C on branch cat" ' |
| 76 | git tag -a -m tag1 tag1 $A && |
| 77 | T=$(git rev-parse --verify tag1) && |
| 78 | |
| 79 | git checkout -b cat && |
| 80 | echo C >file && |
| 81 | git add file && |
| 82 | git commit -m C && |
| 83 | C=$(git rev-parse --verify HEAD) && |
| 84 | git checkout main |
| 85 | ' |
| 86 | |
| 87 | test_expect_success 'setup expect' ' |
| 88 | cat - <<EOF >expect |
| 89 | want $C |
| 90 | want $T |
| 91 | EOF |
| 92 | ' |
| 93 | |
| 94 | test_expect_success 'fetch C, T (new branch, tag : 1 connection)' ' |
| 95 | rm -f $U && |
| 96 | ( |
| 97 | cd cloned && |
| 98 | GIT_TRACE_PACKET=$UPATH git fetch && |
| 99 | test $C = $(git rev-parse --verify origin/cat) && |
| 100 | test $T = $(git rev-parse --verify tag1) && |
| 101 | test $A = $(git rev-parse --verify tag1^0) |
| 102 | ) && |
| 103 | get_needs $U >actual && |
| 104 | test_cmp expect actual |
| 105 | ' |
| 106 | |
| 107 | test_expect_success "create commits O, B, tag S on B" ' |
| 108 | test_tick && |
| 109 | echo O >file && |
| 110 | git add file && |
| 111 | git commit -m O && |
| 112 | |
| 113 | test_tick && |
| 114 | echo B >file && |
| 115 | git add file && |
| 116 | git commit -m B && |
| 117 | B=$(git rev-parse --verify HEAD) && |
| 118 | |
| 119 | git tag -a -m tag2 tag2 $B && |
| 120 | S=$(git rev-parse --verify tag2) |
| 121 | ' |
| 122 | |
| 123 | test_expect_success 'setup expect' ' |
| 124 | cat - <<EOF >expect |
| 125 | want $B |
| 126 | want $S |
| 127 | EOF |
| 128 | ' |
| 129 | |
| 130 | test_expect_success 'fetch B, S (commit and tag : 1 connection)' ' |
| 131 | rm -f $U && |
| 132 | ( |
| 133 | cd cloned && |
| 134 | GIT_TRACE_PACKET=$UPATH git fetch && |
| 135 | test $B = $(git rev-parse --verify origin/main) && |
| 136 | test $B = $(git rev-parse --verify tag2^0) && |
| 137 | test $S = $(git rev-parse --verify tag2) |
| 138 | ) && |
| 139 | get_needs $U >actual && |
| 140 | test_cmp expect actual |
| 141 | ' |
| 142 | |
| 143 | test_expect_success 'setup expect' ' |
| 144 | cat - <<EOF >expect |
| 145 | want $B |
| 146 | want $S |
| 147 | EOF |
| 148 | ' |
| 149 | |
| 150 | test_expect_success 'new clone fetch main and tags' ' |
| 151 | test_might_fail git branch -D cat && |
| 152 | rm -f $U && |
| 153 | ( |
| 154 | mkdir clone2 && |
| 155 | cd clone2 && |
| 156 | git init && |
| 157 | git remote add origin .. && |
| 158 | GIT_TRACE_PACKET=$UPATH git fetch && |
| 159 | test $B = $(git rev-parse --verify origin/main) && |
| 160 | test $S = $(git rev-parse --verify tag2) && |
| 161 | test $B = $(git rev-parse --verify tag2^0) && |
| 162 | test $T = $(git rev-parse --verify tag1) && |
| 163 | test $A = $(git rev-parse --verify tag1^0) |
| 164 | ) && |
| 165 | get_needs $U >actual && |
| 166 | test_cmp expect actual |
| 167 | ' |
| 168 | |
| 169 | test_expect_success 'fetch specific OID with tag following' ' |
| 170 | git init --bare clone3.git && |
| 171 | ( |
| 172 | cd clone3.git && |
| 173 | git remote add origin .. && |
| 174 | git fetch origin $B:refs/heads/main && |
| 175 | |
| 176 | git -C .. for-each-ref >expect && |
| 177 | git for-each-ref >actual && |
| 178 | |
| 179 | test_cmp expect actual |
| 180 | ) |
| 181 | ' |
| 182 | |
| 183 | test_done |