Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='fetch/push involving ref namespaces' |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
| 9 | test_expect_success setup ' |
Brandon Williams | f1762d7 | 2016-12-14 14:39:52 -0800 | [diff] [blame] | 10 | git config --global protocol.ext.allow user && |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 11 | test_tick && |
| 12 | git init original && |
| 13 | ( |
| 14 | cd original && |
| 15 | echo 0 >count && |
| 16 | git add count && |
| 17 | test_commit 0 && |
| 18 | echo 1 >count && |
| 19 | git add count && |
| 20 | test_commit 1 && |
| 21 | git remote add pushee-namespaced "ext::git --namespace=namespace %s ../pushee" && |
| 22 | git remote add pushee-unnamespaced ../pushee |
| 23 | ) && |
| 24 | commit0=$(cd original && git rev-parse HEAD^) && |
| 25 | commit1=$(cd original && git rev-parse HEAD) && |
Hariom Verma | f869211 | 2020-02-23 18:57:09 +0000 | [diff] [blame] | 26 | git init --bare pushee && |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 27 | git init puller |
| 28 | ' |
| 29 | |
| 30 | test_expect_success 'pushing into a repository using a ref namespace' ' |
| 31 | ( |
| 32 | cd original && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 33 | git push pushee-namespaced main && |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 34 | git ls-remote pushee-namespaced >actual && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 35 | printf "$commit1\trefs/heads/main\n" >expected && |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 36 | test_cmp expected actual && |
| 37 | git push pushee-namespaced --tags && |
| 38 | git ls-remote pushee-namespaced >actual && |
| 39 | printf "$commit0\trefs/tags/0\n" >>expected && |
| 40 | printf "$commit1\trefs/tags/1\n" >>expected && |
| 41 | test_cmp expected actual && |
| 42 | # Verify that the GIT_NAMESPACE environment variable works as well |
| 43 | GIT_NAMESPACE=namespace git ls-remote "ext::git %s ../pushee" >actual && |
| 44 | test_cmp expected actual && |
| 45 | # Verify that --namespace overrides GIT_NAMESPACE |
| 46 | GIT_NAMESPACE=garbage git ls-remote pushee-namespaced >actual && |
| 47 | test_cmp expected actual && |
| 48 | # Try a namespace with no content |
| 49 | git ls-remote "ext::git --namespace=garbage %s ../pushee" >actual && |
SZEDER Gábor | ec21ac8 | 2018-08-19 23:57:24 +0200 | [diff] [blame] | 50 | test_must_be_empty actual && |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 51 | git ls-remote pushee-unnamespaced >actual && |
| 52 | sed -e "s|refs/|refs/namespaces/namespace/refs/|" expected >expected.unnamespaced && |
| 53 | test_cmp expected.unnamespaced actual |
| 54 | ) |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'pulling from a repository using a ref namespace' ' |
| 58 | ( |
| 59 | cd puller && |
| 60 | git remote add -f pushee-namespaced "ext::git --namespace=namespace %s ../pushee" && |
| 61 | git for-each-ref refs/ >actual && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 62 | printf "$commit1 commit\trefs/remotes/pushee-namespaced/main\n" >expected && |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 63 | printf "$commit0 commit\trefs/tags/0\n" >>expected && |
| 64 | printf "$commit1 commit\trefs/tags/1\n" >>expected && |
| 65 | test_cmp expected actual |
| 66 | ) |
| 67 | ' |
| 68 | |
| 69 | # This test with clone --mirror checks for possible regressions in clone |
| 70 | # or the machinery underneath it. It ensures that no future change |
| 71 | # causes clone to ignore refs in refs/namespaces/*. In particular, it |
| 72 | # protects against a regression caused by any future change to the refs |
| 73 | # machinery that might cause it to ignore refs outside of refs/heads/* |
| 74 | # or refs/tags/*. More generally, this test also checks the high-level |
| 75 | # functionality of using clone --mirror to back up a set of repos hosted |
| 76 | # in the namespaces of a single repo. |
| 77 | test_expect_success 'mirroring a repository using a ref namespace' ' |
| 78 | git clone --mirror pushee mirror && |
| 79 | ( |
| 80 | cd mirror && |
| 81 | git for-each-ref refs/ >actual && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 82 | printf "$commit1 commit\trefs/namespaces/namespace/refs/heads/main\n" >expected && |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 83 | printf "$commit0 commit\trefs/namespaces/namespace/refs/tags/0\n" >>expected && |
| 84 | printf "$commit1 commit\trefs/namespaces/namespace/refs/tags/1\n" >>expected && |
| 85 | test_cmp expected actual |
| 86 | ) |
| 87 | ' |
| 88 | |
Lukas Fleischer | 948bfa2 | 2015-11-05 07:07:31 +0100 | [diff] [blame] | 89 | test_expect_success 'hide namespaced refs with transfer.hideRefs' ' |
| 90 | GIT_NAMESPACE=namespace \ |
| 91 | git -C pushee -c transfer.hideRefs=refs/tags \ |
| 92 | ls-remote "ext::git %s ." >actual && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 93 | printf "$commit1\trefs/heads/main\n" >expected && |
Lukas Fleischer | 948bfa2 | 2015-11-05 07:07:31 +0100 | [diff] [blame] | 94 | test_cmp expected actual |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'check that transfer.hideRefs does not match unstripped refs' ' |
| 98 | GIT_NAMESPACE=namespace \ |
| 99 | git -C pushee -c transfer.hideRefs=refs/namespaces/namespace/refs/tags \ |
| 100 | ls-remote "ext::git %s ." >actual && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 101 | printf "$commit1\trefs/heads/main\n" >expected && |
Lukas Fleischer | 948bfa2 | 2015-11-05 07:07:31 +0100 | [diff] [blame] | 102 | printf "$commit0\trefs/tags/0\n" >>expected && |
| 103 | printf "$commit1\trefs/tags/1\n" >>expected && |
| 104 | test_cmp expected actual |
| 105 | ' |
| 106 | |
| 107 | test_expect_success 'hide full refs with transfer.hideRefs' ' |
| 108 | GIT_NAMESPACE=namespace \ |
| 109 | git -C pushee -c transfer.hideRefs="^refs/namespaces/namespace/refs/tags" \ |
| 110 | ls-remote "ext::git %s ." >actual && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 111 | printf "$commit1\trefs/heads/main\n" >expected && |
Lukas Fleischer | 948bfa2 | 2015-11-05 07:07:31 +0100 | [diff] [blame] | 112 | test_cmp expected actual |
| 113 | ' |
| 114 | |
| 115 | test_expect_success 'try to update a hidden ref' ' |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 116 | test_config -C pushee transfer.hideRefs refs/heads/main && |
| 117 | test_must_fail git -C original push pushee-namespaced main |
Lukas Fleischer | 948bfa2 | 2015-11-05 07:07:31 +0100 | [diff] [blame] | 118 | ' |
| 119 | |
| 120 | test_expect_success 'try to update a ref that is not hidden' ' |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 121 | test_config -C pushee transfer.hideRefs refs/namespaces/namespace/refs/heads/main && |
| 122 | git -C original push pushee-namespaced main |
Lukas Fleischer | 948bfa2 | 2015-11-05 07:07:31 +0100 | [diff] [blame] | 123 | ' |
| 124 | |
| 125 | test_expect_success 'try to update a hidden full ref' ' |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 126 | test_config -C pushee transfer.hideRefs "^refs/namespaces/namespace/refs/heads/main" && |
| 127 | test_must_fail git -C original push pushee-namespaced main |
Lukas Fleischer | 948bfa2 | 2015-11-05 07:07:31 +0100 | [diff] [blame] | 128 | ' |
| 129 | |
Jeff King | 533e088 | 2019-05-23 02:11:21 -0400 | [diff] [blame] | 130 | test_expect_success 'set up ambiguous HEAD' ' |
| 131 | git init ambiguous && |
| 132 | ( |
| 133 | cd ambiguous && |
| 134 | git commit --allow-empty -m foo && |
| 135 | git update-ref refs/namespaces/ns/refs/heads/one HEAD && |
| 136 | git update-ref refs/namespaces/ns/refs/heads/two HEAD && |
| 137 | git symbolic-ref refs/namespaces/ns/HEAD \ |
| 138 | refs/namespaces/ns/refs/heads/two |
| 139 | ) |
| 140 | ' |
| 141 | |
| 142 | test_expect_success 'clone chooses correct HEAD (v0)' ' |
| 143 | GIT_NAMESPACE=ns git -c protocol.version=0 \ |
| 144 | clone ambiguous ambiguous-v0 && |
| 145 | echo refs/heads/two >expect && |
| 146 | git -C ambiguous-v0 symbolic-ref HEAD >actual && |
| 147 | test_cmp expect actual |
| 148 | ' |
| 149 | |
| 150 | test_expect_success 'clone chooses correct HEAD (v2)' ' |
| 151 | GIT_NAMESPACE=ns git -c protocol.version=2 \ |
| 152 | clone ambiguous ambiguous-v2 && |
| 153 | echo refs/heads/two >expect && |
| 154 | git -C ambiguous-v2 symbolic-ref HEAD >actual && |
| 155 | test_cmp expect actual |
| 156 | ' |
| 157 | |
Hariom Verma | 4ef3464 | 2020-02-23 18:57:10 +0000 | [diff] [blame] | 158 | test_expect_success 'denyCurrentBranch and unborn branch with ref namespace' ' |
| 159 | ( |
| 160 | cd original && |
| 161 | git init unborn && |
| 162 | git remote add unborn-namespaced "ext::git --namespace=namespace %s unborn" && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 163 | test_must_fail git push unborn-namespaced HEAD:main && |
Hariom Verma | 4ef3464 | 2020-02-23 18:57:10 +0000 | [diff] [blame] | 164 | git -C unborn config receive.denyCurrentBranch updateInstead && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 165 | git push unborn-namespaced HEAD:main |
Hariom Verma | 4ef3464 | 2020-02-23 18:57:10 +0000 | [diff] [blame] | 166 | ) |
| 167 | ' |
| 168 | |
Josh Triplett | bf7930c | 2011-07-21 13:10:54 -0700 | [diff] [blame] | 169 | test_done |