diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/t04-commit.c | 20 | ||||
-rw-r--r-- | tests/t08-tag.c | 58 | ||||
-rw-r--r-- | tests/t10-refs.c | 40 |
3 files changed, 53 insertions, 65 deletions
diff --git a/tests/t04-commit.c b/tests/t04-commit.c index 0ae0cdfb2..b7e0afe1e 100644 --- a/tests/t04-commit.c +++ b/tests/t04-commit.c @@ -415,19 +415,21 @@ This is a commit created in memory and it will be written back to disk\n" static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; - BEGIN_TEST(write0, "write a new commit object from memory to disk") git_repository *repo; git_commit *commit; git_oid tree_id, parent_id, commit_id; const git_signature *author, *committer; - /* char hex_oid[41]; */ + git_commit *parent; + git_tree *tree; must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - git_oid_fromstr(&tree_id, tree_oid); + must_pass(git_tree_lookup(&tree, repo, &tree_id)); + git_oid_fromstr(&parent_id, commit_ids[4]); + must_pass(git_commit_lookup(&parent, repo, &parent_id)); /* create signatures */ committer = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60); @@ -443,8 +445,11 @@ BEGIN_TEST(write0, "write a new commit object from memory to disk") author, committer, COMMIT_MESSAGE, - &tree_id, - 1, &parent_id)); + tree, + 1, parent)); + + git_object_close((git_object *)parent); + git_object_close((git_object *)tree); git_signature_free((git_signature *)committer); git_signature_free((git_signature *)author); @@ -486,10 +491,12 @@ BEGIN_TEST(root0, "create a root commit") const char *branch_name = "refs/heads/root-commit-branch"; git_reference *head, *branch; char *head_old; + git_tree *tree; must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); git_oid_fromstr(&tree_id, tree_oid); + must_pass(git_tree_lookup(&tree, repo, &tree_id)); /* create signatures */ committer = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60); @@ -513,9 +520,10 @@ BEGIN_TEST(root0, "create a root commit") author, committer, ROOT_COMMIT_MESSAGE, - &tree_id, + tree, 0)); + git_object_close((git_object *)tree); git_signature_free((git_signature *)committer); git_signature_free((git_signature *)author); diff --git a/tests/t08-tag.c b/tests/t08-tag.c index 48d48fe39..64a939f0e 100644 --- a/tests/t08-tag.c +++ b/tests/t08-tag.c @@ -88,10 +88,12 @@ BEGIN_TEST(write0, "write a tag to the repository and read it again") git_oid target_id, tag_id; const git_signature *tagger; git_reference *ref_tag; + git_object *target; must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); git_oid_fromstr(&target_id, tagged_commit); + must_pass(git_object_lookup(&target, repo, &target_id, GIT_OBJ_COMMIT)); /* create signature */ tagger = git_signature_new(TAGGER_NAME, TAGGER_EMAIL, 123456789, 60); @@ -101,11 +103,12 @@ BEGIN_TEST(write0, "write a tag to the repository and read it again") &tag_id, /* out id */ repo, "the-tag", - &target_id, - GIT_OBJ_COMMIT, + target, tagger, - TAGGER_MESSAGE)); + TAGGER_MESSAGE, + 0)); + git_object_close(target); git_signature_free((git_signature *)tagger); must_pass(git_tag_lookup(&tag, repo, &tag_id)); @@ -132,42 +135,16 @@ BEGIN_TEST(write0, "write a tag to the repository and read it again") END_TEST -BEGIN_TEST(write1, "write a tag to the repository which points to an unknown oid should fail") - git_repository *repo; - git_oid target_id, tag_id; - const git_signature *tagger; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&target_id, "deadbeef1b46c854b31185ea97743be6a8774479"); - - /* create signature */ - tagger = git_signature_new(TAGGER_NAME, TAGGER_EMAIL, 123456789, 60); - must_be_true(tagger != NULL); - - must_fail(git_tag_create( - &tag_id, /* out id */ - repo, - "the-zombie-tag", - &target_id, - GIT_OBJ_COMMIT, - tagger, - TAGGER_MESSAGE)); - - git_signature_free((git_signature *)tagger); - - git_repository_free(repo); - -END_TEST - BEGIN_TEST(write2, "Attempt to write a tag bearing the same name than an already existing tag") git_repository *repo; git_oid target_id, tag_id; const git_signature *tagger; + git_object *target; must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); git_oid_fromstr(&target_id, tagged_commit); + must_pass(git_object_lookup(&target, repo, &target_id, GIT_OBJ_COMMIT)); /* create signature */ tagger = git_signature_new(TAGGER_NAME, TAGGER_EMAIL, 123456789, 60); @@ -177,11 +154,12 @@ BEGIN_TEST(write2, "Attempt to write a tag bearing the same name than an already &tag_id, /* out id */ repo, "e90810b", - &target_id, - GIT_OBJ_COMMIT, + target, tagger, - TAGGER_MESSAGE)); + TAGGER_MESSAGE, + 0)); + git_object_close(target); git_signature_free((git_signature *)tagger); git_repository_free(repo); @@ -193,10 +171,12 @@ BEGIN_TEST(write3, "Replace an already existing tag") git_oid target_id, tag_id, old_tag_id; const git_signature *tagger; git_reference *ref_tag; + git_object *target; must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); git_oid_fromstr(&target_id, tagged_commit); + must_pass(git_object_lookup(&target, repo, &target_id, GIT_OBJ_COMMIT)); must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/e90810b")); git_oid_cpy(&old_tag_id, git_reference_oid(ref_tag)); @@ -205,15 +185,16 @@ BEGIN_TEST(write3, "Replace an already existing tag") tagger = git_signature_new(TAGGER_NAME, TAGGER_EMAIL, 123456789, 60); must_be_true(tagger != NULL); - must_pass(git_tag_create_f( + must_pass(git_tag_create( &tag_id, /* out id */ repo, "e90810b", - &target_id, - GIT_OBJ_COMMIT, + target, tagger, - TAGGER_MESSAGE)); + TAGGER_MESSAGE, + 1)); + git_object_close(target); git_signature_free((git_signature *)tagger); must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/e90810b")); @@ -242,7 +223,6 @@ BEGIN_SUITE(tag) ADD_TEST(read0); ADD_TEST(read1); ADD_TEST(write0); - ADD_TEST(write1); ADD_TEST(write2); ADD_TEST(write3); ADD_TEST(write4); diff --git a/tests/t10-refs.c b/tests/t10-refs.c index 5efe80447..0ca30d058 100644 --- a/tests/t10-refs.c +++ b/tests/t10-refs.c @@ -212,7 +212,7 @@ BEGIN_TEST(create0, "create a new symbolic reference") git__joinpath(ref_path, repo->path_repository, new_head_tracker); /* Create and write the new symbolic reference */ - must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target)); + must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); /* Ensure the reference can be looked-up... */ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); @@ -252,7 +252,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); git__joinpath(ref_path, repo->path_repository, new_head_tracker); - must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target)); + must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); @@ -276,7 +276,7 @@ BEGIN_TEST(create2, "create a new OID reference") git__joinpath(ref_path, repo->path_repository, new_head); /* Create and write the new object id reference */ - must_pass(git_reference_create_oid(&new_reference, repo, new_head, &id)); + must_pass(git_reference_create_oid(&new_reference, repo, new_head, &id, 0)); /* Ensure the reference can be looked-up... */ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head)); @@ -310,7 +310,7 @@ BEGIN_TEST(create3, "Can not create a new OID reference which targets at an unkn 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)); + must_fail(git_reference_create_oid(&new_reference, repo, new_head, &id, 0)); /* Ensure the reference can't be looked-up... */ must_fail(git_reference_lookup(&looked_up_ref, repo, new_head)); @@ -329,16 +329,16 @@ BEGIN_TEST(overwrite0, "Overwrite an existing symbolic reference") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* The target needds to exist and we need to check the name has changed */ - must_pass(git_reference_create_symbolic(&branch_ref, repo, ref_branch_name, ref_master_name)); - must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_branch_name)); + must_pass(git_reference_create_symbolic(&branch_ref, repo, ref_branch_name, ref_master_name, 0)); + must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_branch_name, 0)); /* Ensure it points to the right place*/ must_pass(git_reference_lookup(&ref, repo, ref_name)); must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC); must_be_true(!strcmp(git_reference_target(ref), ref_branch_name)); /* Ensure we can't create it unless we force it to */ - must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name)); - must_pass(git_reference_create_symbolic_f(&ref, repo, ref_name, ref_master_name)); + must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0)); + must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 1)); /* Ensure it points to the right place */ must_pass(git_reference_lookup(&ref, repo, ref_name)); @@ -360,15 +360,15 @@ BEGIN_TEST(overwrite1, "Overwrite an existing object id reference") git_oid_cpy(&id, git_reference_oid(ref)); /* Create it */ - must_pass(git_reference_create_oid(&ref, repo, ref_name, &id)); + must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); must_pass(git_reference_lookup(&ref, repo, ref_test_name)); must_be_true(ref->type & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); /* Ensure we can't overwrite unless we force it */ - must_fail(git_reference_create_oid(&ref, repo, ref_name, &id)); - must_pass(git_reference_create_oid_f(&ref, repo, ref_name, &id)); + must_fail(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); + must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 1)); /* Ensure it has been overwritten */ must_pass(git_reference_lookup(&ref, repo, ref_name)); @@ -388,9 +388,9 @@ BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symboli must_be_true(ref->type & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); - must_pass(git_reference_create_oid(&ref, repo, ref_name, &id)); - must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name)); - must_pass(git_reference_create_symbolic_f(&ref, repo, ref_name, ref_master_name)); + must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); + must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0)); + must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 1)); /* Ensure it points to the right place */ must_pass(git_reference_lookup(&ref, repo, ref_name)); @@ -412,10 +412,10 @@ BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object git_oid_cpy(&id, git_reference_oid(ref)); /* Create the symbolic ref */ - must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name)); + must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0)); /* It shouldn't overwrite unless we tell it to */ - must_fail(git_reference_create_oid(&ref, repo, ref_name, &id)); - must_pass(git_reference_create_oid_f(&ref, repo, ref_name, &id)); + must_fail(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); + must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 1)); /* Ensure it points to the right place */ must_pass(git_reference_lookup(&ref, repo, ref_name)); @@ -671,14 +671,14 @@ BEGIN_TEST(rename6, "can not overwrite name of existing reference") git_oid_cpy(&id, git_reference_oid(ref)); /* Create loose references */ - must_pass(git_reference_create_oid(&ref_one, repo, ref_one_name, &id)); - must_pass(git_reference_create_oid(&ref_two, repo, ref_two_name, &id)); + must_pass(git_reference_create_oid(&ref_one, repo, ref_one_name, &id, 0)); + must_pass(git_reference_create_oid(&ref_two, repo, ref_two_name, &id, 0)); /* Pack everything */ must_pass(git_reference_packall(repo)); /* Attempt to create illegal reference */ - must_fail(git_reference_create_oid(&ref_one_new, repo, ref_one_name_new, &id)); + must_fail(git_reference_create_oid(&ref_one_new, repo, ref_one_name_new, &id, 0)); /* Illegal reference couldn't be created so this is supposed to fail */ must_fail(git_reference_lookup(&ref_one_new, repo, ref_one_name_new)); |