mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 20:29:27 +00:00
repository: make git_repository_set_workdir() prettify the path it is being passed
This commit is contained in:
parent
dcfdb958e2
commit
b78fb64d2f
@ -871,13 +871,16 @@ const char *git_repository_workdir(git_repository *repo)
|
|||||||
|
|
||||||
int git_repository_set_workdir(git_repository *repo, const char *workdir)
|
int git_repository_set_workdir(git_repository *repo, const char *workdir)
|
||||||
{
|
{
|
||||||
|
git_buf path = GIT_BUF_INIT;
|
||||||
|
|
||||||
assert(repo && workdir);
|
assert(repo && workdir);
|
||||||
|
|
||||||
|
if (git_path_prettify_dir(&path, workdir, NULL) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
free(repo->workdir);
|
free(repo->workdir);
|
||||||
|
|
||||||
repo->workdir = git__strdup(workdir);
|
repo->workdir = git_buf_detach(&path);
|
||||||
GITERR_CHECK_ALLOC(repo->workdir);
|
|
||||||
|
|
||||||
repo->is_bare = 0;
|
repo->is_bare = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
34
tests-clar/repo/setters.c
Normal file
34
tests-clar/repo/setters.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "clar_libgit2.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
static git_repository *repo;
|
||||||
|
|
||||||
|
void test_repo_setters__initialize(void)
|
||||||
|
{
|
||||||
|
cl_fixture_sandbox("testrepo.git");
|
||||||
|
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_repo_setters__cleanup(void)
|
||||||
|
{
|
||||||
|
git_repository_free(repo);
|
||||||
|
cl_fixture_cleanup("testrepo.git");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standard_one(void)
|
||||||
|
{
|
||||||
|
cl_assert(git_repository_is_bare(repo) == 1);
|
||||||
|
|
||||||
|
cl_assert(git_repository_workdir(repo) == NULL);
|
||||||
|
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir"));
|
||||||
|
|
||||||
|
cl_assert(git_repository_workdir(repo) != NULL);
|
||||||
|
cl_assert(git_repository_is_bare(repo) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
|
||||||
|
{
|
||||||
|
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir"));
|
||||||
|
|
||||||
|
cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user