3 test_description
='handling of missing objects in rev-list'
5 TEST_PASSES_SANITIZE_LEAK
=true
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' '
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
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"
56 echo $(git rev-parse HEAD:1.t) >>expect.raw &&
57 echo $(git rev-parse HEAD:2.t) >>expect.raw
60 mv "$path" "$path.hidden" &&
61 test_when_finished "mv $path.hidden $path" &&
63 git rev-list --missing=$action --objects --no-object-names \
66 # When the action is to print, we should also add the missing
67 # oid to the expect list.
72 grep ?$oid actual.raw &&
73 echo ?$oid >>expect.raw
77 sort actual.raw >actual &&
78 sort expect.raw >expect &&
79 test_cmp expect actual
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"
98 git rev-list --objects --no-object-names \
99 HEAD ^$missing_tip >expect.raw
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"
108 echo $(git rev-parse HEAD:1.t) >>expect.raw &&
109 echo $(git rev-parse HEAD:2.t) >>expect.raw
112 missing_oid="$(git rev-parse $missing_tip)" &&
114 if test "$missing_tip" = "annot_tag"
116 oid="$(git rev-parse $missing_tip^{commit})" &&
117 echo "$missing_oid" >>expect.raw
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.
136 grep ?$oid actual.raw &&
137 echo ?$oid >>expect.raw
141 sort actual.raw >actual &&
142 sort expect.raw >expect &&
143 test_cmp expect actual