Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2013-05-09 18:42:39 +0400
committernulltoken <emeric.fermas@gmail.com>2013-05-16 23:43:24 +0400
commite841c533d75c12156e0be8811d02f0537e32a458 (patch)
treec3bbeac67ce1e70a96ec2173a4e722720539d0e1 /tests-clar
parentdcaa898d8200d5eefa5ba8c7618c5526d8392da0 (diff)
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 `<branchname>@{upstream}` syntax).
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/refs/revparse.c49
1 files changed, 47 insertions, 2 deletions
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);
+}