8000 repo: ensure we can initialize win32 paths · libgit2/libgit2@90c7bce · GitHub
[go: up one dir, main page]

Skip to content

Commit 90c7bce

Browse files
committed
repo: ensure we can initialize win32 paths
Given a win32 path, ensure that we can initialize it. This involves a posix-style path conversion at the beginning of our initialization.
1 parent b49b8db commit 90c7bce

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/libgit2/repository.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,8 @@ static int repo_init_directories(
26302630
if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
26312631
return -1;
26322632

2633+
git_fs_path_mkposix(repo_path->ptr);
2634+
26332635
has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
26342636
if (has_dotgit)
26352637
opts->flags |= GIT_REPOSITORY_INIT__HAS_DOTGIT;

tests/libgit2/repo/init.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,3 +755,27 @@ void test_repo_init__longpath(void)
755755
git_str_dispose(&path);
756756
#endif
757757
}
758+
759+
void test_repo_init__absolute_path_with_backslashes(void)
760+
{
761+
#ifdef GIT_WIN32
762+
git_repository_init_options initopts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
763+
git_str path = GIT_STR_INIT;
764+
char *c;
765+
766+
cl_set_cleanup(&cleanup_repository, "path");
767+
768+
cl_git_pass(git_str_joinpath(&path, clar_sandbox_path(), "path/to/newrepo"));
769+
770+
for (c = path.ptr; *c; c++) {
771+
if (*c == '/')
772+
*c = '\\';
773+
}
774+
775+
initopts.flags |= GIT_REPOSITORY_INIT_MKDIR | GIT_REPOSITORY_INIT_MKPATH;
776+
777+
cl_git_pass(git_repository_init_ext(&g_repo, path.ptr, &initopts));
778+
#else
779+
clar__skip();
780+
#endif
781+
}

0 commit comments

Comments
 (0)
0