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