]> git.proxmox.com Git - libgit2.git/blobdiff - tests/refs/revparse.c
New upstream version 1.3.0+dfsg.1
[libgit2.git] / tests / refs / revparse.c
index a540f389dbfe16d9fee49a3ebcfafa583a2fa7d0..bc6e0a4c4115114f93a759ee11f17bb231620e39 100644 (file)
@@ -24,11 +24,11 @@ static void test_object_and_ref_inrepo(
        error = git_revparse_ext(&obj, &ref, repo, spec);
 
        if (expected_oid != NULL) {
-               cl_assert_equal_i(0, error);
+               cl_git_pass(error);
                git_oid_fmt(objstr, git_object_id(obj));
                cl_assert_equal_s(objstr, expected_oid);
        } else
-               cl_assert_equal_i(GIT_ENOTFOUND, error);
+               cl_git_fail(error);
 
        if (assert_reference_retrieval) {
                if (expected_refname == NULL)
@@ -50,7 +50,7 @@ static void test_id_inrepo(
        const char *spec,
        const char *expected_left,
        const char *expected_right,
-       git_revparse_mode_t expected_flags,
+       git_revspec_t expected_flags,
        git_repository *repo)
 {
        git_revspec revspec;
@@ -90,7 +90,7 @@ static void test_object_and_ref(const char *spec, const char *expected_oid, cons
 static void test_rangelike(const char *rangelike,
                                                   const char *expected_left,
                                                   const char *expected_right,
-                                                  git_revparse_mode_t expected_revparseflags)
+                                                  git_revspec_t expected_revparseflags)
 {
        char objstr[64] = {0};
        git_revspec revspec;
@@ -117,11 +117,19 @@ static void test_id(
        const char *spec,
        const char *expected_left,
        const char *expected_right,
-       git_revparse_mode_t expected_flags)
+       git_revspec_t expected_flags)
 {
        test_id_inrepo(spec, expected_left, expected_right, expected_flags, g_repo);
 }
 
+static void test_invalid_revspec(const char* invalid_spec)
+{
+       git_revspec revspec;
+
+       cl_assert_equal_i(
+               GIT_EINVALIDSPEC, git_revparse(&revspec, g_repo, invalid_spec));
+}
+
 void test_refs_revparse__initialize(void)
 {
        cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
@@ -222,7 +230,7 @@ void test_refs_revparse__to_type(void)
        assert_invalid_single_spec("wrapped_tag^{trip}");
        test_object("point_to_blob^{commit}", NULL);
        cl_assert_equal_i(
-               GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}"));
+               GIT_EPEEL, git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}"));
 
        test_object("wrapped_tag^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
        test_object("wrapped_tag^{tree}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
@@ -325,12 +333,12 @@ static void create_fake_stash_reference_and_reflog(git_repository *repo)
        cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&log_path)));
 
        cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
-       cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0, NULL, NULL));
+       cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0, NULL));
        git_reference_free(master);
 
        cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
 
-       git_buf_free(&log_path);
+       git_buf_dispose(&log_path);
        git_reference_free(new_master);
 }
 
@@ -597,7 +605,7 @@ void test_refs_revparse__issue_994(void)
                "refs/remotes/origin/bim_with_3d@11296",
                git_reference_target(head),
                0,
-               NULL, NULL));
+               NULL));
 
        cl_git_pass(git_revparse_single(&target, repo, "origin/bim_with_3d@11296"));
        git_object_free(target);
@@ -634,7 +642,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void)
        test_object_inrepo("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
 
        cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
-       cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0, NULL, NULL));
+       cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0));
 
        git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
 
@@ -672,7 +680,7 @@ void test_refs_revparse__try_to_retrieve_sha_before_branch(void)
        test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
 
        cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
-       cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0, NULL, NULL));
+       cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0));
 
        git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
 
@@ -708,7 +716,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
        test_object_inrepo("c47800", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
 
        cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
-       cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0, NULL, NULL));
+       cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0));
 
        git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
 
@@ -727,28 +735,55 @@ void test_refs_revparse__range(void)
        test_rangelike("be3563a^1..be3563a",
                       "9fd738e8f7967c078dceed8190330fc8648ee56a",
                       "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
-                      GIT_REVPARSE_RANGE);
+                      GIT_REVSPEC_RANGE);
 
        test_rangelike("be3563a^1...be3563a",
                       "9fd738e8f7967c078dceed8190330fc8648ee56a",
                       "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
-                      GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+                      GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
 
        test_rangelike("be3563a^1.be3563a", NULL, NULL, 0);
 }
 
 void test_refs_revparse__parses_range_operator(void)
 {
-       test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVPARSE_SINGLE);
+       test_id("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
        test_id("HEAD~3..HEAD",
                "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
                "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
-               GIT_REVPARSE_RANGE);
+               GIT_REVSPEC_RANGE);
 
        test_id("HEAD~3...HEAD",
                "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
                "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
-               GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE);
+               GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
+
+       test_id("HEAD~3..",
+               "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
+               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+               GIT_REVSPEC_RANGE);
+
+       test_id("HEAD~3...",
+               "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
+               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+               GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
+
+       test_id("..HEAD~3",
+               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+               "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
+               GIT_REVSPEC_RANGE);
+
+       test_id("...HEAD~3",
+               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+               "4a202b346bb0fb0db7eff3cffeb3c70babbd2045",
+               GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
+
+       test_id("...",
+               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
+               GIT_REVSPEC_RANGE | GIT_REVSPEC_MERGE_BASE);
+
+       test_invalid_revspec("..");
 }
 
 void test_refs_revparse__ext_retrieves_both_the_reference_and_its_target(void)
@@ -812,3 +847,18 @@ void test_refs_revparse__ext_returns_NULL_reference_when_expression_points_at_a_
                "0266163a49e280c4f5ed1e08facd36a2bd716bcf",
         NULL);
 }
+
+void test_refs_revparse__uneven_sizes(void)
+{
+       test_object("a65fedf39aefe402d3bb6e24df4d4f5fe454775",
+                               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+
+       test_object("a65fedf39aefe402d3bb6e24df4d4f5fe45477",
+                               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+
+       test_object("a65fedf39aefe402d3bb6e24df4d4f5fe4547",
+                               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+
+       test_object("a65fedf39aefe402d3bb6e24df4d",
+                               "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+}