Commit 1f0c1984 by Vicent Martí

Merge pull request #549 from nulltoken/fix/open-repo-with-workdir-path

Fix trailing slash issue to the gitdir path when the repo is opened through a workdir
parents 0a4aebb0 99abb79d
......@@ -166,7 +166,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
* of the working dir, by testing if it contains a `.git`
* folder inside of it.
*/
git_path_contains_dir(&path_buf, DOT_GIT, 1); /* append on success */
git_path_contains_dir(&path_buf, GIT_DIR, 1); /* append on success */
/* ignore error, since it just means `path/.git` doesn't exist */
if (quickcheck_repository_dir(&path_buf) < GIT_SUCCESS) {
......
#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"));
}
#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");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment