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