Add test ensuring one can not create an oid reference which targets at an unknown id
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index 8bdb75e..b1124b3 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -292,6 +292,26 @@ BEGIN_TEST(create2, "create a new OID reference")
git_repository_free(repo);
END_TEST
+BEGIN_TEST(create3, "Can not create a new OID reference which targets at an unknown id")
+ git_reference *new_reference, *looked_up_ref;
+ git_repository *repo;
+ git_oid id;
+
+ const char *new_head = "refs/heads/new-head";
+
+ git_oid_mkstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644");
+
+ must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
+
+ /* Create and write the new object id reference */
+ must_fail(git_reference_create_oid(&new_reference, repo, new_head, &id));
+
+ /* Ensure the reference can't be looked-up... */
+ must_fail(git_reference_lookup(&looked_up_ref, repo, new_head));
+
+ git_repository_free(repo);
+END_TEST
+
static const char *ref_name = "refs/heads/other";
static const char *ref_master_name = "refs/heads/master";
static const char *ref_branch_name = "refs/heads/branch";
@@ -889,6 +909,7 @@ BEGIN_SUITE(refs)
ADD_TEST(create0);
ADD_TEST(create1);
ADD_TEST(create2);
+ ADD_TEST(create3);
ADD_TEST(overwrite0);
ADD_TEST(overwrite1);