Git fork
1#!/bin/sh
2
3test_description='git mktree'
4
5. ./test-lib.sh
6
7test_expect_success setup '
8 for d in a a- a0
9 do
10 mkdir "$d" && echo "$d/one" >"$d/one" &&
11 git add "$d" || return 1
12 done &&
13 echo zero >one &&
14 if test_have_prereq BROKEN_OBJECTS
15 then
16 git update-index --add --info-only one &&
17 git write-tree --missing-ok >tree.missing &&
18 git ls-tree $(cat tree.missing) >top.missing &&
19 git ls-tree -r $(cat tree.missing) >all.missing
20 fi &&
21 echo one >one &&
22 git add one &&
23 git write-tree >tree &&
24 git ls-tree $(cat tree) >top &&
25 git ls-tree -r $(cat tree) >all &&
26 test_tick &&
27 git commit -q -m one &&
28 H=$(git rev-parse HEAD) &&
29 git update-index --add --cacheinfo 160000 $H sub &&
30 test_tick &&
31 git commit -q -m two &&
32 git rev-parse HEAD^{tree} >tree.withsub &&
33 git ls-tree HEAD >top.withsub &&
34 git ls-tree -r HEAD >all.withsub
35'
36
37test_expect_success 'ls-tree piped to mktree (1)' '
38 git mktree <top >actual &&
39 test_cmp tree actual
40'
41
42test_expect_success 'ls-tree piped to mktree (2)' '
43 git mktree <top.withsub >actual &&
44 test_cmp tree.withsub actual
45'
46
47test_expect_success 'ls-tree output in wrong order given to mktree (1)' '
48 sort -r <top |
49 git mktree >actual &&
50 test_cmp tree actual
51'
52
53test_expect_success 'ls-tree output in wrong order given to mktree (2)' '
54 sort -r <top.withsub |
55 git mktree >actual &&
56 test_cmp tree.withsub actual
57'
58
59test_expect_success BROKEN_OBJECTS 'allow missing object with --missing' '
60 git mktree --missing <top.missing >actual &&
61 test_cmp tree.missing actual
62'
63
64test_expect_success 'mktree refuses to read ls-tree -r output (1)' '
65 test_must_fail git mktree <all
66'
67
68test_expect_success 'mktree refuses to read ls-tree -r output (2)' '
69 test_must_fail git mktree <all.withsub
70'
71
72test_done