]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6022-rev-list-missing.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t6022-rev-list-missing.sh
CommitLineData
9830926c
KN
1#!/bin/sh
2
3test_description='handling of missing objects in rev-list'
4
5TEST_PASSES_SANITIZE_LEAK=true
6. ./test-lib.sh
7
8# We setup the repository with two commits, this way HEAD is always
9# available and we can hide commit 1.
10test_expect_success 'create repository and alternate directory' '
11 test_commit 1 &&
12 test_commit 2 &&
a4324bab
CC
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
9830926c
KN
17'
18
b1df3b38
PS
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.
22GIT_COMMIT_GRAPH_PARANOIA=true
23export GIT_COMMIT_GRAPH_PARANOIA
24
9830926c
KN
25for obj in "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
26do
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)" &&
30
31 mv "$path" "$path.hidden" &&
32 test_when_finished "mv $path.hidden $path" &&
33
34 test_must_fail git rev-list --missing=error --objects \
35 --no-object-names HEAD
36 '
37done
38
39for obj in "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
40do
41 for action in "allow-any" "print"
42 do
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)" &&
46
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 &&
51
686101ff 52 # Blobs are shared by all commits, so even though a commit/tree
9830926c 53 # might be skipped, its blob must be accounted for.
686101ff
CC
54 if test $obj != "HEAD:1.t"
55 then
9830926c
KN
56 echo $(git rev-parse HEAD:1.t) >>expect.raw &&
57 echo $(git rev-parse HEAD:2.t) >>expect.raw
58 fi &&
59
60 mv "$path" "$path.hidden" &&
61 test_when_finished "mv $path.hidden $path" &&
62
63 git rev-list --missing=$action --objects --no-object-names \
64 HEAD >actual.raw &&
65
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)
70 ;;
71 print)
72 grep ?$oid actual.raw &&
73 echo ?$oid >>expect.raw
74 ;;
75 esac &&
76
77 sort actual.raw >actual &&
78 sort expect.raw >expect &&
79 test_cmp expect actual
80 '
81 done
82done
83
a4324bab 84for missing_tip in "annot_tag" "regul_tag" "a_branch" "HEAD~1" "HEAD~1^{tree}" "HEAD:1.t"
7b644c8c
CC
85do
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"
90 do
91 for action in "allow-any" "print"
92 do
93 test_expect_success "--missing=$action with tip '$missing_tip' missing and tip '$existing_tip'" '
7b644c8c
CC
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 &&
103
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 &&
111
a4324bab
CC
112 missing_oid="$(git rev-parse $missing_tip)" &&
113
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 &&
121
122 path=".git/objects/$(test_oid_to_path $oid)" &&
123
7b644c8c
CC
124 mv "$path" "$path.hidden" &&
125 test_when_finished "mv $path.hidden $path" &&
126
127 git rev-list --missing=$action --objects --no-object-names \
a4324bab 128 $missing_oid $existing_tip >actual.raw &&
7b644c8c
CC
129
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)
134 ;;
135 print)
136 grep ?$oid actual.raw &&
137 echo ?$oid >>expect.raw
138 ;;
139 esac &&
140
141 sort actual.raw >actual &&
142 sort expect.raw >expect &&
143 test_cmp expect actual
144 '
145 done
146 done
147done
148
9830926c 149test_done