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>
This commit is contained in:
Dmitry Ivankov 2011-08-22 18:10:18 +06:00 committed by Junio C Hamano
parent 0906f6e14e
commit 2efe38e7da
2 changed files with 44 additions and 7 deletions

View File

@ -2688,13 +2688,9 @@ static void parse_new_tag(void)
type = oe->type; type = oe->type;
hashcpy(sha1, oe->idx.sha1); hashcpy(sha1, oe->idx.sha1);
} else if (!get_sha1(from, sha1)) { } else if (!get_sha1(from, sha1)) {
unsigned long size; type = sha1_object_info(sha1, NULL);
char *buf; if (type < 0)
die("Not a valid object: %s", from);
buf = read_sha1_file(sha1, &type, &size);
if (!buf || size < 46)
die("Not a valid commit: %s", from);
free(buf);
} else } else
die("Invalid ref name or SHA1 expression: %s", from); die("Invalid ref name or SHA1 expression: %s", from);
read_next_command(); read_next_command();

View File

@ -94,6 +94,12 @@ data <<EOF
An annotated tag without a tagger An annotated tag without a tagger
EOF EOF
tag series-A-blob
from :3
data <<EOF
An annotated tag that annotates a blob.
EOF
INPUT_END INPUT_END
test_expect_success \ test_expect_success \
'A: create pack from stdin' \ 'A: create pack from stdin' \
@ -151,6 +157,18 @@ test_expect_success 'A: verify tag/series-A' '
test_cmp expect actual test_cmp expect actual
' '
cat >expect <<EOF
object $(git rev-parse refs/heads/master:file3)
type blob
tag series-A-blob
An annotated tag that annotates a blob.
EOF
test_expect_success 'A: verify tag/series-A-blob' '
git cat-file tag tags/series-A-blob >actual &&
test_cmp expect actual
'
cat >expect <<EOF cat >expect <<EOF
:2 `git rev-parse --verify master:file2` :2 `git rev-parse --verify master:file2`
:3 `git rev-parse --verify master:file3` :3 `git rev-parse --verify master:file3`
@ -169,6 +187,29 @@ test_expect_success \
</dev/null && </dev/null &&
test_cmp expect marks.new' test_cmp expect marks.new'
test_tick
cat >input <<INPUT_END
tag series-A-blob-2
from $(git rev-parse refs/heads/master:file3)
data <<EOF
Tag blob by sha1.
EOF
INPUT_END
cat >expect <<EOF
object $(git rev-parse refs/heads/master:file3)
type blob
tag series-A-blob-2
Tag blob by sha1.
EOF
test_expect_success \
'A: tag blob by sha1' \
'git fast-import <input &&
git cat-file tag tags/series-A-blob-2 >actual &&
test_cmp expect actual'
test_tick test_tick
cat >input <<INPUT_END cat >input <<INPUT_END
commit refs/heads/verify--import-marks commit refs/heads/verify--import-marks