]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5509-fetch-push-namespaces.sh
The second batch
[thirdparty/git.git] / t / t5509-fetch-push-namespaces.sh
CommitLineData
bf7930ca
JT
1#!/bin/sh
2
3test_description='fetch/push involving ref namespaces'
3275f4e8 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
bf7930ca
JT
7. ./test-lib.sh
8
9test_expect_success setup '
f1762d77 10 git config --global protocol.ext.allow user &&
bf7930ca
JT
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) &&
f8692114 26 git init --bare pushee &&
bf7930ca
JT
27 git init puller
28'
29
30test_expect_success 'pushing into a repository using a ref namespace' '
31 (
32 cd original &&
3275f4e8 33 git push pushee-namespaced main &&
bf7930ca 34 git ls-remote pushee-namespaced >actual &&
3275f4e8 35 printf "$commit1\trefs/heads/main\n" >expected &&
bf7930ca
JT
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 &&
ec21ac8c 50 test_must_be_empty actual &&
bf7930ca
JT
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
57test_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 &&
3275f4e8 62 printf "$commit1 commit\trefs/remotes/pushee-namespaced/main\n" >expected &&
bf7930ca
JT
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.
77test_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 &&
3275f4e8 82 printf "$commit1 commit\trefs/namespaces/namespace/refs/heads/main\n" >expected &&
bf7930ca
JT
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
948bfa2c
LF
89test_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 &&
3275f4e8 93 printf "$commit1\trefs/heads/main\n" >expected &&
948bfa2c
LF
94 test_cmp expected actual
95'
96
97test_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 &&
3275f4e8 101 printf "$commit1\trefs/heads/main\n" >expected &&
948bfa2c
LF
102 printf "$commit0\trefs/tags/0\n" >>expected &&
103 printf "$commit1\trefs/tags/1\n" >>expected &&
104 test_cmp expected actual
105'
106
107test_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 &&
3275f4e8 111 printf "$commit1\trefs/heads/main\n" >expected &&
948bfa2c
LF
112 test_cmp expected actual
113'
114
115test_expect_success 'try to update a hidden ref' '
3275f4e8
JS
116 test_config -C pushee transfer.hideRefs refs/heads/main &&
117 test_must_fail git -C original push pushee-namespaced main
948bfa2c
LF
118'
119
120test_expect_success 'try to update a ref that is not hidden' '
3275f4e8
JS
121 test_config -C pushee transfer.hideRefs refs/namespaces/namespace/refs/heads/main &&
122 git -C original push pushee-namespaced main
948bfa2c
LF
123'
124
125test_expect_success 'try to update a hidden full ref' '
3275f4e8
JS
126 test_config -C pushee transfer.hideRefs "^refs/namespaces/namespace/refs/heads/main" &&
127 test_must_fail git -C original push pushee-namespaced main
948bfa2c
LF
128'
129
533e0882
JK
130test_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
142test_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
150test_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
4ef34648
HV
158test_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" &&
3275f4e8 163 test_must_fail git push unborn-namespaced HEAD:main &&
4ef34648 164 git -C unborn config receive.denyCurrentBranch updateInstead &&
3275f4e8 165 git push unborn-namespaced HEAD:main
4ef34648
HV
166 )
167'
168
bf7930ca 169test_done