fast-import: add tests for tagging blobs

fast-import allows to create an annotated tag that annotates a blob, via mark or direct sha1 specification. For mark it works, for sha1 it tries to read the object. It tries to do so via read_sha1_file, and then checks the size to be at least 46. That's weird, let's just allow to (annotated) tag any object referenced by sha1. If the object originates from our packfile, we still fail though. Signed-off-by: Dmitry Ivankov <divanorama@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dmitry Ivankov committed Aug 22, 2011 at 18:10 UTC 2efe38e7da40fdf2b6e0261984d7adaab16ad930
2 files changed +44 -7
fast-import.c
+3 -7
@@ -2688,13 +2688,9 @@ static void parse_new_tag(void)
2688 type = oe->type;
2689 hashcpy(sha1, oe->idx.sha1);
2690 } else if (!get_sha1(from, sha1)) {
2691 - unsigned long size;
2692 - char *buf;
2693 -
2694 - buf = read_sha1_file(sha1, &type, &size);
2695 - if (!buf || size < 46)
2696 - die("Not a valid commit: %s", from);
2697 - free(buf);
2691 + type = sha1_object_info(sha1, NULL);
2692 + if (type < 0)
2693 + die("Not a valid object: %s", from);
2694 } else
2695 die("Invalid ref name or SHA1 expression: %s", from);
2696 read_next_command();
t/t9300-fast-import.sh
+41
@@ -94,6 +94,12 @@ data <<EOF
94 An annotated tag without a tagger
95 EOF
96
97 +tag series-A-blob
98 +from :3
99 +data <<EOF
100 +An annotated tag that annotates a blob.
101 +EOF
102 +
103 INPUT_END
104 test_expect_success \
105 'A: create pack from stdin' \
@@ -151,6 +157,18 @@ test_expect_success 'A: verify tag/series-A' '
157 test_cmp expect actual
158 '
159
160 +cat >expect <<EOF
161 +object $(git rev-parse refs/heads/master:file3)
162 +type blob
163 +tag series-A-blob
164 +
165 +An annotated tag that annotates a blob.
166 +EOF
167 +test_expect_success 'A: verify tag/series-A-blob' '
168 + git cat-file tag tags/series-A-blob >actual &&
169 + test_cmp expect actual
170 +'
171 +
172 cat >expect <<EOF
173 :2 `git rev-parse --verify master:file2`
174 :3 `git rev-parse --verify master:file3`
@@ -169,6 +187,29 @@ test_expect_success \
187 </dev/null &&
188 test_cmp expect marks.new'
189
190 +test_tick
191 +cat >input <<INPUT_END
192 +tag series-A-blob-2
193 +from $(git rev-parse refs/heads/master:file3)
194 +data <<EOF
195 +Tag blob by sha1.
196 +EOF
197 +INPUT_END
198 +
199 +cat >expect <<EOF
200 +object $(git rev-parse refs/heads/master:file3)
201 +type blob
202 +tag series-A-blob-2
203 +
204 +Tag blob by sha1.
205 +EOF
206 +
207 +test_expect_success \
208 + 'A: tag blob by sha1' \
209 + 'git fast-import <input &&
210 + git cat-file tag tags/series-A-blob-2 >actual &&
211 + test_cmp expect actual'
212 +
213 test_tick
214 cat >input <<INPUT_END
215 commit refs/heads/verify--import-marks