summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-04-12 08:54:06 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2019-04-17 10:42:09 +0100
commit45f24e787adc4fc805f65257ee2b2efb70c95d08 (patch)
tree123329968407aa8ed9b84b3a07b7f13f2729d901 /tests
parentd1cfd79a477a440c5f0929c34e817da202227ec7 (diff)
downloadlibgit2-ethomson/windows_init_traversal.tar.gz
git_repository_init: stop traversing at windows rootethomson/windows_init_traversal
Stop traversing the filesystem at the Windows directory root. We were calculating the filesystem root for the given directory to create, and walking up the filesystem hierarchy. We intended to stop when the traversal path length is equal to the root path length (ie, stopping at the root, since no path may be shorter than the root path). However, on Windows, the root path may be specified in two different ways, as either `Z:` or `Z:\`, where `Z:` is the current drive letter. `git_path_dirname_r` returns the path _without_ a trailing slash, even for the Windows root. As a result, during traversal, we need to test that the traversal path is _less than or equal to_ the root path length to determine if we've hit the root to ensure that we stop when our traversal path is `Z:` and our calculated root path was `Z:\`.
Diffstat (limited to 'tests')
-rw-r--r--tests/repo/init.c12
1 files changed, 12 insertions, 0 deletions
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
+}