t / t4054-diff-bogus-tree.shon commit Merge branch 'va/i18n-even-more' (eef32a0)
   1#!/bin/sh
   2
   3test_description='test diff with a bogus tree containing the null sha1'
   4. ./test-lib.sh
   5
   6test_expect_success 'create bogus tree' '
   7        bogus_tree=$(
   8                printf "100644 fooQQQQQQQQQQQQQQQQQQQQQ" |
   9                q_to_nul |
  10                git hash-object -w --stdin -t tree
  11        )
  12'
  13
  14test_expect_success 'create tree with matching file' '
  15        echo bar >foo &&
  16        git add foo &&
  17        good_tree=$(git write-tree) &&
  18        blob=$(git rev-parse :foo)
  19'
  20
  21test_expect_success 'raw diff shows null sha1 (addition)' '
  22        echo ":000000 100644 $_z40 $_z40 A      foo" >expect &&
  23        git diff-tree $EMPTY_TREE $bogus_tree >actual &&
  24        test_cmp expect actual
  25'
  26
  27test_expect_success 'raw diff shows null sha1 (removal)' '
  28        echo ":100644 000000 $_z40 $_z40 D      foo" >expect &&
  29        git diff-tree $bogus_tree $EMPTY_TREE >actual &&
  30        test_cmp expect actual
  31'
  32
  33test_expect_success 'raw diff shows null sha1 (modification)' '
  34        echo ":100644 100644 $blob $_z40 M      foo" >expect &&
  35        git diff-tree $good_tree $bogus_tree >actual &&
  36        test_cmp expect actual
  37'
  38
  39test_expect_success 'raw diff shows null sha1 (other direction)' '
  40        echo ":100644 100644 $_z40 $blob M      foo" >expect &&
  41        git diff-tree $bogus_tree $good_tree >actual &&
  42        test_cmp expect actual
  43'
  44
  45test_expect_success 'raw diff shows null sha1 (reverse)' '
  46        echo ":100644 100644 $_z40 $blob M      foo" >expect &&
  47        git diff-tree -R $good_tree $bogus_tree >actual &&
  48        test_cmp expect actual
  49'
  50
  51test_expect_success 'raw diff shows null sha1 (index)' '
  52        echo ":100644 100644 $_z40 $blob M      foo" >expect &&
  53        git diff-index $bogus_tree >actual &&
  54        test_cmp expect actual
  55'
  56
  57test_expect_success 'patch fails due to bogus sha1 (addition)' '
  58        test_must_fail git diff-tree -p $EMPTY_TREE $bogus_tree
  59'
  60
  61test_expect_success 'patch fails due to bogus sha1 (removal)' '
  62        test_must_fail git diff-tree -p $bogus_tree $EMPTY_TREE
  63'
  64
  65test_expect_success 'patch fails due to bogus sha1 (modification)' '
  66        test_must_fail git diff-tree -p $good_tree $bogus_tree
  67'
  68
  69test_expect_success 'patch fails due to bogus sha1 (other direction)' '
  70        test_must_fail git diff-tree -p $bogus_tree $good_tree
  71'
  72
  73test_expect_success 'patch fails due to bogus sha1 (reverse)' '
  74        test_must_fail git diff-tree -R -p $good_tree $bogus_tree
  75'
  76
  77test_expect_success 'patch fails due to bogus sha1 (index)' '
  78        test_must_fail git diff-index -p $bogus_tree
  79'
  80
  81test_done