t / t5309-pack-delta-cycles.shon commit Merge branch 'ds/ci-commit-graph-and-midx' (5742ba5)
   1#!/bin/sh
   2
   3test_description='test index-pack handling of delta cycles in packfiles'
   4. ./test-lib.sh
   5. "$TEST_DIRECTORY"/lib-pack.sh
   6
   7if ! test_have_prereq SHA1
   8then
   9       skip_all='not using SHA-1 for objects'
  10       test_done
  11fi
  12
  13# Two similar-ish objects that we have computed deltas between.
  14A=01d7713666f4de822776c7622c10f1b07de280dc
  15B=e68fe8129b546b101aee9510c5328e7f21ca1d18
  16
  17# double-check our hand-constucted packs
  18test_expect_success 'index-pack works with a single delta (A->B)' '
  19        clear_packs &&
  20        {
  21                pack_header 2 &&
  22                pack_obj $A $B &&
  23                pack_obj $B
  24        } >ab.pack &&
  25        pack_trailer ab.pack &&
  26        git index-pack --stdin <ab.pack &&
  27        git cat-file -t $A &&
  28        git cat-file -t $B
  29'
  30
  31test_expect_success 'index-pack works with a single delta (B->A)' '
  32        clear_packs &&
  33        {
  34                pack_header 2 &&
  35                pack_obj $A &&
  36                pack_obj $B $A
  37        } >ba.pack &&
  38        pack_trailer ba.pack &&
  39        git index-pack --stdin <ba.pack &&
  40        git cat-file -t $A &&
  41        git cat-file -t $B
  42'
  43
  44test_expect_success 'index-pack detects missing base objects' '
  45        clear_packs &&
  46        {
  47                pack_header 1 &&
  48                pack_obj $A $B
  49        } >missing.pack &&
  50        pack_trailer missing.pack &&
  51        test_must_fail git index-pack --fix-thin --stdin <missing.pack
  52'
  53
  54test_expect_success 'index-pack detects REF_DELTA cycles' '
  55        clear_packs &&
  56        {
  57                pack_header 2 &&
  58                pack_obj $A $B &&
  59                pack_obj $B $A
  60        } >cycle.pack &&
  61        pack_trailer cycle.pack &&
  62        test_must_fail git index-pack --fix-thin --stdin <cycle.pack
  63'
  64
  65test_expect_failure 'failover to an object in another pack' '
  66        clear_packs &&
  67        git index-pack --stdin <ab.pack &&
  68        git index-pack --stdin --fix-thin <cycle.pack
  69'
  70
  71test_expect_failure 'failover to a duplicate object in the same pack' '
  72        clear_packs &&
  73        {
  74                pack_header 3 &&
  75                pack_obj $A $B &&
  76                pack_obj $B $A &&
  77                pack_obj $A
  78        } >recoverable.pack &&
  79        pack_trailer recoverable.pack &&
  80        git index-pack --fix-thin --stdin <recoverable.pack
  81'
  82
  83test_done