summaryrefslogtreecommitdiff
path: root/tests/refs
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-03-01 17:16:27 +0000
committerEdward Thomson <ethomson@github.com>2016-03-01 17:16:27 +0000
commitedaffe22a205c57022cc365ab20dcbf7e22f68c4 (patch)
treedebce9f07cfd07e0cd7ebada95be7cd0dca08a51 /tests/refs
parentdbee683553ef4c43273b24ebc503d424c46c01f1 (diff)
parentf2dddf52c041ff2f9185bdb320ddccad1523a2bf (diff)
downloadlibgit2-edaffe22a205c57022cc365ab20dcbf7e22f68c4.tar.gz
Merge pull request #3633 from ethomson/safe_creation
Stricter object dependency checking during creation
Diffstat (limited to 'tests/refs')
-rw-r--r--tests/refs/create.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/refs/create.c b/tests/refs/create.c
index 48194ae3b..a0bc78014 100644
--- a/tests/refs/create.c
+++ b/tests/refs/create.c
@@ -18,6 +18,8 @@ void test_refs_create__initialize(void)
void test_refs_create__cleanup(void)
{
cl_git_sandbox_cleanup();
+
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 0));
}
void test_refs_create__symbolic(void)
@@ -119,9 +121,27 @@ void test_refs_create__oid(void)
git_reference_free(looked_up_ref);
}
-void test_refs_create__oid_unknown(void)
+/* Can by default create a reference that targets at an unknown id */
+void test_refs_create__oid_unknown_succeeds_by_default(void)
+{
+ git_reference *new_reference, *looked_up_ref;
+ git_oid id;
+
+ const char *new_head = "refs/heads/new-head";
+
+ git_oid_fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644");
+
+ /* Create and write the new object id reference */
+ cl_git_pass(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL));
+
+ /* Ensure the reference can't be looked-up... */
+ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head));
+ git_reference_free(looked_up_ref);
+}
+
+/* Strict object enforcement enforces valid object id */
+void test_refs_create__oid_unknown_fails_strict_mode(void)
{
- // Can not create a new OID reference which targets at an unknown id
git_reference *new_reference, *looked_up_ref;
git_oid id;
@@ -129,6 +149,8 @@ void test_refs_create__oid_unknown(void)
git_oid_fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644");
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 1));
+
/* Create and write the new object id reference */
cl_git_fail(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL));