Commit 2b9b99b6ed45d42627916f0d9e2105d61fd23b11

nulltoken 2011-03-29T21:29:30

Add test ensuring one can not create an oid reference which targets at an unknown id

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);