t / t5509-fetch-push-namespaces.shon commit merge: detect delete/modechange conflict (72fac66)
   1#!/bin/sh
   2
   3test_description='fetch/push involving ref namespaces'
   4. ./test-lib.sh
   5
   6test_expect_success setup '
   7        test_tick &&
   8        git init original &&
   9        (
  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
  24'
  25
  26test_expect_success 'pushing into a repository using a ref namespace' '
  27        (
  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
  50        )
  51'
  52
  53test_expect_success 'pulling from a repository using a ref namespace' '
  54        (
  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
  62        )
  63'
  64
  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.
  73test_expect_success 'mirroring a repository using a ref namespace' '
  74        git clone --mirror pushee mirror &&
  75        (
  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
  82        )
  83'
  84
  85test_done