diff options
author | Edward Thomson <ethomson@microsoft.com> | 2014-10-14 16:31:55 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2014-10-22 17:49:53 -0400 |
commit | 12f32d919390f47124bed41d6c54d75b666e1e5e (patch) | |
tree | 117f850eca530b39e8eecd3171a9ea4e0f827679 /tests/clone | |
parent | 89244e7ff9755657b96d733b6936cecbd4e2ef0c (diff) | |
download | libgit2-12f32d919390f47124bed41d6c54d75b666e1e5e.tar.gz |
Remote paths: canonicalize UNC paths on Win32
Git for Windows will handle UNC paths only when in forward-slash
format, eg "//server/path". When given a UNC path as a remote,
rewrite standard format ("\\server\path") into this ridiculous
format.
Diffstat (limited to 'tests/clone')
-rw-r--r-- | tests/clone/local.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/clone/local.c b/tests/clone/local.c index 78d026794..fec3be519 100644 --- a/tests/clone/local.c +++ b/tests/clone/local.c @@ -16,6 +16,40 @@ static int file_url(git_buf *buf, const char *host, const char *path) return git_buf_printf(buf, "file://%s/%s", host, path); } +static int git_style_unc_path(git_buf *buf, const char *host, const char *path) +{ + git_buf_clear(buf); + + if (host) + git_buf_printf(buf, "//%s/", host); + + if (path[0] == '/') + path++; + + if (isalpha(path[0]) && path[1] == ':' && path[2] == '/') { + git_buf_printf(buf, "%c$/", path[0]); + path += 3; + } + + git_buf_puts(buf, path); + + return git_buf_oom(buf) ? -1 : 0; +} + +static int unc_path(git_buf *buf, const char *host, const char *path) +{ + char *c; + + if (git_style_unc_path(buf, host, path) < 0) + return -1; + + for (c = buf->ptr; *c; c++) + if (*c == '/') + *c = '\\'; + + return 0; +} + void test_clone_local__should_clone_local(void) { git_buf buf = GIT_BUF_INIT; @@ -121,3 +155,57 @@ void test_clone_local__hardlinks(void) cl_git_pass(git_futils_rmdir_r("./clone3.git", NULL, GIT_RMDIR_REMOVE_FILES)); cl_git_pass(git_futils_rmdir_r("./clone4.git", NULL, GIT_RMDIR_REMOVE_FILES)); } + +void test_clone_local__standard_unc_paths_are_written_git_style(void) +{ +#ifdef GIT_WIN32 + git_repository *repo; + git_remote *remote; + git_clone_options opts = GIT_CLONE_OPTIONS_INIT; + git_buf unc = GIT_BUF_INIT, git_unc = GIT_BUF_INIT; + + /* we use a fixture path because it needs to exist for us to want to clone */ + const char *path = cl_fixture("testrepo.git"); + + cl_git_pass(unc_path(&unc, "localhost", path)); + cl_git_pass(git_style_unc_path(&git_unc, "localhost", path)); + + cl_git_pass(git_clone(&repo, unc.ptr, "./clone.git", &opts)); + cl_git_pass(git_remote_load(&remote, repo, "origin")); + + cl_assert_equal_s(git_unc.ptr, git_remote_url(remote)); + + git_remote_free(remote); + git_repository_free(repo); + git_buf_free(&unc); + git_buf_free(&git_unc); + + cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES)); +#endif +} + +void test_clone_local__git_style_unc_paths(void) +{ +#ifdef GIT_WIN32 + git_repository *repo; + git_remote *remote; + git_clone_options opts = GIT_CLONE_OPTIONS_INIT; + git_buf git_unc = GIT_BUF_INIT; + + /* we use a fixture path because it needs to exist for us to want to clone */ + const char *path = cl_fixture("testrepo.git"); + + cl_git_pass(git_style_unc_path(&git_unc, "localhost", path)); + + cl_git_pass(git_clone(&repo, git_unc.ptr, "./clone.git", &opts)); + cl_git_pass(git_remote_load(&remote, repo, "origin")); + + cl_assert_equal_s(git_unc.ptr, git_remote_url(remote)); + + git_remote_free(remote); + git_repository_free(repo); + git_buf_free(&git_unc); + + cl_git_pass(git_futils_rmdir_r("./clone.git", NULL, GIT_RMDIR_REMOVE_FILES)); +#endif +} |