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