]> 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 3f89b5f7765220a82ac8ca15e447623be60899e6..bc6e0a4c4115114f93a759ee11f17bb231620e39 100644 (file)
@@ -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")));
@@ -330,7 +338,7 @@ static void create_fake_stash_reference_and_reflog(git_repository *repo)
 
        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);
 }
 
@@ -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");
+}