]>
Commit | Line | Data |
---|---|---|
bf7930ca JT |
1 | #!/bin/sh |
2 | ||
3 | test_description='fetch/push involving ref namespaces' | |
4 | . ./test-lib.sh | |
5 | ||
6 | test_expect_success setup ' | |
f1762d77 | 7 | git config --global protocol.ext.allow user && |
bf7930ca JT |
8 | test_tick && |
9 | git init original && | |
10 | ( | |
11 | cd original && | |
12 | echo 0 >count && | |
13 | git add count && | |
14 | test_commit 0 && | |
15 | echo 1 >count && | |
16 | git add count && | |
17 | test_commit 1 && | |
18 | git remote add pushee-namespaced "ext::git --namespace=namespace %s ../pushee" && | |
19 | git remote add pushee-unnamespaced ../pushee | |
20 | ) && | |
21 | commit0=$(cd original && git rev-parse HEAD^) && | |
22 | commit1=$(cd original && git rev-parse HEAD) && | |
23 | git init pushee && | |
24 | git init puller | |
25 | ' | |
26 | ||
27 | test_expect_success 'pushing into a repository using a ref namespace' ' | |
28 | ( | |
29 | cd original && | |
30 | git push pushee-namespaced master && | |
31 | git ls-remote pushee-namespaced >actual && | |
32 | printf "$commit1\trefs/heads/master\n" >expected && | |
33 | test_cmp expected actual && | |
34 | git push pushee-namespaced --tags && | |
35 | git ls-remote pushee-namespaced >actual && | |
36 | printf "$commit0\trefs/tags/0\n" >>expected && | |
37 | printf "$commit1\trefs/tags/1\n" >>expected && | |
38 | test_cmp expected actual && | |
39 | # Verify that the GIT_NAMESPACE environment variable works as well | |
40 | GIT_NAMESPACE=namespace git ls-remote "ext::git %s ../pushee" >actual && | |
41 | test_cmp expected actual && | |
42 | # Verify that --namespace overrides GIT_NAMESPACE | |
43 | GIT_NAMESPACE=garbage git ls-remote pushee-namespaced >actual && | |
44 | test_cmp expected actual && | |
45 | # Try a namespace with no content | |
46 | git ls-remote "ext::git --namespace=garbage %s ../pushee" >actual && | |
ec21ac8c | 47 | test_must_be_empty actual && |
bf7930ca JT |
48 | git ls-remote pushee-unnamespaced >actual && |
49 | sed -e "s|refs/|refs/namespaces/namespace/refs/|" expected >expected.unnamespaced && | |
50 | test_cmp expected.unnamespaced actual | |
51 | ) | |
52 | ' | |
53 | ||
54 | test_expect_success 'pulling from a repository using a ref namespace' ' | |
55 | ( | |
56 | cd puller && | |
57 | git remote add -f pushee-namespaced "ext::git --namespace=namespace %s ../pushee" && | |
58 | git for-each-ref refs/ >actual && | |
59 | printf "$commit1 commit\trefs/remotes/pushee-namespaced/master\n" >expected && | |
60 | printf "$commit0 commit\trefs/tags/0\n" >>expected && | |
61 | printf "$commit1 commit\trefs/tags/1\n" >>expected && | |
62 | test_cmp expected actual | |
63 | ) | |
64 | ' | |
65 | ||
66 | # This test with clone --mirror checks for possible regressions in clone | |
67 | # or the machinery underneath it. It ensures that no future change | |
68 | # causes clone to ignore refs in refs/namespaces/*. In particular, it | |
69 | # protects against a regression caused by any future change to the refs | |
70 | # machinery that might cause it to ignore refs outside of refs/heads/* | |
71 | # or refs/tags/*. More generally, this test also checks the high-level | |
72 | # functionality of using clone --mirror to back up a set of repos hosted | |
73 | # in the namespaces of a single repo. | |
74 | test_expect_success 'mirroring a repository using a ref namespace' ' | |
75 | git clone --mirror pushee mirror && | |
76 | ( | |
77 | cd mirror && | |
78 | git for-each-ref refs/ >actual && | |
79 | printf "$commit1 commit\trefs/namespaces/namespace/refs/heads/master\n" >expected && | |
80 | printf "$commit0 commit\trefs/namespaces/namespace/refs/tags/0\n" >>expected && | |
81 | printf "$commit1 commit\trefs/namespaces/namespace/refs/tags/1\n" >>expected && | |
82 | test_cmp expected actual | |
83 | ) | |
84 | ' | |
85 | ||
948bfa2c LF |
86 | test_expect_success 'hide namespaced refs with transfer.hideRefs' ' |
87 | GIT_NAMESPACE=namespace \ | |
88 | git -C pushee -c transfer.hideRefs=refs/tags \ | |
89 | ls-remote "ext::git %s ." >actual && | |
90 | printf "$commit1\trefs/heads/master\n" >expected && | |
91 | test_cmp expected actual | |
92 | ' | |
93 | ||
94 | test_expect_success 'check that transfer.hideRefs does not match unstripped refs' ' | |
95 | GIT_NAMESPACE=namespace \ | |
96 | git -C pushee -c transfer.hideRefs=refs/namespaces/namespace/refs/tags \ | |
97 | ls-remote "ext::git %s ." >actual && | |
98 | printf "$commit1\trefs/heads/master\n" >expected && | |
99 | printf "$commit0\trefs/tags/0\n" >>expected && | |
100 | printf "$commit1\trefs/tags/1\n" >>expected && | |
101 | test_cmp expected actual | |
102 | ' | |
103 | ||
104 | test_expect_success 'hide full refs with transfer.hideRefs' ' | |
105 | GIT_NAMESPACE=namespace \ | |
106 | git -C pushee -c transfer.hideRefs="^refs/namespaces/namespace/refs/tags" \ | |
107 | ls-remote "ext::git %s ." >actual && | |
108 | printf "$commit1\trefs/heads/master\n" >expected && | |
109 | test_cmp expected actual | |
110 | ' | |
111 | ||
112 | test_expect_success 'try to update a hidden ref' ' | |
113 | test_config -C pushee transfer.hideRefs refs/heads/master && | |
114 | test_must_fail git -C original push pushee-namespaced master | |
115 | ' | |
116 | ||
117 | test_expect_success 'try to update a ref that is not hidden' ' | |
118 | test_config -C pushee transfer.hideRefs refs/namespaces/namespace/refs/heads/master && | |
119 | git -C original push pushee-namespaced master | |
120 | ' | |
121 | ||
122 | test_expect_success 'try to update a hidden full ref' ' | |
123 | test_config -C pushee transfer.hideRefs "^refs/namespaces/namespace/refs/heads/master" && | |
124 | test_must_fail git -C original push pushee-namespaced master | |
125 | ' | |
126 | ||
533e0882 JK |
127 | test_expect_success 'set up ambiguous HEAD' ' |
128 | git init ambiguous && | |
129 | ( | |
130 | cd ambiguous && | |
131 | git commit --allow-empty -m foo && | |
132 | git update-ref refs/namespaces/ns/refs/heads/one HEAD && | |
133 | git update-ref refs/namespaces/ns/refs/heads/two HEAD && | |
134 | git symbolic-ref refs/namespaces/ns/HEAD \ | |
135 | refs/namespaces/ns/refs/heads/two | |
136 | ) | |
137 | ' | |
138 | ||
139 | test_expect_success 'clone chooses correct HEAD (v0)' ' | |
140 | GIT_NAMESPACE=ns git -c protocol.version=0 \ | |
141 | clone ambiguous ambiguous-v0 && | |
142 | echo refs/heads/two >expect && | |
143 | git -C ambiguous-v0 symbolic-ref HEAD >actual && | |
144 | test_cmp expect actual | |
145 | ' | |
146 | ||
147 | test_expect_success 'clone chooses correct HEAD (v2)' ' | |
148 | GIT_NAMESPACE=ns git -c protocol.version=2 \ | |
149 | clone ambiguous ambiguous-v2 && | |
150 | echo refs/heads/two >expect && | |
151 | git -C ambiguous-v2 symbolic-ref HEAD >actual && | |
152 | test_cmp expect actual | |
153 | ' | |
154 | ||
bf7930ca | 155 | test_done |