Skip to content

Commit fb20d4b

Browse files
avargitster
authored andcommitted
pack-objects tests: cover blindspots in stdin handling
Cover blindspots in the testing of stdin handling, including the "!len" condition added in b5d97e6 (pack-objects: run rev-list equivalent internally., 2006-09-04). The codepath taken with --revs and read_object_list_from_stdin() acts differently in some of these common cases, let's test for those. The "--stdin --revs" test being added here stresses the combination of --stdin-packs and the revision.c --stdin argument, some of this was covered in a test added in 339bce2 (builtin/pack-objects.c: add '--stdin-packs' option, 2021-02-22), but let's make sure that GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true keeps erroring out about --stdin, and it isn't picked up by the revision.c API's handling of that option. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebf3c04 commit fb20d4b

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

t/t5300-pack-object.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,91 @@ test_expect_success 'setup' '
3434
} >expect
3535
'
3636

37+
test_expect_success 'setup pack-object <stdin' '
38+
git init pack-object-stdin &&
39+
test_commit -C pack-object-stdin one &&
40+
test_commit -C pack-object-stdin two
41+
42+
'
43+
44+
test_expect_success 'pack-object <stdin parsing: basic [|--revs]' '
45+
cat >in <<-EOF &&
46+
$(git -C pack-object-stdin rev-parse one)
47+
EOF
48+
49+
git -C pack-object-stdin pack-objects basic-stdin <in &&
50+
idx=$(echo pack-object-stdin/basic-stdin-*.idx) &&
51+
git show-index <"$idx" >actual &&
52+
test_line_count = 1 actual &&
53+
54+
git -C pack-object-stdin pack-objects --revs basic-stdin-revs <in &&
55+
idx=$(echo pack-object-stdin/basic-stdin-revs-*.idx) &&
56+
git show-index <"$idx" >actual &&
57+
test_line_count = 3 actual
58+
'
59+
60+
test_expect_success 'pack-object <stdin parsing: [|--revs] bad line' '
61+
cat >in <<-EOF &&
62+
$(git -C pack-object-stdin rev-parse one)
63+
garbage
64+
$(git -C pack-object-stdin rev-parse two)
65+
EOF
66+
67+
sed "s/^> //g" >err.expect <<-EOF &&
68+
fatal: expected object ID, got garbage:
69+
> garbage
70+
71+
EOF
72+
test_must_fail git -C pack-object-stdin pack-objects bad-line-stdin <in 2>err.actual &&
73+
test_cmp err.expect err.actual &&
74+
75+
cat >err.expect <<-EOF &&
76+
fatal: bad revision '"'"'garbage'"'"'
77+
EOF
78+
test_must_fail git -C pack-object-stdin pack-objects --revs bad-line-stdin-revs <in 2>err.actual &&
79+
test_cmp err.expect err.actual
80+
'
81+
82+
test_expect_success 'pack-object <stdin parsing: [|--revs] empty line' '
83+
cat >in <<-EOF &&
84+
$(git -C pack-object-stdin rev-parse one)
85+
86+
$(git -C pack-object-stdin rev-parse two)
87+
EOF
88+
89+
sed -e "s/^> //g" -e "s/Z$//g" >err.expect <<-EOF &&
90+
fatal: expected object ID, got garbage:
91+
> Z
92+
93+
EOF
94+
test_must_fail git -C pack-object-stdin pack-objects empty-line-stdin <in 2>err.actual &&
95+
test_cmp err.expect err.actual &&
96+
97+
git -C pack-object-stdin pack-objects --revs empty-line-stdin-revs <in &&
98+
idx=$(echo pack-object-stdin/empty-line-stdin-revs-*.idx) &&
99+
git show-index <"$idx" >actual &&
100+
test_line_count = 3 actual
101+
'
102+
103+
test_expect_success 'pack-object <stdin parsing: [|--revs] with --stdin' '
104+
cat >in <<-EOF &&
105+
$(git -C pack-object-stdin rev-parse one)
106+
$(git -C pack-object-stdin rev-parse two)
107+
EOF
108+
109+
# There is the "--stdin-packs is incompatible with --revs"
110+
# test below, but we should make sure that the revision.c
111+
# --stdin is not picked up
112+
cat >err.expect <<-EOF &&
113+
fatal: disallowed abbreviated or ambiguous option '"'"'stdin'"'"'
114+
EOF
115+
test_must_fail git -C pack-object-stdin pack-objects stdin-with-stdin-option --stdin <in 2>err.actual &&
116+
test_cmp err.expect err.actual &&
117+
118+
test_must_fail git -C pack-object-stdin pack-objects --stdin --revs stdin-with-stdin-option-revs 2>err.actual <in &&
119+
test_cmp err.expect err.actual
120+
'
121+
37122
# usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas>
38123
# e.g.: check_deltas stderr -gt 0
39124
check_deltas() {

0 commit comments

Comments
 (0)