summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-02-03 12:45:43 +0100
committernulltoken <emeric.fermas@gmail.com>2012-02-03 12:46:50 +0100
commit99abb79d53781dda9bbdc7b896eaa383d8789cb3 (patch)
treef9ba87532e6c97eb21b5bf264d2e222238a69d9c /tests-clar
parent0a4aebb097bbe7a940c0f73174b756027105d92f (diff)
downloadlibgit2-99abb79d53781dda9bbdc7b896eaa383d8789cb3.tar.gz
repository: ensure that the path to the .git directory ends with a forward slash when opening a repository through a working directory path
This fixes an issue which was detected while using one of the libgit2 bindings [0]. The lack of the trailing forward slash led the name of references returned by git_reference_listall() to be prefixed with a forward slash. [0]: https://github.com/libgit2/libgit2sharp/pull/108
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/refs/listall.c36
-rw-r--r--tests-clar/repo/open.c36
2 files changed, 65 insertions, 7 deletions
diff --git a/tests-clar/refs/listall.c b/tests-clar/refs/listall.c
new file mode 100644
index 000000000..4aa7051c8
--- /dev/null
+++ b/tests-clar/refs/listall.c
@@ -0,0 +1,36 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+
+static git_repository *repo;
+static git_strarray ref_list;
+
+static void ensure_no_refname_starts_with_a_forward_slash(const char *path)
+{
+ int i;
+
+ cl_git_pass(git_repository_open(&repo, path));
+ cl_git_pass(git_reference_listall(&ref_list, repo, GIT_REF_LISTALL));
+
+ cl_assert(ref_list.count > 0);
+
+ for (i = 0; i < ref_list.count; i++)
+ cl_assert(git__prefixcmp(ref_list.strings[i], "/") != 0);
+
+ git_strarray_free(&ref_list);
+ git_repository_free(repo);
+}
+
+void test_refs_listall__from_repository_opened_through_workdir_path(void)
+{
+ cl_fixture_sandbox("status");
+ cl_git_pass(p_rename("status/.gitted", "status/.git"));
+
+ ensure_no_refname_starts_with_a_forward_slash("status");
+
+ cl_fixture_cleanup("status");
+}
+
+void test_refs_listall__from_repository_opened_through_gitdir_path(void)
+{
+ ensure_no_refname_starts_with_a_forward_slash(cl_fixture("testrepo.git"));
+}
diff --git a/tests-clar/repo/open.c b/tests-clar/repo/open.c
index b5002843c..c3a7dadbd 100644
--- a/tests-clar/repo/open.c
+++ b/tests-clar/repo/open.c
@@ -1,24 +1,46 @@
#include "clar_libgit2.h"
#include "posix.h"
-void test_repo_open__bare_empty_repo(void)
+static git_repository *repo;
+
+void test_repo_open__cleanup(void)
{
- git_repository *repo;
+ git_repository_free(repo);
+}
+void test_repo_open__bare_empty_repo(void)
+{
cl_git_pass(git_repository_open(&repo, cl_fixture("empty_bare.git")));
+
cl_assert(git_repository_path(repo) != NULL);
+ cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0);
+
cl_assert(git_repository_workdir(repo) == NULL);
+}
- git_repository_free(repo);
+void test_repo_open__standard_empty_repo_through_gitdir(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("empty_standard_repo/.gitted")));
+
+ cl_assert(git_repository_path(repo) != NULL);
+ cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0);
+
+ cl_assert(git_repository_workdir(repo) != NULL);
+ cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0);
}
-void test_repo_open__standard_empty_repo(void)
+void test_repo_open__standard_empty_repo_through_workdir(void)
{
- git_repository *repo;
+ cl_fixture_sandbox("empty_standard_repo");
+ cl_git_pass(p_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
+
+ cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
- cl_git_pass(git_repository_open(&repo, cl_fixture("empty_standard_repo/.gitted")));
cl_assert(git_repository_path(repo) != NULL);
+ cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0);
+
cl_assert(git_repository_workdir(repo) != NULL);
+ cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0);
- git_repository_free(repo);
+ cl_fixture_cleanup("empty_standard_repo");
}