Merge branch 'jc/exclusion-doc'
[alt-git.git] / t / t5509-fetch-push-namespaces.sh
blobbc44ac36d57615b516018a2602c15bea8085e316
1 #!/bin/sh
3 test_description='fetch/push involving ref namespaces'
4 . ./test-lib.sh
6 test_expect_success setup '
7 test_tick &&
8 git init original &&
10 cd original &&
11 echo 0 >count &&
12 git add count &&
13 test_commit 0 &&
14 echo 1 >count &&
15 git add count &&
16 test_commit 1 &&
17 git remote add pushee-namespaced "ext::git --namespace=namespace %s ../pushee" &&
18 git remote add pushee-unnamespaced ../pushee
19 ) &&
20 commit0=$(cd original && git rev-parse HEAD^) &&
21 commit1=$(cd original && git rev-parse HEAD) &&
22 git init pushee &&
23 git init puller
26 test_expect_success 'pushing into a repository using a ref namespace' '
28 cd original &&
29 git push pushee-namespaced master &&
30 git ls-remote pushee-namespaced >actual &&
31 printf "$commit1\trefs/heads/master\n" >expected &&
32 test_cmp expected actual &&
33 git push pushee-namespaced --tags &&
34 git ls-remote pushee-namespaced >actual &&
35 printf "$commit0\trefs/tags/0\n" >>expected &&
36 printf "$commit1\trefs/tags/1\n" >>expected &&
37 test_cmp expected actual &&
38 # Verify that the GIT_NAMESPACE environment variable works as well
39 GIT_NAMESPACE=namespace git ls-remote "ext::git %s ../pushee" >actual &&
40 test_cmp expected actual &&
41 # Verify that --namespace overrides GIT_NAMESPACE
42 GIT_NAMESPACE=garbage git ls-remote pushee-namespaced >actual &&
43 test_cmp expected actual &&
44 # Try a namespace with no content
45 git ls-remote "ext::git --namespace=garbage %s ../pushee" >actual &&
46 test_cmp /dev/null actual &&
47 git ls-remote pushee-unnamespaced >actual &&
48 sed -e "s|refs/|refs/namespaces/namespace/refs/|" expected >expected.unnamespaced &&
49 test_cmp expected.unnamespaced actual
53 test_expect_success 'pulling from a repository using a ref namespace' '
55 cd puller &&
56 git remote add -f pushee-namespaced "ext::git --namespace=namespace %s ../pushee" &&
57 git for-each-ref refs/ >actual &&
58 printf "$commit1 commit\trefs/remotes/pushee-namespaced/master\n" >expected &&
59 printf "$commit0 commit\trefs/tags/0\n" >>expected &&
60 printf "$commit1 commit\trefs/tags/1\n" >>expected &&
61 test_cmp expected actual
65 # This test with clone --mirror checks for possible regressions in clone
66 # or the machinery underneath it. It ensures that no future change
67 # causes clone to ignore refs in refs/namespaces/*. In particular, it
68 # protects against a regression caused by any future change to the refs
69 # machinery that might cause it to ignore refs outside of refs/heads/*
70 # or refs/tags/*. More generally, this test also checks the high-level
71 # functionality of using clone --mirror to back up a set of repos hosted
72 # in the namespaces of a single repo.
73 test_expect_success 'mirroring a repository using a ref namespace' '
74 git clone --mirror pushee mirror &&
76 cd mirror &&
77 git for-each-ref refs/ >actual &&
78 printf "$commit1 commit\trefs/namespaces/namespace/refs/heads/master\n" >expected &&
79 printf "$commit0 commit\trefs/namespaces/namespace/refs/tags/0\n" >>expected &&
80 printf "$commit1 commit\trefs/namespaces/namespace/refs/tags/1\n" >>expected &&
81 test_cmp expected actual
85 test_expect_success 'hide namespaced refs with transfer.hideRefs' '
86 GIT_NAMESPACE=namespace \
87 git -C pushee -c transfer.hideRefs=refs/tags \
88 ls-remote "ext::git %s ." >actual &&
89 printf "$commit1\trefs/heads/master\n" >expected &&
90 test_cmp expected actual
93 test_expect_success 'check that transfer.hideRefs does not match unstripped refs' '
94 GIT_NAMESPACE=namespace \
95 git -C pushee -c transfer.hideRefs=refs/namespaces/namespace/refs/tags \
96 ls-remote "ext::git %s ." >actual &&
97 printf "$commit1\trefs/heads/master\n" >expected &&
98 printf "$commit0\trefs/tags/0\n" >>expected &&
99 printf "$commit1\trefs/tags/1\n" >>expected &&
100 test_cmp expected actual
103 test_expect_success 'hide full refs with transfer.hideRefs' '
104 GIT_NAMESPACE=namespace \
105 git -C pushee -c transfer.hideRefs="^refs/namespaces/namespace/refs/tags" \
106 ls-remote "ext::git %s ." >actual &&
107 printf "$commit1\trefs/heads/master\n" >expected &&
108 test_cmp expected actual
111 test_expect_success 'try to update a hidden ref' '
112 test_config -C pushee transfer.hideRefs refs/heads/master &&
113 test_must_fail git -C original push pushee-namespaced master
116 test_expect_success 'try to update a ref that is not hidden' '
117 test_config -C pushee transfer.hideRefs refs/namespaces/namespace/refs/heads/master &&
118 git -C original push pushee-namespaced master
121 test_expect_success 'try to update a hidden full ref' '
122 test_config -C pushee transfer.hideRefs "^refs/namespaces/namespace/refs/heads/master" &&
123 test_must_fail git -C original push pushee-namespaced master
126 test_done