t / t1700-split-index.shon commit tag: respect `pager.tag` in list-mode only (de121ff)
   1#!/bin/sh
   2
   3test_description='split index mode tests'
   4
   5. ./test-lib.sh
   6
   7# We need total control of index splitting here
   8sane_unset GIT_TEST_SPLIT_INDEX
   9
  10test_expect_success 'enable split index' '
  11        git config splitIndex.maxPercentChange 100 &&
  12        git update-index --split-index &&
  13        test-dump-split-index .git/index >actual &&
  14        indexversion=$(test-index-version <.git/index) &&
  15        if test "$indexversion" = "4"
  16        then
  17                own=432ef4b63f32193984f339431fd50ca796493569
  18                base=508851a7f0dfa8691e9f69c7f055865389012491
  19        else
  20                own=8299b0bcd1ac364e5f1d7768efb62fa2da79a339
  21                base=39d890139ee5356c7ef572216cebcd27aa41f9df
  22        fi &&
  23        cat >expect <<-EOF &&
  24        own $own
  25        base $base
  26        replacements:
  27        deletions:
  28        EOF
  29        test_cmp expect actual
  30'
  31
  32test_expect_success 'add one file' '
  33        : >one &&
  34        git update-index --add one &&
  35        git ls-files --stage >ls-files.actual &&
  36        cat >ls-files.expect <<-EOF &&
  37        100644 $EMPTY_BLOB 0    one
  38        EOF
  39        test_cmp ls-files.expect ls-files.actual &&
  40
  41        test-dump-split-index .git/index | sed "/^own/d" >actual &&
  42        cat >expect <<-EOF &&
  43        base $base
  44        100644 $EMPTY_BLOB 0    one
  45        replacements:
  46        deletions:
  47        EOF
  48        test_cmp expect actual
  49'
  50
  51test_expect_success 'disable split index' '
  52        git update-index --no-split-index &&
  53        git ls-files --stage >ls-files.actual &&
  54        cat >ls-files.expect <<-EOF &&
  55        100644 $EMPTY_BLOB 0    one
  56        EOF
  57        test_cmp ls-files.expect ls-files.actual &&
  58
  59        BASE=$(test-dump-split-index .git/index | grep "^own" | sed "s/own/base/") &&
  60        test-dump-split-index .git/index | sed "/^own/d" >actual &&
  61        cat >expect <<-EOF &&
  62        not a split index
  63        EOF
  64        test_cmp expect actual
  65'
  66
  67test_expect_success 'enable split index again, "one" now belongs to base index"' '
  68        git update-index --split-index &&
  69        git ls-files --stage >ls-files.actual &&
  70        cat >ls-files.expect <<-EOF &&
  71        100644 $EMPTY_BLOB 0    one
  72        EOF
  73        test_cmp ls-files.expect ls-files.actual &&
  74
  75        test-dump-split-index .git/index | sed "/^own/d" >actual &&
  76        cat >expect <<-EOF &&
  77        $BASE
  78        replacements:
  79        deletions:
  80        EOF
  81        test_cmp expect actual
  82'
  83
  84test_expect_success 'modify original file, base index untouched' '
  85        echo modified >one &&
  86        git update-index one &&
  87        git ls-files --stage >ls-files.actual &&
  88        cat >ls-files.expect <<-EOF &&
  89        100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0       one
  90        EOF
  91        test_cmp ls-files.expect ls-files.actual &&
  92
  93        test-dump-split-index .git/index | sed "/^own/d" >actual &&
  94        q_to_tab >expect <<-EOF &&
  95        $BASE
  96        100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
  97        replacements: 0
  98        deletions:
  99        EOF
 100        test_cmp expect actual
 101'
 102
 103test_expect_success 'add another file, which stays index' '
 104        : >two &&
 105        git update-index --add two &&
 106        git ls-files --stage >ls-files.actual &&
 107        cat >ls-files.expect <<-EOF &&
 108        100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0       one
 109        100644 $EMPTY_BLOB 0    two
 110        EOF
 111        test_cmp ls-files.expect ls-files.actual &&
 112
 113        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 114        q_to_tab >expect <<-EOF &&
 115        $BASE
 116        100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
 117        100644 $EMPTY_BLOB 0    two
 118        replacements: 0
 119        deletions:
 120        EOF
 121        test_cmp expect actual
 122'
 123
 124test_expect_success 'remove file not in base index' '
 125        git update-index --force-remove two &&
 126        git ls-files --stage >ls-files.actual &&
 127        cat >ls-files.expect <<-EOF &&
 128        100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0       one
 129        EOF
 130        test_cmp ls-files.expect ls-files.actual &&
 131
 132        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 133        q_to_tab >expect <<-EOF &&
 134        $BASE
 135        100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
 136        replacements: 0
 137        deletions:
 138        EOF
 139        test_cmp expect actual
 140'
 141
 142test_expect_success 'remove file in base index' '
 143        git update-index --force-remove one &&
 144        git ls-files --stage >ls-files.actual &&
 145        cat >ls-files.expect <<-EOF &&
 146        EOF
 147        test_cmp ls-files.expect ls-files.actual &&
 148
 149        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 150        cat >expect <<-EOF &&
 151        $BASE
 152        replacements:
 153        deletions: 0
 154        EOF
 155        test_cmp expect actual
 156'
 157
 158test_expect_success 'add original file back' '
 159        : >one &&
 160        git update-index --add one &&
 161        git ls-files --stage >ls-files.actual &&
 162        cat >ls-files.expect <<-EOF &&
 163        100644 $EMPTY_BLOB 0    one
 164        EOF
 165        test_cmp ls-files.expect ls-files.actual &&
 166
 167        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 168        cat >expect <<-EOF &&
 169        $BASE
 170        100644 $EMPTY_BLOB 0    one
 171        replacements:
 172        deletions: 0
 173        EOF
 174        test_cmp expect actual
 175'
 176
 177test_expect_success 'add new file' '
 178        : >two &&
 179        git update-index --add two &&
 180        git ls-files --stage >actual &&
 181        cat >expect <<-EOF &&
 182        100644 $EMPTY_BLOB 0    one
 183        100644 $EMPTY_BLOB 0    two
 184        EOF
 185        test_cmp expect actual
 186'
 187
 188test_expect_success 'unify index, two files remain' '
 189        git update-index --no-split-index &&
 190        git ls-files --stage >ls-files.actual &&
 191        cat >ls-files.expect <<-EOF &&
 192        100644 $EMPTY_BLOB 0    one
 193        100644 $EMPTY_BLOB 0    two
 194        EOF
 195        test_cmp ls-files.expect ls-files.actual &&
 196
 197        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 198        cat >expect <<-EOF &&
 199        not a split index
 200        EOF
 201        test_cmp expect actual
 202'
 203
 204test_expect_success 'rev-parse --shared-index-path' '
 205        test_create_repo split-index &&
 206        (
 207                cd split-index &&
 208                git update-index --split-index &&
 209                echo .git/sharedindex* >expect &&
 210                git rev-parse --shared-index-path >actual &&
 211                test_cmp expect actual &&
 212                mkdir subdirectory &&
 213                cd subdirectory &&
 214                echo ../.git/sharedindex* >expect &&
 215                git rev-parse --shared-index-path >actual &&
 216                test_cmp expect actual
 217        )
 218'
 219
 220test_expect_success 'set core.splitIndex config variable to true' '
 221        git config core.splitIndex true &&
 222        : >three &&
 223        git update-index --add three &&
 224        git ls-files --stage >ls-files.actual &&
 225        cat >ls-files.expect <<-EOF &&
 226        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       one
 227        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       three
 228        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       two
 229        EOF
 230        test_cmp ls-files.expect ls-files.actual &&
 231        BASE=$(test-dump-split-index .git/index | grep "^base") &&
 232        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 233        cat >expect <<-EOF &&
 234        $BASE
 235        replacements:
 236        deletions:
 237        EOF
 238        test_cmp expect actual
 239'
 240
 241test_expect_success 'set core.splitIndex config variable to false' '
 242        git config core.splitIndex false &&
 243        git update-index --force-remove three &&
 244        git ls-files --stage >ls-files.actual &&
 245        cat >ls-files.expect <<-EOF &&
 246        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       one
 247        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       two
 248        EOF
 249        test_cmp ls-files.expect ls-files.actual &&
 250        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 251        cat >expect <<-EOF &&
 252        not a split index
 253        EOF
 254        test_cmp expect actual
 255'
 256
 257test_expect_success 'set core.splitIndex config variable to true' '
 258        git config core.splitIndex true &&
 259        : >three &&
 260        git update-index --add three &&
 261        BASE=$(test-dump-split-index .git/index | grep "^base") &&
 262        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 263        cat >expect <<-EOF &&
 264        $BASE
 265        replacements:
 266        deletions:
 267        EOF
 268        test_cmp expect actual &&
 269        : >four &&
 270        git update-index --add four &&
 271        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 272        cat >expect <<-EOF &&
 273        $BASE
 274        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       four
 275        replacements:
 276        deletions:
 277        EOF
 278        test_cmp expect actual
 279'
 280
 281test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
 282        git config --unset splitIndex.maxPercentChange &&
 283        : >five &&
 284        git update-index --add five &&
 285        BASE=$(test-dump-split-index .git/index | grep "^base") &&
 286        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 287        cat >expect <<-EOF &&
 288        $BASE
 289        replacements:
 290        deletions:
 291        EOF
 292        test_cmp expect actual &&
 293        : >six &&
 294        git update-index --add six &&
 295        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 296        cat >expect <<-EOF &&
 297        $BASE
 298        100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       six
 299        replacements:
 300        deletions:
 301        EOF
 302        test_cmp expect actual
 303'
 304
 305test_expect_success 'check splitIndex.maxPercentChange set to 0' '
 306        git config splitIndex.maxPercentChange 0 &&
 307        : >seven &&
 308        git update-index --add seven &&
 309        BASE=$(test-dump-split-index .git/index | grep "^base") &&
 310        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 311        cat >expect <<-EOF &&
 312        $BASE
 313        replacements:
 314        deletions:
 315        EOF
 316        test_cmp expect actual &&
 317        : >eight &&
 318        git update-index --add eight &&
 319        BASE=$(test-dump-split-index .git/index | grep "^base") &&
 320        test-dump-split-index .git/index | sed "/^own/d" >actual &&
 321        cat >expect <<-EOF &&
 322        $BASE
 323        replacements:
 324        deletions:
 325        EOF
 326        test_cmp expect actual
 327'
 328
 329test_expect_success 'shared index files expire after 2 weeks by default' '
 330        : >ten &&
 331        git update-index --add ten &&
 332        test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
 333        just_under_2_weeks_ago=$((5-14*86400)) &&
 334        test-chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
 335        : >eleven &&
 336        git update-index --add eleven &&
 337        test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
 338        just_over_2_weeks_ago=$((-1-14*86400)) &&
 339        test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
 340        : >twelve &&
 341        git update-index --add twelve &&
 342        test $(ls .git/sharedindex.* | wc -l) -le 2
 343'
 344
 345test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
 346        git config splitIndex.sharedIndexExpire "16.days.ago" &&
 347        test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
 348        : >thirteen &&
 349        git update-index --add thirteen &&
 350        test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
 351        just_over_16_days_ago=$((-1-16*86400)) &&
 352        test-chmtime =$just_over_16_days_ago .git/sharedindex.* &&
 353        : >fourteen &&
 354        git update-index --add fourteen &&
 355        test $(ls .git/sharedindex.* | wc -l) -le 2
 356'
 357
 358test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"' '
 359        git config splitIndex.sharedIndexExpire never &&
 360        just_10_years_ago=$((-365*10*86400)) &&
 361        test-chmtime =$just_10_years_ago .git/sharedindex.* &&
 362        : >fifteen &&
 363        git update-index --add fifteen &&
 364        test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
 365        git config splitIndex.sharedIndexExpire now &&
 366        just_1_second_ago=-1 &&
 367        test-chmtime =$just_1_second_ago .git/sharedindex.* &&
 368        : >sixteen &&
 369        git update-index --add sixteen &&
 370        test $(ls .git/sharedindex.* | wc -l) -le 2
 371'
 372
 373while read -r mode modebits
 374do
 375        test_expect_success POSIXPERM "split index respects core.sharedrepository $mode" '
 376                # Remove existing shared index files
 377                git config core.splitIndex false &&
 378                git update-index --force-remove one &&
 379                rm -f .git/sharedindex.* &&
 380                # Create one new shared index file
 381                git config core.sharedrepository "$mode" &&
 382                git config core.splitIndex true &&
 383                : >one &&
 384                git update-index --add one &&
 385                echo "$modebits" >expect &&
 386                test_modebits .git/index >actual &&
 387                test_cmp expect actual &&
 388                shared=$(ls .git/sharedindex.*) &&
 389                case "$shared" in
 390                *" "*)
 391                        # we have more than one???
 392                        false ;;
 393                *)
 394                        test_modebits "$shared" >actual &&
 395                        test_cmp expect actual ;;
 396                esac
 397        '
 398done <<\EOF
 3990666 -rw-rw-rw-
 4000642 -rw-r---w-
 401EOF
 402
 403test_done