summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-04-17 13:43:52 +0100
committerGitHub <noreply@github.com>2019-04-17 13:43:52 +0100
commitb3923cf7199a93dadcb31e727eeca5b3c6e16361 (patch)
treed62e16380fdec282af326408a48ab3a931518558
parent9c40260043e8f146642ae54fc0e6bae2a76f9f79 (diff)
parent45f24e787adc4fc805f65257ee2b2efb70c95d08 (diff)
downloadlibgit2-b3923cf7199a93dadcb31e727eeca5b3c6e16361.tar.gz
Merge pull request #5050 from libgit2/ethomson/windows_init_traversal
git_repository_init: stop traversing at windows root
-rw-r--r--src/fileops.c9
-rw-r--r--tests/repo/init.c12
2 files changed, 18 insertions, 3 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 61906ed7f..a4d5cc67c 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -489,10 +489,13 @@ int git_futils_mkdir(
assert(len);
- /* we've walked all the given path's parents and it's either relative
- * or rooted. either way, give up and make the entire path.
+ /*
+ * We've walked all the given path's parents and it's either relative
+ * (the parent is simply '.') or rooted (the length is less than or
+ * equal to length of the root path). The path may be less than the
+ * root path length on Windows, where `C:` == `C:/`.
*/
- if ((len == 1 && parent_path.ptr[0] == '.') || len == root_len+1) {
+ if ((len == 1 && parent_path.ptr[0] == '.') || len <= root_len) {
relative = make_path.ptr;
break;
}
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 91b25a5f1..6e6e65297 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -877,3 +877,15 @@ void test_repo_init__at_filesystem_root(void)
git_buf_dispose(&root);
git_repository_free(repo);
}
+
+void test_repo_init__nonexistent_paths(void)
+{
+ git_repository *repo;
+
+#ifdef GIT_WIN32
+ cl_git_fail(git_repository_init(&repo, "Q:/non/existent/path", 0));
+ cl_git_fail(git_repository_init(&repo, "Q:\\non\\existent\\path", 0));
+#else
+ cl_git_fail(git_repository_init(&repo, "/non/existent/path", 0));
+#endif
+}