t / t5612-clone-refspec.shon commit promisor-remote: parse remote.*.partialclonefilter (fa3d1b6)
   1#!/bin/sh
   2
   3test_description='test refspec written by clone-command'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup' '
   7        # Make two branches, "master" and "side"
   8        echo one >file &&
   9        git add file &&
  10        git commit -m one &&
  11        echo two >file &&
  12        git commit -a -m two &&
  13        git tag two &&
  14        echo three >file &&
  15        git commit -a -m three &&
  16        git checkout -b side &&
  17        echo four >file &&
  18        git commit -a -m four &&
  19        git checkout master &&
  20        git tag five &&
  21
  22        # default clone
  23        git clone . dir_all &&
  24
  25        # default clone --no-tags
  26        git clone --no-tags . dir_all_no_tags &&
  27
  28        # default --single that follows HEAD=master
  29        git clone --single-branch . dir_master &&
  30
  31        # default --single that follows HEAD=master with no tags
  32        git clone --single-branch --no-tags . dir_master_no_tags &&
  33
  34        # default --single that follows HEAD=side
  35        git checkout side &&
  36        git clone --single-branch . dir_side &&
  37
  38        # explicit --single that follows side
  39        git checkout master &&
  40        git clone --single-branch --branch side . dir_side2 &&
  41
  42        # default --single with --mirror
  43        git clone --single-branch --mirror . dir_mirror &&
  44
  45        # default --single with --branch and --mirror
  46        git clone --single-branch --mirror --branch side . dir_mirror_side &&
  47
  48        # --single that does not know what branch to follow
  49        git checkout two^ &&
  50        git clone --single-branch . dir_detached &&
  51
  52        # explicit --single with tag
  53        git clone --single-branch --branch two . dir_tag &&
  54
  55        # explicit --single with tag and --no-tags
  56        git clone --single-branch --no-tags --branch two . dir_tag_no_tags &&
  57
  58        # advance both "master" and "side" branches
  59        git checkout side &&
  60        echo five >file &&
  61        git commit -a -m five &&
  62        git checkout master &&
  63        echo six >file &&
  64        git commit -a -m six &&
  65
  66        # update tag
  67        git tag -d two && git tag two
  68'
  69
  70test_expect_success 'by default all branches will be kept updated' '
  71        (
  72                cd dir_all &&
  73                git fetch &&
  74                git for-each-ref refs/remotes/origin |
  75                sed -e "/HEAD$/d" \
  76                    -e "s|/remotes/origin/|/heads/|" >../actual
  77        ) &&
  78        # follow both master and side
  79        git for-each-ref refs/heads >expect &&
  80        test_cmp expect actual
  81'
  82
  83test_expect_success 'by default no tags will be kept updated' '
  84        (
  85                cd dir_all &&
  86                git fetch &&
  87                git for-each-ref refs/tags >../actual
  88        ) &&
  89        git for-each-ref refs/tags >expect &&
  90        test_must_fail test_cmp expect actual &&
  91        test_line_count = 2 actual
  92'
  93
  94test_expect_success 'clone with --no-tags' '
  95        (
  96                cd dir_all_no_tags &&
  97                git fetch &&
  98                git for-each-ref refs/tags >../actual
  99        ) &&
 100        test_must_be_empty actual
 101'
 102
 103test_expect_success '--single-branch while HEAD pointing at master' '
 104        (
 105                cd dir_master &&
 106                git fetch --force &&
 107                git for-each-ref refs/remotes/origin |
 108                sed -e "/HEAD$/d" \
 109                    -e "s|/remotes/origin/|/heads/|" >../actual
 110        ) &&
 111        # only follow master
 112        git for-each-ref refs/heads/master >expect &&
 113        # get & check latest tags
 114        test_cmp expect actual &&
 115        (
 116                cd dir_master &&
 117                git fetch --tags --force &&
 118                git for-each-ref refs/tags >../actual
 119        ) &&
 120        git for-each-ref refs/tags >expect &&
 121        test_cmp expect actual &&
 122        test_line_count = 2 actual
 123'
 124
 125test_expect_success '--single-branch while HEAD pointing at master and --no-tags' '
 126        (
 127                cd dir_master_no_tags &&
 128                git fetch &&
 129                git for-each-ref refs/remotes/origin |
 130                sed -e "/HEAD$/d" \
 131                    -e "s|/remotes/origin/|/heads/|" >../actual
 132        ) &&
 133        # only follow master
 134        git for-each-ref refs/heads/master >expect &&
 135        test_cmp expect actual &&
 136        # get tags (noop)
 137        (
 138                cd dir_master_no_tags &&
 139                git fetch &&
 140                git for-each-ref refs/tags >../actual
 141        ) &&
 142        test_must_be_empty actual &&
 143        test_line_count = 0 actual &&
 144        # get tags with --tags overrides tagOpt
 145        (
 146                cd dir_master_no_tags &&
 147                git fetch --tags &&
 148                git for-each-ref refs/tags >../actual
 149        ) &&
 150        git for-each-ref refs/tags >expect &&
 151        test_cmp expect actual &&
 152        test_line_count = 2 actual
 153'
 154
 155test_expect_success '--single-branch while HEAD pointing at side' '
 156        (
 157                cd dir_side &&
 158                git fetch &&
 159                git for-each-ref refs/remotes/origin |
 160                sed -e "/HEAD$/d" \
 161                    -e "s|/remotes/origin/|/heads/|" >../actual
 162        ) &&
 163        # only follow side
 164        git for-each-ref refs/heads/side >expect &&
 165        test_cmp expect actual
 166'
 167
 168test_expect_success '--single-branch with explicit --branch side' '
 169        (
 170                cd dir_side2 &&
 171                git fetch &&
 172                git for-each-ref refs/remotes/origin |
 173                sed -e "/HEAD$/d" \
 174                    -e "s|/remotes/origin/|/heads/|" >../actual
 175        ) &&
 176        # only follow side
 177        git for-each-ref refs/heads/side >expect &&
 178        test_cmp expect actual
 179'
 180
 181test_expect_success '--single-branch with explicit --branch with tag fetches updated tag' '
 182        (
 183                cd dir_tag &&
 184                git fetch &&
 185                git for-each-ref refs/tags >../actual
 186        ) &&
 187        git for-each-ref refs/tags >expect &&
 188        test_cmp expect actual
 189'
 190
 191test_expect_success '--single-branch with explicit --branch with tag fetches updated tag despite --no-tags' '
 192        (
 193                cd dir_tag_no_tags &&
 194                git fetch &&
 195                git for-each-ref refs/tags >../actual
 196        ) &&
 197        git for-each-ref refs/tags/two >expect &&
 198        test_cmp expect actual &&
 199        test_line_count = 1 actual
 200'
 201
 202test_expect_success '--single-branch with --mirror' '
 203        (
 204                cd dir_mirror &&
 205                git fetch &&
 206                git for-each-ref refs > ../actual
 207        ) &&
 208        git for-each-ref refs >expect &&
 209        test_cmp expect actual
 210'
 211
 212test_expect_success '--single-branch with explicit --branch and --mirror' '
 213        (
 214                cd dir_mirror_side &&
 215                git fetch &&
 216                git for-each-ref refs > ../actual
 217        ) &&
 218        git for-each-ref refs >expect &&
 219        test_cmp expect actual
 220'
 221
 222test_expect_success '--single-branch with detached' '
 223        (
 224                cd dir_detached &&
 225                git fetch &&
 226                git for-each-ref refs/remotes/origin |
 227                sed -e "/HEAD$/d" \
 228                    -e "s|/remotes/origin/|/heads/|" >../actual
 229        ) &&
 230        # nothing
 231        test_must_be_empty actual
 232'
 233
 234test_done