summaryrefslogtreecommitdiff
path: root/tests/clone
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-07-08 15:45:50 -0400
committerEdward Thomson <ethomson@microsoft.com>2014-07-11 18:46:00 -0400
commit529fd30d1f81cc711ce3ca3857d637e84a1ca6e4 (patch)
tree237ac8450787374eb3bbf7f202ad1ebb4dcaa588 /tests/clone
parent356b891e3ec53ed937db38b6827c6045fc1beff4 (diff)
downloadlibgit2-529fd30d1f81cc711ce3ca3857d637e84a1ca6e4.tar.gz
Handle local file:/// paths on Windows
Windows can't handle a path like `/c:/foo`; when turning file:/// URIs into local paths, we must strip the leading slash.
Diffstat (limited to 'tests/clone')
-rw-r--r--tests/clone/local.c56
1 files changed, 43 insertions, 13 deletions
diff --git a/tests/clone/local.c b/tests/clone/local.c
index c8ebc143d..78d026794 100644
--- a/tests/clone/local.c
+++ b/tests/clone/local.c
@@ -7,25 +7,55 @@
#include "posix.h"
#include "fileops.h"
+static int file_url(git_buf *buf, const char *host, const char *path)
+{
+ if (path[0] == '/')
+ path++;
+
+ git_buf_clear(buf);
+ return git_buf_printf(buf, "file://%s/%s", host, path);
+}
+
void test_clone_local__should_clone_local(void)
{
git_buf buf = GIT_BUF_INIT;
- const char *path;
/* we use a fixture path because it needs to exist for us to want to clone */
-
- cl_git_pass(git_buf_printf(&buf, "file://%s", cl_fixture("testrepo.git")));
- cl_assert_equal_i(false, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO));
- cl_assert_equal_i(true, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL));
- cl_assert_equal_i(true, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS));
- cl_assert_equal_i(false, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL));
- git_buf_free(&buf);
+ const char *path = cl_fixture("testrepo.git");
+
+ cl_git_pass(file_url(&buf, "", path));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO));
+ cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL));
+ cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL));
+
+ cl_git_pass(file_url(&buf, "localhost", path));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO));
+ cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL));
+ cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL));
+
+ cl_git_pass(file_url(&buf, "other-host.mycompany.com", path));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL));
+
+ /* Ensure that file:/// urls are percent decoded: .git == %2e%67%69%74 */
+ cl_git_pass(file_url(&buf, "", path));
+ git_buf_shorten(&buf, 4);
+ cl_git_pass(git_buf_puts(&buf, "%2e%67%69%74"));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_AUTO));
+ cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL));
+ cl_assert_equal_i(1, git_clone__should_clone_local(buf.ptr, GIT_CLONE_LOCAL_NO_LINKS));
+ cl_assert_equal_i(0, git_clone__should_clone_local(buf.ptr, GIT_CLONE_NO_LOCAL));
+
+ cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_AUTO));
+ cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL));
+ cl_assert_equal_i(1, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_NO_LINKS));
+ cl_assert_equal_i(0, git_clone__should_clone_local(path, GIT_CLONE_NO_LOCAL));
- path = cl_fixture("testrepo.git");
- cl_assert_equal_i(true, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_AUTO));
- cl_assert_equal_i(true, git_clone__should_clone_local(path, GIT_CLONE_LOCAL));
- cl_assert_equal_i(true, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_NO_LINKS));
- cl_assert_equal_i(false, git_clone__should_clone_local(path, GIT_CLONE_NO_LOCAL));
+ git_buf_free(&buf);
}
void test_clone_local__hardlinks(void)