Commit 7bc66a79 by Carlos Martín Nieto Committed by Vicent Marti

tag: don't allow tags to non-existent objects

These indicate an inconsistency in the repository which we've created,
so don't allow them.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
parent 81234673
...@@ -209,6 +209,9 @@ static int tag_create( ...@@ -209,6 +209,9 @@ static int tag_create(
return error; return error;
} }
if (!git_odb_exists(repo->db, target))
return GIT_ENOTFOUND;
/* Try to find out what the type is */ /* Try to find out what the type is */
if (target_type == GIT_OBJ_ANY) { if (target_type == GIT_OBJ_ANY) {
size_t _unused; size_t _unused;
......
...@@ -119,7 +119,7 @@ BEGIN_TEST(write0, "write a tag to the repository and read it again") ...@@ -119,7 +119,7 @@ BEGIN_TEST(write0, "write a tag to the repository and read it again")
END_TEST END_TEST
BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid and read it again") BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid should fail")
git_repository *repo; git_repository *repo;
git_tag *tag; git_tag *tag;
git_oid target_id, tag_id; git_oid target_id, tag_id;
...@@ -135,7 +135,7 @@ BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid ...@@ -135,7 +135,7 @@ BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid
tagger = git_signature_new(TAGGER_NAME, TAGGER_EMAIL, 123456789, 60); tagger = git_signature_new(TAGGER_NAME, TAGGER_EMAIL, 123456789, 60);
must_be_true(tagger != NULL); must_be_true(tagger != NULL);
must_pass(git_tag_create( must_fail(git_tag_create(
&tag_id, /* out id */ &tag_id, /* out id */
repo, repo,
"the-zombie-tag", "the-zombie-tag",
...@@ -146,17 +146,6 @@ BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid ...@@ -146,17 +146,6 @@ BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid
git_signature_free((git_signature *)tagger); git_signature_free((git_signature *)tagger);
must_pass(git_tag_lookup(&tag, repo, &tag_id));
/* The non existent target can not be looked up */
must_fail(git_tag_target(&zombie, tag));
must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/the-zombie-tag"));
must_pass(git_reference_delete(ref_tag));
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag));
git_tag_close(tag);
git_repository_free(repo); git_repository_free(repo);
END_TEST END_TEST
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment