t / t7009-filter-branch-null-sha1.shon commit Merge branch 'as/safecrlf-quiet-fix' (8063ff9)
   1#!/bin/sh
   2
   3test_description='filter-branch removal of trees with null sha1'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup: base commits' '
   7        test_commit one &&
   8        test_commit two &&
   9        test_commit three
  10'
  11
  12test_expect_success 'setup: a commit with a bogus null sha1 in the tree' '
  13        {
  14                git ls-tree HEAD &&
  15                printf "160000 commit $ZERO_OID\\tbroken\\n"
  16        } >broken-tree &&
  17        echo "add broken entry" >msg &&
  18
  19        tree=$(git mktree <broken-tree) &&
  20        test_tick &&
  21        commit=$(git commit-tree $tree -p HEAD <msg) &&
  22        git update-ref HEAD "$commit"
  23'
  24
  25# we have to make one more commit on top removing the broken
  26# entry, since otherwise our index does not match HEAD (and filter-branch will
  27# complain). We could make the index match HEAD, but doing so would involve
  28# writing a null sha1 into the index.
  29test_expect_success 'setup: bring HEAD and index in sync' '
  30        test_tick &&
  31        git commit -a -m "back to normal"
  32'
  33
  34test_expect_success 'noop filter-branch complains' '
  35        test_must_fail git filter-branch \
  36                --force --prune-empty \
  37                --index-filter "true"
  38'
  39
  40test_expect_success 'filter commands are still checked' '
  41        test_must_fail git filter-branch \
  42                --force --prune-empty \
  43                --index-filter "git rm --cached --ignore-unmatch three.t"
  44'
  45
  46test_expect_success 'removing the broken entry works' '
  47        echo three >expect &&
  48        git filter-branch \
  49                --force --prune-empty \
  50                --index-filter "git rm --cached --ignore-unmatch broken" &&
  51        git log -1 --format=%s >actual &&
  52        test_cmp expect actual
  53'
  54
  55test_done