interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t1010-mktree.sh

120 lines · 3460 bytes Raw Blame History
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_expect_success PIPE 'mktree --batch survives a concurrent repack retiring a pack' '
73 test_when_finished "rm -fr race" &&
74 git init race &&
75 (
76 cd race &&
77 test_commit seed &&
78 a=$(echo A | git hash-object -w --stdin) &&
79 b=$(echo B | git hash-object -w --stdin) &&
80 echo "$a" | git pack-objects .git/objects/pack/pack >pack-a &&
81 echo "$b" | git pack-objects .git/objects/pack/pack >pack-b &&
82
83 # Drop the loose copies so the blobs resolve only through the
84 # packs the multi-pack-index names.
85 git prune-packed &&
86 git multi-pack-index write &&
87 printf "100644 blob %s\ta\n" "$a" >tree-a &&
88 printf "100644 blob %s\tb\n" "$b" >tree-b &&
89
90 victim=".git/objects/pack/pack-$(cat pack-b)" &&
91 mkfifo in out &&
92
93 # mktree --batch stays resident, so its pack view predates the
94 # repack below; feed it one tree at a time over a fifo. The
95 # subshell exit closes the fifos, letting mktree see EOF and quit.
96 (git mktree --batch <in >out 2>err &) &&
97 exec 9>in &&
98 exec 8<out &&
99
100 # The first tree makes the reader cache its (soon stale) view.
101 cat tree-a >&9 && echo >&9 && read tree_a <&8 &&
102
103 # Mimic a concurrent repack: a replacement pack holds every
104 # object, and the pack for b loses its .idx (its .pack lingers),
105 # matching the order in which unlink_pack_path() removes files.
106 git cat-file --batch-all-objects --batch-check="%(objectname)" >oids &&
107 git pack-objects .git/objects/pack/pack <oids >/dev/null &&
108 rm -f "$victim.idx" &&
109
110 # Resolving b used to fail, as its QUICK lookup accepted the
111 # miss; without QUICK the reader repreps and finds b in the
112 # replacement pack.
113 cat tree-b >&9 && echo >&9 && read tree_b <&8 &&
114 exec 9>&- &&
115
116 test -n "$tree_b"
117 )
118'
119
120test_done