t / t5509-fetch-push-namespaces.shon commit Merge branch 'js/mingw-http-ssl' (d7b1859)
   1#!/bin/sh
   2
   3test_description='fetch/push involving ref namespaces'
   4. ./test-lib.sh
   5
   6test_expect_success setup '
   7        git config --global protocol.ext.allow user &&
   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
  27test_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 &&
  47                test_must_be_empty actual &&
  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
  54test_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.
  74test_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
  86test_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
  94test_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
 104test_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
 112test_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
 117test_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
 122test_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
 127test_done