From e841c533d75c12156e0be8811d02f0537e32a458 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 9 May 2013 16:42:39 +0200 Subject: revparse: Introduce git_revparse_ext() Expose a way to retrieve, along with the target git_object, the reference pointed at by some revparse expression (`@{<-n>}` or `@{upstream}` syntax). --- tests-clar/refs/revparse.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'tests-clar') diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c index 43406e239..1d156f567 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, @@ -694,3 +718,24 @@ void test_refs_revparse__parses_range_operator(void) "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", 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_only_retrieve_the_object_target(void) +{ + test_object_and_ref( + "master", + "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", + NULL); +} -- cgit v1.2.3