Git 2.45
[git/gitster.git] / t / t6022-rev-list-missing.sh
blob127180e1c9a246769fb5bb7ede57f814abb4fc79
1 #!/bin/sh
3 test_description='handling of missing objects in rev-list'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 # We setup the repository with two commits, this way HEAD is always
9 # available and we can hide commit 1.
10 test_expect_success 'create repository and alternate directory' '
11 test_commit 1 &&
12 test_commit 2 &&
13 test_commit 3 &&
14 git tag -m "tag message" annot_tag HEAD~1 &&
15 git tag regul_tag HEAD~1 &&
16 git branch a_branch HEAD~1
19 # We manually corrupt the repository, which means that the commit-graph may
20 # contain references to already-deleted objects. We thus need to enable
21 # commit-graph paranoia to not returned these deleted commits from the graph.
22 GIT_COMMIT_GRAPH_PARANOIA=true
23 export GIT_COMMIT_GRAPH_PARANOIA
25 for obj in "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
27 test_expect_success "rev-list --missing=error fails with missing object $obj" '
28 oid="$(git rev-parse $obj)" &&
29 path=".git/objects/$(test_oid_to_path $oid)" &&
31 mv "$path" "$path.hidden" &&
32 test_when_finished "mv $path.hidden $path" &&
34 test_must_fail git rev-list --missing=error --objects \
35 --no-object-names HEAD
37 done
39 for obj in "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
41 for action in "allow-any" "print"
43 test_expect_success "rev-list --missing=$action with missing $obj" '
44 oid="$(git rev-parse $obj)" &&
45 path=".git/objects/$(test_oid_to_path $oid)" &&
47 # Before the object is made missing, we use rev-list to
48 # get the expected oids.
49 git rev-list --objects --no-object-names \
50 HEAD ^$obj >expect.raw &&
52 # Blobs are shared by all commits, so even though a commit/tree
53 # might be skipped, its blob must be accounted for.
54 if test $obj != "HEAD:1.t"
55 then
56 echo $(git rev-parse HEAD:1.t) >>expect.raw &&
57 echo $(git rev-parse HEAD:2.t) >>expect.raw
58 fi &&
60 mv "$path" "$path.hidden" &&
61 test_when_finished "mv $path.hidden $path" &&
63 git rev-list --missing=$action --objects --no-object-names \
64 HEAD >actual.raw &&
66 # When the action is to print, we should also add the missing
67 # oid to the expect list.
68 case $action in
69 allow-any)
71 print)
72 grep ?$oid actual.raw &&
73 echo ?$oid >>expect.raw
75 esac &&
77 sort actual.raw >actual &&
78 sort expect.raw >expect &&
79 test_cmp expect actual
81 done
82 done
84 for missing_tip in "annot_tag" "regul_tag" "a_branch" "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
86 # We want to check that things work when both
87 # - all the tips passed are missing (case existing_tip = ""), and
88 # - there is one missing tip and one existing tip (case existing_tip = "HEAD")
89 for existing_tip in "" "HEAD"
91 for action in "allow-any" "print"
93 test_expect_success "--missing=$action with tip '$missing_tip' missing and tip '$existing_tip'" '
94 # Before the object is made missing, we use rev-list to
95 # get the expected oids.
96 if test "$existing_tip" = "HEAD"
97 then
98 git rev-list --objects --no-object-names \
99 HEAD ^$missing_tip >expect.raw
100 else
101 >expect.raw
102 fi &&
104 # Blobs are shared by all commits, so even though a commit/tree
105 # might be skipped, its blob must be accounted for.
106 if test "$existing_tip" = "HEAD" && test $missing_tip != "HEAD:1.t"
107 then
108 echo $(git rev-parse HEAD:1.t) >>expect.raw &&
109 echo $(git rev-parse HEAD:2.t) >>expect.raw
110 fi &&
112 missing_oid="$(git rev-parse $missing_tip)" &&
114 if test "$missing_tip" = "annot_tag"
115 then
116 oid="$(git rev-parse $missing_tip^{commit})" &&
117 echo "$missing_oid" >>expect.raw
118 else
119 oid="$missing_oid"
120 fi &&
122 path=".git/objects/$(test_oid_to_path $oid)" &&
124 mv "$path" "$path.hidden" &&
125 test_when_finished "mv $path.hidden $path" &&
127 git rev-list --missing=$action --objects --no-object-names \
128 $missing_oid $existing_tip >actual.raw &&
130 # When the action is to print, we should also add the missing
131 # oid to the expect list.
132 case $action in
133 allow-any)
135 print)
136 grep ?$oid actual.raw &&
137 echo ?$oid >>expect.raw
139 esac &&
141 sort actual.raw >actual &&
142 sort expect.raw >expect &&
143 test_cmp expect actual
145 done
146 done
147 done
149 test_done