summaryrefslogtreecommitdiff
path: root/tests/t10-refs.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/t10-refs.c')
-rw-r--r--tests/t10-refs.c80
1 files changed, 45 insertions, 35 deletions
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index 3cfba582d..e8c7b7e00 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -37,7 +37,7 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference")
git_repository *repo;
git_reference *reference;
git_object *object;
- char ref_name_from_tag_name[GIT_REFNAME_MAX];
+ git_buf ref_name_from_tag_name = GIT_BUF_INIT;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
@@ -51,8 +51,9 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference")
must_be_true(git_object_type(object) == GIT_OBJ_TAG);
/* Ensure the name of the tag matches the name of the reference */
- git_path_join(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object));
- must_be_true(strcmp(ref_name_from_tag_name, loose_tag_ref_name) == 0);
+ must_pass(git_buf_joinpath(&ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)));
+ must_be_true(strcmp(ref_name_from_tag_name.ptr, loose_tag_ref_name) == 0);
+ git_buf_free(&ref_name_from_tag_name);
git_object_free(object);
git_repository_free(repo);
@@ -227,7 +228,7 @@ BEGIN_TEST(create0, "create a new symbolic reference")
git_reference *new_reference, *looked_up_ref, *resolved_ref;
git_repository *repo, *repo2;
git_oid id;
- char ref_path[GIT_PATH_MAX];
+ git_buf ref_path = GIT_BUF_INIT;
const char *new_head_tracker = "another-head-tracker";
@@ -236,7 +237,8 @@ BEGIN_TEST(create0, "create a new symbolic reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Retrieve the physical path to the symbolic ref for further cleaning */
- git_path_join(ref_path, repo->path_repository, new_head_tracker);
+ must_pass(git_buf_joinpath(&ref_path, repo->path_repository, new_head_tracker));
+ git_buf_free(&ref_path);
/* Create and write the new symbolic reference */
must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0));
@@ -276,7 +278,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference")
git_reference *new_reference, *looked_up_ref, *resolved_ref;
git_repository *repo;
git_oid id;
- char ref_path[GIT_PATH_MAX];
+ git_buf ref_path = GIT_BUF_INIT;
const char *new_head_tracker = "deep/rooted/tracker";
@@ -284,7 +286,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
- git_path_join(ref_path, repo->path_repository, new_head_tracker);
+ must_pass(git_buf_joinpath(&ref_path, repo->path_repository, new_head_tracker));
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));
@@ -295,13 +297,14 @@ BEGIN_TEST(create1, "create a deep symbolic reference")
git_reference_free(new_reference);
git_reference_free(looked_up_ref);
git_reference_free(resolved_ref);
+ git_buf_free(&ref_path);
END_TEST
BEGIN_TEST(create2, "create a new OID reference")
git_reference *new_reference, *looked_up_ref;
git_repository *repo, *repo2;
git_oid id;
- char ref_path[GIT_PATH_MAX];
+ git_buf ref_path = GIT_BUF_INIT;
const char *new_head = "refs/heads/new-head";
@@ -310,7 +313,7 @@ BEGIN_TEST(create2, "create a new OID reference")
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Retrieve the physical path to the symbolic ref for further cleaning */
- git_path_join(ref_path, repo->path_repository, new_head);
+ must_pass(git_buf_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, 0));
@@ -337,6 +340,7 @@ BEGIN_TEST(create2, "create a new OID reference")
git_reference_free(new_reference);
git_reference_free(looked_up_ref);
+ git_buf_free(&ref_path);
END_TEST
BEGIN_TEST(create3, "Can not create a new OID reference which targets at an unknown id")
@@ -491,12 +495,13 @@ END_TEST
BEGIN_TEST(pack0, "create a packfile for an empty folder")
git_repository *repo;
- char temp_path[GIT_PATH_MAX];
+ git_buf temp_path = GIT_BUF_INIT;
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
- git_path_join_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir");
- must_pass(git_futils_mkdir_r(temp_path, GIT_REFS_DIR_MODE));
+ must_pass(git_buf_join_n(&temp_path, '/', 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir"));
+ must_pass(git_futils_mkdir_r(temp_path.ptr, NULL, GIT_REFS_DIR_MODE));
+ git_buf_free(&temp_path);
must_pass(git_reference_packall(repo));
@@ -506,7 +511,7 @@ END_TEST
BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
git_repository *repo;
git_reference *reference;
- char temp_path[GIT_PATH_MAX];
+ git_buf temp_path = GIT_BUF_INIT;
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
@@ -524,8 +529,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_pass(git_reference_packall(repo));
/* Ensure the packed-refs file exists */
- git_path_join(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE);
- must_pass(git_futils_exists(temp_path));
+ must_pass(git_buf_joinpath(&temp_path, repo->path_repository, GIT_PACKEDREFS_FILE));
+ must_pass(git_futils_exists(temp_path.ptr));
/* Ensure the known ref can still be looked up but is now packed */
must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name));
@@ -533,25 +538,26 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
/* Ensure the known ref has been removed from the loose folder structure */
- git_path_join(temp_path, repo->path_repository, loose_tag_ref_name);
- must_pass(!git_futils_exists(temp_path));
+ must_pass(git_buf_joinpath(&temp_path, repo->path_repository, loose_tag_ref_name));
+ must_pass(!git_futils_exists(temp_path.ptr));
close_temp_repo(repo);
git_reference_free(reference);
+ git_buf_free(&temp_path);
END_TEST
BEGIN_TEST(rename0, "rename a loose reference")
git_reference *looked_up_ref, *another_looked_up_ref;
git_repository *repo;
- char temp_path[GIT_PATH_MAX];
+ git_buf temp_path = GIT_BUF_INIT;
const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu";
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the ref doesn't exist on the file system */
- git_path_join(temp_path, repo->path_repository, new_name);
- must_pass(!git_futils_exists(temp_path));
+ must_pass(git_buf_joinpath(&temp_path, repo->path_repository, new_name));
+ must_pass(!git_futils_exists(temp_path.ptr));
/* Retrieval of the reference to rename */
must_pass(git_reference_lookup(&looked_up_ref, repo, loose_tag_ref_name));
@@ -575,26 +581,27 @@ BEGIN_TEST(rename0, "rename a loose reference")
must_be_true(git_reference_is_packed(looked_up_ref) == 0);
/* ...and the ref can be found in the file system */
- git_path_join(temp_path, repo->path_repository, new_name);
- must_pass(git_futils_exists(temp_path));
+ must_pass(git_buf_joinpath(&temp_path, repo->path_repository, new_name));
+ must_pass(git_futils_exists(temp_path.ptr));
close_temp_repo(repo);
git_reference_free(looked_up_ref);
git_reference_free(another_looked_up_ref);
+ git_buf_free(&temp_path);
END_TEST
BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
git_reference *looked_up_ref, *another_looked_up_ref;
git_repository *repo;
- char temp_path[GIT_PATH_MAX];
+ git_buf temp_path = GIT_BUF_INIT;
const char *brand_new_name = "refs/heads/brand_new_name";
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the ref doesn't exist on the file system */
- git_path_join(temp_path, repo->path_repository, packed_head_name);
- must_pass(!git_futils_exists(temp_path));
+ must_pass(git_buf_joinpath(&temp_path, repo->path_repository, packed_head_name));
+ must_pass(!git_futils_exists(temp_path.ptr));
/* The reference can however be looked-up... */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
@@ -618,26 +625,27 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)")
must_be_true(git_reference_is_packed(looked_up_ref) == 0);
/* ...and the ref now happily lives in the file system */
- git_path_join(temp_path, repo->path_repository, brand_new_name);
- must_pass(git_futils_exists(temp_path));
+ must_pass(git_buf_joinpath(&temp_path, repo->path_repository, brand_new_name));
+ must_pass(git_futils_exists(temp_path.ptr));
close_temp_repo(repo);
git_reference_free(looked_up_ref);
git_reference_free(another_looked_up_ref);
+ git_buf_free(&temp_path);
END_TEST
BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference which happens to be in both loose and pack state")
git_reference *looked_up_ref, *another_looked_up_ref;
git_repository *repo;
- char temp_path[GIT_PATH_MAX];
+ git_buf temp_path = GIT_BUF_INIT;
const char *brand_new_name = "refs/heads/brand_new_name";
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the other reference exists on the file system */
- git_path_join(temp_path, repo->path_repository, packed_test_head_name);
- must_pass(git_futils_exists(temp_path));
+ must_pass(git_buf_joinpath(&temp_path, repo->path_repository, packed_test_head_name));
+ must_pass(git_futils_exists(temp_path.ptr));
/* Lookup the other reference */
must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
@@ -662,12 +670,13 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference
must_be_true(git_reference_is_packed(another_looked_up_ref) == 0);
/* Ensure the other ref still exists on the file system */
- must_pass(git_futils_exists(temp_path));
+ must_pass(git_futils_exists(temp_path.ptr));
close_temp_repo(repo);
git_reference_free(looked_up_ref);
git_reference_free(another_looked_up_ref);
+ git_buf_free(&temp_path);
END_TEST
BEGIN_TEST(rename3, "can not rename a reference with the name of an existing reference")
@@ -884,13 +893,13 @@ END_TEST
BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove both tracks in the filesystem")
git_reference *looked_up_ref, *another_looked_up_ref;
git_repository *repo;
- char temp_path[GIT_PATH_MAX];
+ git_buf temp_path = GIT_BUF_INIT;
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
/* Ensure the loose reference exists on the file system */
- git_path_join(temp_path, repo->path_repository, packed_test_head_name);
- must_pass(git_futils_exists(temp_path));
+ must_pass(git_buf_joinpath(&temp_path, repo->path_repository, packed_test_head_name));
+ must_pass(git_futils_exists(temp_path.ptr));
/* Lookup the reference */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));
@@ -905,11 +914,12 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove
must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name));
/* Ensure the loose reference doesn't exist any longer on the file system */
- must_pass(!git_futils_exists(temp_path));
+ must_pass(!git_futils_exists(temp_path.ptr));
close_temp_repo(repo);
git_reference_free(another_looked_up_ref);
+ git_buf_free(&temp_path);
END_TEST
BEGIN_TEST(delete1, "can delete a just packed reference")