diff options
Diffstat (limited to 'tests-clar/refs')
-rw-r--r-- | tests-clar/refs/branches/foreach.c | 36 | ||||
-rw-r--r-- | tests-clar/refs/branches/move.c | 22 | ||||
-rw-r--r-- | tests-clar/refs/branches/remote.c | 9 | ||||
-rw-r--r-- | tests-clar/refs/branches/upstream.c | 13 | ||||
-rw-r--r-- | tests-clar/refs/delete.c | 6 | ||||
-rw-r--r-- | tests-clar/refs/foreachglob.c | 14 | ||||
-rw-r--r-- | tests-clar/refs/iterator.c | 97 | ||||
-rw-r--r-- | tests-clar/refs/list.c | 15 | ||||
-rw-r--r-- | tests-clar/refs/listall.c | 4 | ||||
-rw-r--r-- | tests-clar/refs/pack.c | 11 | ||||
-rw-r--r-- | tests-clar/refs/peel.c | 31 | ||||
-rw-r--r-- | tests-clar/refs/ref_helpers.c | 6 | ||||
-rw-r--r-- | tests-clar/refs/reflog/reflog.c | 2 | ||||
-rw-r--r-- | tests-clar/refs/rename.c | 14 | ||||
-rw-r--r-- | tests-clar/refs/revparse.c | 68 | ||||
-rw-r--r-- | tests-clar/refs/setter.c | 16 | ||||
-rw-r--r-- | tests-clar/refs/shorthand.c | 27 |
17 files changed, 310 insertions, 81 deletions
diff --git a/tests-clar/refs/branches/foreach.c b/tests-clar/refs/branches/foreach.c index 96a5bc2b9..433812cb4 100644 --- a/tests-clar/refs/branches/foreach.c +++ b/tests-clar/refs/branches/foreach.c @@ -24,6 +24,8 @@ void test_refs_branches_foreach__cleanup(void) repo = NULL; cl_fixture_cleanup("testrepo.git"); + + cl_git_sandbox_cleanup(); } static int count_branch_list_cb(const char *branch_name, git_branch_t branch_type, void *payload) @@ -72,14 +74,11 @@ static void assert_branch_has_been_found(struct expectations *findings, const ch { int pos = 0; - while (findings[pos].branch_name) - { + for (pos = 0; findings[pos].branch_name; ++pos) { if (strcmp(expected_branch_name, findings[pos].branch_name) == 0) { cl_assert_equal_i(1, findings[pos].encounters); return; } - - pos++; } cl_fail("expected branch not found in list."); @@ -94,12 +93,9 @@ static int contains_branch_list_cb(const char *branch_name, git_branch_t branch_ exp = (struct expectations *)payload; - while (exp[pos].branch_name) - { + for (pos = 0; exp[pos].branch_name; ++pos) { if (strcmp(branch_name, exp[pos].branch_name) == 0) exp[pos].encounters++; - - pos++; } return 0; @@ -126,7 +122,7 @@ void test_refs_branches_foreach__retrieve_remote_symbolic_HEAD_when_present(void cl_git_pass(git_branch_foreach(repo, GIT_BRANCH_REMOTE, contains_branch_list_cb, &exp)); assert_branch_has_been_found(exp, "nulltoken/HEAD"); - assert_branch_has_been_found(exp, "nulltoken/HEAD"); + assert_branch_has_been_found(exp, "nulltoken/master"); } static int branch_list_interrupt_cb( @@ -153,3 +149,25 @@ void test_refs_branches_foreach__can_cancel(void) cl_assert_equal_i(5, count); } + +void test_refs_branches_foreach__mix_of_packed_and_loose(void) +{ + struct expectations exp[] = { + { "master", 0 }, + { "origin/HEAD", 0 }, + { "origin/master", 0 }, + { "origin/packed", 0 }, + { NULL, 0 } + }; + git_repository *r2; + + r2 = cl_git_sandbox_init("testrepo2"); + + cl_git_pass(git_branch_foreach(r2, GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, + contains_branch_list_cb, &exp)); + + assert_branch_has_been_found(exp, "master"); + assert_branch_has_been_found(exp, "origin/HEAD"); + assert_branch_has_been_found(exp, "origin/master"); + assert_branch_has_been_found(exp, "origin/packed"); +} diff --git a/tests-clar/refs/branches/move.c b/tests-clar/refs/branches/move.c index 7267f941d..ecf14e006 100644 --- a/tests-clar/refs/branches/move.c +++ b/tests-clar/refs/branches/move.c @@ -24,7 +24,7 @@ void test_refs_branches_move__can_move_a_local_branch(void) cl_git_pass(git_branch_move(&new_ref, original_ref, NEW_BRANCH_NAME, 0)); cl_assert_equal_s(GIT_REFS_HEADS_DIR NEW_BRANCH_NAME, git_reference_name(new_ref)); - + git_reference_free(original_ref); git_reference_free(new_ref); } @@ -32,7 +32,7 @@ void test_refs_branches_move__can_move_a_local_branch(void) void test_refs_branches_move__can_move_a_local_branch_to_a_different_namespace(void) { git_reference *original_ref, *new_ref, *newer_ref; - + cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2")); /* Downward */ @@ -42,14 +42,14 @@ void test_refs_branches_move__can_move_a_local_branch_to_a_different_namespace(v /* Upward */ cl_git_pass(git_branch_move(&newer_ref, new_ref, "br2", 0)); git_reference_free(new_ref); - + git_reference_free(newer_ref); } void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_namespace(void) { git_reference *original_ref, *new_ref, *newer_ref; - + cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2")); /* Downward */ @@ -59,29 +59,29 @@ void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_n /* Upward */ cl_git_pass(git_branch_move(&newer_ref, new_ref, "br2", 0)); git_reference_free(new_ref); - + git_reference_free(newer_ref); } void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void) { git_reference *original_ref, *new_ref; - + cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2")); cl_assert_equal_i(GIT_EEXISTS, git_branch_move(&new_ref, original_ref, "master", 0)); - + git_reference_free(original_ref); } void test_refs_branches_move__moving_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void) { git_reference *original_ref, *new_ref; - + cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2")); cl_assert_equal_i(GIT_EINVALIDSPEC, git_branch_move(&new_ref, original_ref, "Inv@{id", 0)); - + git_reference_free(original_ref); } @@ -98,11 +98,11 @@ void test_refs_branches_move__can_not_move_a_non_branch(void) void test_refs_branches_move__can_force_move_over_an_existing_branch(void) { git_reference *original_ref, *new_ref; - + cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2")); cl_git_pass(git_branch_move(&new_ref, original_ref, "master", 1)); - + git_reference_free(original_ref); git_reference_free(new_ref); } diff --git a/tests-clar/refs/branches/remote.c b/tests-clar/refs/branches/remote.c index 2beef3724..c110adb33 100644 --- a/tests-clar/refs/branches/remote.c +++ b/tests-clar/refs/branches/remote.c @@ -49,16 +49,20 @@ void test_refs_branches_remote__no_matching_remote_returns_error(void) { const char *unknown = "refs/remotes/nonexistent/master"; + giterr_clear(); cl_git_fail_with(git_branch_remote_name( NULL, 0, g_repo, unknown), GIT_ENOTFOUND); + cl_assert(giterr_last() != NULL); } void test_refs_branches_remote__local_remote_returns_error(void) { const char *local = "refs/heads/master"; + giterr_clear(); cl_git_fail_with(git_branch_remote_name( NULL, 0, g_repo, local), GIT_ERROR); + cl_assert(giterr_last() != NULL); } void test_refs_branches_remote__ambiguous_remote_returns_error(void) @@ -69,11 +73,14 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void) cl_git_pass(git_remote_create(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2")); /* Update the remote fetch spec */ - cl_git_pass(git_remote_set_fetchspec(remote, "refs/heads/*:refs/remotes/test/*")); + git_remote_clear_refspecs(remote); + cl_git_pass(git_remote_add_fetch(remote, "refs/heads/*:refs/remotes/test/*")); cl_git_pass(git_remote_save(remote)); git_remote_free(remote); + giterr_clear(); cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name), GIT_EAMBIGUOUS); + cl_assert(giterr_last() != NULL); } diff --git a/tests-clar/refs/branches/upstream.c b/tests-clar/refs/branches/upstream.c index 2d0ebd240..69e55a0c5 100644 --- a/tests-clar/refs/branches/upstream.c +++ b/tests-clar/refs/branches/upstream.c @@ -103,6 +103,7 @@ void test_refs_branches_upstream__set_unset_upstream(void) repository = cl_git_sandbox_init("testrepo.git"); + /* remote */ cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test")); cl_git_pass(git_branch_set_upstream(branch, "test/master")); @@ -112,6 +113,18 @@ void test_refs_branches_upstream__set_unset_upstream(void) cl_git_pass(git_config_get_string(&value, config, "branch.test.merge")); cl_assert_equal_s(value, "refs/heads/master"); + git_reference_free(branch); + + /* local */ + cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test")); + cl_git_pass(git_branch_set_upstream(branch, "master")); + + cl_git_pass(git_config_get_string(&value, config, "branch.test.remote")); + cl_assert_equal_s(value, "."); + cl_git_pass(git_config_get_string(&value, config, "branch.test.merge")); + cl_assert_equal_s(value, "refs/heads/master"); + + /* unset */ cl_git_pass(git_branch_set_upstream(branch, NULL)); cl_git_fail_with(git_config_get_string(&value, config, "branch.test.merge"), GIT_ENOTFOUND); cl_git_fail_with(git_config_get_string(&value, config, "branch.test.remote"), GIT_ENOTFOUND); diff --git a/tests-clar/refs/delete.c b/tests-clar/refs/delete.c index ac517d869..973768aeb 100644 --- a/tests-clar/refs/delete.c +++ b/tests-clar/refs/delete.c @@ -1,7 +1,8 @@ #include "clar_libgit2.h" -#include "repository.h" +#include "fileops.h" #include "git2/reflog.h" +#include "git2/refdb.h" #include "reflog.h" #include "ref_helpers.h" @@ -31,7 +32,7 @@ void test_refs_delete__packed_loose(void) git_buf temp_path = GIT_BUF_INIT; /* Ensure the loose reference exists on the file system */ - cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, packed_test_head_name)); + cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name)); cl_assert(git_path_exists(temp_path.ptr)); /* Lookup the reference */ @@ -88,4 +89,5 @@ void test_refs_delete__packed_only(void) /* This should pass */ cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); + git_refdb_free(refdb); } diff --git a/tests-clar/refs/foreachglob.c b/tests-clar/refs/foreachglob.c index 4da1a15dd..2c458082f 100644 --- a/tests-clar/refs/foreachglob.c +++ b/tests-clar/refs/foreachglob.c @@ -37,11 +37,11 @@ static int count_cb(const char *reference_name, void *payload) return 0; } -static void assert_retrieval(const char *glob, unsigned int flags, int expected_count) +static void assert_retrieval(const char *glob, int expected_count) { int count = 0; - cl_git_pass(git_reference_foreach_glob(repo, glob, flags, count_cb, &count)); + cl_git_pass(git_reference_foreach_glob(repo, glob, count_cb, &count)); cl_assert_equal_i(expected_count, count); } @@ -49,17 +49,17 @@ static void assert_retrieval(const char *glob, unsigned int flags, int expected_ void test_refs_foreachglob__retrieve_all_refs(void) { /* 12 heads (including one packed head) + 1 note + 2 remotes + 7 tags */ - assert_retrieval("*", GIT_REF_LISTALL, 22); + assert_retrieval("*", 22); } void test_refs_foreachglob__retrieve_remote_branches(void) { - assert_retrieval("refs/remotes/*", GIT_REF_LISTALL, 2); + assert_retrieval("refs/remotes/*", 2); } void test_refs_foreachglob__retrieve_local_branches(void) { - assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 12); + assert_retrieval("refs/heads/*", 12); } void test_refs_foreachglob__retrieve_partially_named_references(void) @@ -69,7 +69,7 @@ void test_refs_foreachglob__retrieve_partially_named_references(void) * refs/remotes/test/master, refs/tags/test */ - assert_retrieval("*test*", GIT_REF_LISTALL, 4); + assert_retrieval("*test*", 4); } @@ -89,7 +89,7 @@ void test_refs_foreachglob__can_cancel(void) int count = 0; cl_assert_equal_i(GIT_EUSER, git_reference_foreach_glob( - repo, "*", GIT_REF_LISTALL, interrupt_cb, &count) ); + repo, "*", interrupt_cb, &count) ); cl_assert_equal_i(11, count); } diff --git a/tests-clar/refs/iterator.c b/tests-clar/refs/iterator.c new file mode 100644 index 000000000..266410fdf --- /dev/null +++ b/tests-clar/refs/iterator.c @@ -0,0 +1,97 @@ +#include "clar_libgit2.h" +#include "refs.h" +#include "vector.h" + +static git_repository *repo; + +void test_refs_iterator__initialize(void) +{ + cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); +} + +void test_refs_iterator__cleanup(void) +{ + git_repository_free(repo); +} + +static const char *refnames[] = { + "refs/heads/br2", + "refs/heads/cannot-fetch", + "refs/heads/chomped", + "refs/heads/haacked", + "refs/heads/master", + "refs/heads/not-good", + "refs/heads/packed", + "refs/heads/packed-test", + "refs/heads/subtrees", + "refs/heads/test", + "refs/heads/track-local", + "refs/heads/trailing", + "refs/notes/fanout", + "refs/remotes/test/master", + "refs/tags/annotated_tag_to_blob", + "refs/tags/e90810b", + "refs/tags/hard_tag", + "refs/tags/point_to_blob", + "refs/tags/taggerless", + "refs/tags/test", + "refs/tags/wrapped_tag", +}; + +static int refcmp_cb(const void *a, const void *b) +{ + const git_reference *refa = (const git_reference *)a; + const git_reference *refb = (const git_reference *)b; + + return strcmp(refa->name, refb->name); +} + +void test_refs_iterator__list(void) +{ + git_reference_iterator *iter; + git_vector output; + git_reference *ref; + int error; + size_t i; + + cl_git_pass(git_vector_init(&output, 32, &refcmp_cb)); + cl_git_pass(git_reference_iterator_new(&iter, repo)); + + do { + error = git_reference_next(&ref, iter); + cl_assert(error == 0 || error == GIT_ITEROVER); + if (error != GIT_ITEROVER) { + cl_git_pass(git_vector_insert(&output, ref)); + } + } while (!error); + + git_reference_iterator_free(iter); + cl_assert_equal_sz(output.length, ARRAY_SIZE(refnames)); + + git_vector_sort(&output); + + git_vector_foreach(&output, i, ref) { + cl_assert_equal_s(ref->name, refnames[i]); + git_reference_free(ref); + } + + git_vector_free(&output); +} + +void test_refs_iterator__empty(void) +{ + git_reference_iterator *iter; + git_odb *odb; + git_reference *ref; + git_repository *empty; + + cl_git_pass(git_odb_new(&odb)); + cl_git_pass(git_repository_wrap_odb(&empty, odb)); + + cl_git_pass(git_reference_iterator_new(&iter, empty)); + cl_assert_equal_i(GIT_ITEROVER, git_reference_next(&ref, iter)); + + git_reference_iterator_free(iter); + git_odb_free(odb); + git_repository_free(empty); +} diff --git a/tests-clar/refs/list.c b/tests-clar/refs/list.c index 3948b2b7a..c9c2af4a7 100644 --- a/tests-clar/refs/list.c +++ b/tests-clar/refs/list.c @@ -25,7 +25,7 @@ void test_refs_list__all(void) // try to list all the references in our test repo git_strarray ref_list; - cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_LISTALL)); + cl_git_pass(git_reference_list(&ref_list, g_repo)); /*{ unsigned short i; @@ -41,17 +41,6 @@ void test_refs_list__all(void) git_strarray_free(&ref_list); } -void test_refs_list__symbolic_only(void) -{ - // try to list only the symbolic references - git_strarray ref_list; - - cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_SYMBOLIC)); - cl_assert(ref_list.count == 0); /* no symrefs in the test repo */ - - git_strarray_free(&ref_list); -} - void test_refs_list__do_not_retrieve_references_which_name_end_with_a_lock_extension(void) { git_strarray ref_list; @@ -61,7 +50,7 @@ void test_refs_list__do_not_retrieve_references_which_name_end_with_a_lock_exten "./testrepo/.git/refs/heads/hanwen.lock", "144344043ba4d4a405da03de3844aa829ae8be0e\n"); - cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_LISTALL)); + cl_git_pass(git_reference_list(&ref_list, g_repo)); cl_assert_equal_i((int)ref_list.count, 13); git_strarray_free(&ref_list); diff --git a/tests-clar/refs/listall.c b/tests-clar/refs/listall.c index 8f4c3746b..c696fbb2e 100644 --- a/tests-clar/refs/listall.c +++ b/tests-clar/refs/listall.c @@ -9,7 +9,7 @@ static void ensure_no_refname_starts_with_a_forward_slash(const char *path) size_t i; cl_git_pass(git_repository_open(&repo, path)); - cl_git_pass(git_reference_list(&ref_list, repo, GIT_REF_LISTALL)); + cl_git_pass(git_reference_list(&ref_list, repo)); cl_assert(ref_list.count > 0); @@ -38,7 +38,7 @@ void test_refs_listall__from_repository_opened_through_gitdir_path(void) void test_refs_listall__from_repository_with_no_trailing_newline(void) { cl_git_pass(git_repository_open(&repo, cl_fixture("bad_tag.git"))); - cl_git_pass(git_reference_list(&ref_list, repo, GIT_REF_LISTALL)); + cl_git_pass(git_reference_list(&ref_list, repo)); cl_assert(ref_list.count > 0); diff --git a/tests-clar/refs/pack.c b/tests-clar/refs/pack.c index 973abae30..d8d5cc6d0 100644 --- a/tests-clar/refs/pack.c +++ b/tests-clar/refs/pack.c @@ -1,8 +1,10 @@ #include "clar_libgit2.h" -#include "repository.h" +#include "fileops.h" #include "git2/reflog.h" +#include "git2/refdb.h" #include "reflog.h" +#include "refs.h" #include "ref_helpers.h" static const char *loose_tag_ref_name = "refs/tags/e90810b"; @@ -25,6 +27,7 @@ static void packall(void) cl_git_pass(git_repository_refdb(&refdb, g_repo)); cl_git_pass(git_refdb_compress(refdb)); + git_refdb_free(refdb); } void test_refs_pack__empty(void) @@ -32,7 +35,7 @@ void test_refs_pack__empty(void) // create a packfile for an empty folder git_buf temp_path = GIT_BUF_INIT; - cl_git_pass(git_buf_join_n(&temp_path, '/', 3, g_repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir")); + cl_git_pass(git_buf_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir")); cl_git_pass(git_futils_mkdir_r(temp_path.ptr, NULL, GIT_REFS_DIR_MODE)); git_buf_free(&temp_path); @@ -59,7 +62,7 @@ void test_refs_pack__loose(void) packall(); /* Ensure the packed-refs file exists */ - cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, GIT_PACKEDREFS_FILE)); + cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), GIT_PACKEDREFS_FILE)); cl_assert(git_path_exists(temp_path.ptr)); /* Ensure the known ref can still be looked up but is now packed */ @@ -68,7 +71,7 @@ void test_refs_pack__loose(void) cl_assert_equal_s(reference->name, loose_tag_ref_name); /* Ensure the known ref has been removed from the loose folder structure */ - cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, loose_tag_ref_name)); + cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), loose_tag_ref_name)); cl_assert(!git_path_exists(temp_path.ptr)); git_reference_free(reference); diff --git a/tests-clar/refs/peel.c b/tests-clar/refs/peel.c index 34bd02ce0..f2fb6e259 100644 --- a/tests-clar/refs/peel.c +++ b/tests-clar/refs/peel.c @@ -1,19 +1,24 @@ #include "clar_libgit2.h" static git_repository *g_repo; +static git_repository *g_peel_repo; void test_refs_peel__initialize(void) { cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git"))); + cl_git_pass(git_repository_open(&g_peel_repo, cl_fixture("peeled.git"))); } void test_refs_peel__cleanup(void) { git_repository_free(g_repo); g_repo = NULL; + git_repository_free(g_peel_repo); + g_peel_repo = NULL; } -static void assert_peel( +static void assert_peel_generic( + git_repository *repo, const char *ref_name, git_otype requested_type, const char* expected_sha, @@ -23,7 +28,7 @@ static void assert_peel( git_reference *ref; git_object *peeled; - cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name)); + cl_git_pass(git_reference_lookup(&ref, repo, ref_name)); cl_git_pass(git_reference_peel(&peeled, ref, requested_type)); @@ -36,6 +41,16 @@ static void assert_peel( git_reference_free(ref); } +static void assert_peel( + const char *ref_name, + git_otype requested_type, + const char* expected_sha, + git_otype expected_type) +{ + assert_peel_generic(g_repo, ref_name, requested_type, + expected_sha, expected_type); +} + static void assert_peel_error(int error, const char *ref_name, git_otype requested_type) { git_reference *ref; @@ -90,3 +105,15 @@ void test_refs_peel__can_peel_into_any_non_tag_object(void) assert_peel("refs/tags/test", GIT_OBJ_ANY, "e90810b8df3e80c413d903f631643c716887138d", GIT_OBJ_COMMIT); } + +void test_refs_peel__can_peel_fully_peeled_packed_refs(void) +{ + assert_peel_generic(g_peel_repo, + "refs/tags/tag-inside-tags", GIT_OBJ_ANY, + "0df1a5865c8abfc09f1f2182e6a31be550e99f07", + GIT_OBJ_COMMIT); + assert_peel_generic(g_peel_repo, + "refs/foo/tag-outside-tags", GIT_OBJ_ANY, + "0df1a5865c8abfc09f1f2182e6a31be550e99f07", + GIT_OBJ_COMMIT); +} diff --git a/tests-clar/refs/ref_helpers.c b/tests-clar/refs/ref_helpers.c index 16ab9e6ef..7676e65a7 100644 --- a/tests-clar/refs/ref_helpers.c +++ b/tests-clar/refs/ref_helpers.c @@ -11,15 +11,15 @@ int reference_is_packed(git_reference *ref) int packed; assert(ref); - + if (git_buf_joinpath(&ref_path, git_repository_path(git_reference_owner(ref)), git_reference_name(ref)) < 0) return -1; packed = !git_path_isfile(ref_path.ptr); - + git_buf_free(&ref_path); - + return packed; } diff --git a/tests-clar/refs/reflog/reflog.c b/tests-clar/refs/reflog/reflog.c index 1cd0ddd92..095cabf04 100644 --- a/tests-clar/refs/reflog/reflog.c +++ b/tests-clar/refs/reflog/reflog.c @@ -1,6 +1,6 @@ #include "clar_libgit2.h" -#include "repository.h" +#include "fileops.h" #include "git2/reflog.h" #include "reflog.h" diff --git a/tests-clar/refs/rename.c b/tests-clar/refs/rename.c index e39abeb05..543bc4d62 100644 --- a/tests-clar/refs/rename.c +++ b/tests-clar/refs/rename.c @@ -1,8 +1,9 @@ #include "clar_libgit2.h" -#include "repository.h" +#include "fileops.h" #include "git2/reflog.h" #include "reflog.h" +#include "refs.h" #include "ref_helpers.h" static const char *loose_tag_ref_name = "refs/tags/e90810b"; @@ -38,7 +39,7 @@ void test_refs_rename__loose(void) const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu"; /* Ensure the ref doesn't exist on the file system */ - cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, new_name)); + cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), new_name)); cl_assert(!git_path_exists(temp_path.ptr)); /* Retrieval of the reference to rename */ @@ -64,7 +65,7 @@ void test_refs_rename__loose(void) cl_assert(reference_is_packed(new_ref) == 0); /* ...and the ref can be found in the file system */ - cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, new_name)); + cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), new_name)); cl_assert(git_path_exists(temp_path.ptr)); git_reference_free(new_ref); @@ -80,7 +81,7 @@ void test_refs_rename__packed(void) const char *brand_new_name = "refs/heads/brand_new_name"; /* Ensure the ref doesn't exist on the file system */ - cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, packed_head_name)); + cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name)); cl_assert(!git_path_exists(temp_path.ptr)); /* The reference can however be looked-up... */ @@ -106,7 +107,7 @@ void test_refs_rename__packed(void) cl_assert(reference_is_packed(new_ref) == 0); /* ...and the ref now happily lives in the file system */ - cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, brand_new_name)); + cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name)); cl_assert(git_path_exists(temp_path.ptr)); git_reference_free(new_ref); @@ -122,7 +123,7 @@ void test_refs_rename__packed_doesnt_pack_others(void) const char *brand_new_name = "refs/heads/brand_new_name"; /* Ensure the other reference exists on the file system */ - cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, packed_test_head_name)); + cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name)); cl_assert(git_path_exists(temp_path.ptr)); /* Lookup the other reference */ @@ -284,6 +285,7 @@ void test_refs_rename__overwrite(void) git_reference_free(ref_one); git_reference_free(ref_one_new); git_reference_free(ref_two); + git_refdb_free(refdb); } diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c index 74472b175..69d92745c 100644 --- a/tests-clar/refs/revparse.c +++ b/tests-clar/refs/revparse.c @@ -9,13 +9,19 @@ static git_repository *g_repo; static git_object *g_obj; /* Helpers */ -static void test_object_inrepo(const char *spec, const char *expected_oid, git_repository *repo) +static void test_object_and_ref_inrepo( + const char *spec, + const char *expected_oid, + const char *expected_refname, + git_repository *repo, + bool assert_reference_retrieval) { char objstr[64] = {0}; git_object *obj = NULL; + git_reference *ref = NULL; int error; - error = git_revparse_single(&obj, repo, spec); + error = git_revparse_ext(&obj, &ref, repo, spec); if (expected_oid != NULL) { cl_assert_equal_i(0, error); @@ -24,7 +30,20 @@ static void test_object_inrepo(const char *spec, const char *expected_oid, git_r } else cl_assert_equal_i(GIT_ENOTFOUND, error); + if (assert_reference_retrieval) { + if (expected_refname == NULL) + cl_assert(NULL == ref); + else + cl_assert_equal_s(expected_refname, git_reference_name(ref)); + } + git_object_free(obj); + git_reference_free(ref); +} + +static void test_object_inrepo(const char *spec, const char *expected_oid, git_repository *repo) +{ + test_object_and_ref_inrepo(spec, expected_oid, NULL, repo, false); } static void test_id_inrepo( @@ -63,6 +82,11 @@ static void test_object(const char *spec, const char *expected_oid) test_object_inrepo(spec, expected_oid, g_repo); } +static void test_object_and_ref(const char *spec, const char *expected_oid, const char *expected_refname) +{ + test_object_and_ref_inrepo(spec, expected_oid, expected_refname, g_repo, true); +} + static void test_rangelike(const char *rangelike, const char *expected_left, const char *expected_right, @@ -557,12 +581,12 @@ void test_refs_revparse__issue_994(void) /** * $ git rev-parse blah-7-gc47800c * c47800c7266a2be04c571c04d5a6614691ea99bd - * + * * $ git rev-parse HEAD~3 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 - * + * * $ git branch blah-7-gc47800c HEAD~3 - * + * * $ git rev-parse blah-7-gc47800c * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 */ @@ -592,15 +616,15 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void) /** * $ git rev-parse a65fedf39aefe402d3bb6e24df4d4f5fe4547750 * a65fedf39aefe402d3bb6e24df4d4f5fe4547750 - * + * * $ git rev-parse HEAD~3 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 - * + * * $ git branch a65fedf39aefe402d3bb6e24df4d4f5fe4547750 HEAD~3 - * + * * $ git rev-parse a65fedf39aefe402d3bb6e24df4d4f5fe4547750 * a65fedf39aefe402d3bb6e24df4d4f5fe4547750 - * + * * $ git rev-parse heads/a65fedf39aefe402d3bb6e24df4d4f5fe4547750 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 */ @@ -631,12 +655,12 @@ void test_refs_revparse__try_to_retrieve_sha_before_branch(void) /** * $ git rev-parse c47800 * c47800c7266a2be04c571c04d5a6614691ea99bd - * + * * $ git rev-parse HEAD~3 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 - * + * * $ git branch c47800 HEAD~3 - * + * * $ git rev-parse c47800 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045 */ @@ -695,3 +719,23 @@ void test_refs_revparse__parses_range_operator(void) GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE); } +void test_refs_revparse__ext_retrieves_both_the_reference_and_its_target(void) +{ + test_object_and_ref( + "master@{upstream}", + "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", + "refs/remotes/test/master"); + + test_object_and_ref( + "@{-1}", + "a4a7dce85cf63874e984719f4fdd239f5145052f", + "refs/heads/br2"); +} + +void test_refs_revparse__ext_can_expand_short_reference_names(void) +{ + test_object_and_ref( + "master", + "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", + "refs/heads/master"); +} diff --git a/tests-clar/refs/setter.c b/tests-clar/refs/setter.c index 713af814f..6d875f9b6 100644 --- a/tests-clar/refs/setter.c +++ b/tests-clar/refs/setter.c @@ -25,7 +25,7 @@ void test_refs_setter__update_direct(void) { git_reference *ref, *test_ref, *new_ref; git_oid id; - + cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name)); cl_assert(git_reference_type(ref) == GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); @@ -48,7 +48,7 @@ void test_refs_setter__update_direct(void) void test_refs_setter__update_symbolic(void) { git_reference *head, *new_head; - + cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD")); cl_assert(git_reference_type(head) == GIT_REF_SYMBOLIC); cl_assert(strcmp(git_reference_symbolic_target(head), ref_master_name) == 0); @@ -56,7 +56,7 @@ void test_refs_setter__update_symbolic(void) cl_git_pass(git_reference_symbolic_set_target(&new_head, head, ref_test_name)); git_reference_free(new_head); git_reference_free(head); - + cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD")); cl_assert(git_reference_type(head) == GIT_REF_SYMBOLIC); cl_assert(strcmp(git_reference_symbolic_target(head), ref_test_name) == 0); @@ -68,13 +68,13 @@ void test_refs_setter__cant_update_direct_with_symbolic(void) // Overwrite an existing object id reference with a symbolic one git_reference *ref, *new; git_oid id; - + cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name)); cl_assert(git_reference_type(ref) == GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); - + cl_git_fail(git_reference_symbolic_set_target(&new, ref, ref_name)); - + git_reference_free(ref); } @@ -83,7 +83,7 @@ void test_refs_setter__cant_update_symbolic_with_direct(void) // Overwrite an existing symbolic reference with an object id one git_reference *ref, *new; git_oid id; - + cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name)); cl_assert(git_reference_type(ref) == GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); @@ -94,6 +94,6 @@ void test_refs_setter__cant_update_symbolic_with_direct(void) /* Can't set an OID on a direct ref */ cl_git_fail(git_reference_set_target(&new, ref, &id)); - + git_reference_free(ref); } diff --git a/tests-clar/refs/shorthand.c b/tests-clar/refs/shorthand.c new file mode 100644 index 000000000..f995d26ca --- /dev/null +++ b/tests-clar/refs/shorthand.c @@ -0,0 +1,27 @@ +#include "clar_libgit2.h" + +#include "repository.h" + +void assert_shorthand(git_repository *repo, const char *refname, const char *shorthand) +{ + git_reference *ref; + + cl_git_pass(git_reference_lookup(&ref, repo, refname)); + cl_assert_equal_s(git_reference_shorthand(ref), shorthand); + git_reference_free(ref); +} + +void test_refs_shorthand__0(void) +{ + git_repository *repo; + + cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); + + + assert_shorthand(repo, "refs/heads/master", "master"); + assert_shorthand(repo, "refs/tags/test", "test"); + assert_shorthand(repo, "refs/remotes/test/master", "test/master"); + assert_shorthand(repo, "refs/notes/fanout", "notes/fanout"); + + git_repository_free(repo); +} |