diff options
| author | Russell Belfer <rb@github.com> | 2013-05-16 13:13:28 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-05-16 13:13:28 -0700 |
| commit | 5b3d52ce37100c1d63229d195041fac3e6f89d28 (patch) | |
| tree | b09735f5fa44ba1a11b05ca01e7f743ffabc9654 /tests-clar | |
| parent | e3107e0ee182403f141178ee323e66c516cf3f08 (diff) | |
| parent | f672cd2a0925c230421efccdefd8e1f640bba41b (diff) | |
| download | libgit2-5b3d52ce37100c1d63229d195041fac3e6f89d28.tar.gz | |
Merge pull request #1568 from nulltoken/topic/revparse_ext
Introduce git_revparse_ext()
Diffstat (limited to 'tests-clar')
| -rw-r--r-- | tests-clar/refs/revparse.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c index 43406e239..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, @@ -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_can_expand_short_reference_names(void) +{ + test_object_and_ref( + "master", + "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", + "refs/heads/master"); +} |
