Skip to content

Commit b3923cf

Browse files
authored
Merge pull request libgit2#5050 from libgit2/ethomson/windows_init_traversal
git_repository_init: stop traversing at windows root
2 parents 9c40260 + 45f24e7 commit b3923cf

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/fileops.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,13 @@ int git_futils_mkdir(
489489

490490
assert(len);
491491

492-
/* we've walked all the given path's parents and it's either relative
493-
* or rooted. either way, give up and make the entire path.
492+
/*
493+
* We've walked all the given path's parents and it's either relative
494+
* (the parent is simply '.') or rooted (the length is less than or
495+
* equal to length of the root path). The path may be less than the
496+
* root path length on Windows, where `C:` == `C:/`.
494497
*/
495-
if ((len == 1 && parent_path.ptr[0] == '.') || len == root_len+1) {
498+
if ((len == 1 && parent_path.ptr[0] == '.') || len <= root_len) {
496499
relative = make_path.ptr;
497500
break;
498501
}

tests/repo/init.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,15 @@ void test_repo_init__at_filesystem_root(void)
877877
git_buf_dispose(&root);
878878
git_repository_free(repo);
879879
}
880+
881+
void test_repo_init__nonexistent_paths(void)
882+
{
883+
git_repository *repo;
884+
885+
#ifdef GIT_WIN32
886+
cl_git_fail(git_repository_init(&repo, "Q:/non/existent/path", 0));
887+
cl_git_fail(git_repository_init(&repo, "Q:\\non\\existent\\path", 0));
888+
#else
889+
cl_git_fail(git_repository_init(&repo, "/non/existent/path", 0));
890+
#endif
891+
}

0 commit comments

Comments
 (0)