@@ -34,6 +34,110 @@ 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+
122+ test_expect_success ' pack-object <stdin parsing: --stdin-packs handles garbage' '
123+ cat >in <<-EOF &&
124+ $(git -C pack-object-stdin rev-parse one)
125+ $(git -C pack-object-stdin rev-parse two)
126+ EOF
127+
128+ # That we get "two" and not "one" has to do with OID
129+ # ordering. It happens to be the same here under SHA-1 and
130+ # SHA-256. See commentary in pack-objects.c
131+ cat >err.expect <<-EOF &&
132+ fatal: could not find pack ' " '" ' $(git -C pack-object-stdin rev-parse two)' " '" '
133+ EOF
134+ test_must_fail git \
135+ -C pack-object-stdin \
136+ pack-objects stdin-with-stdin-option --stdin-packs \
137+ <in 2>err.actual &&
138+ test_cmp err.expect err.actual
139+ '
140+
37141# usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas>
38142# e.g.: check_deltas stderr -gt 0
39143check_deltas () {
0 commit comments