diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2014-07-08 15:45:50 -0400 |
|---|---|---|
| committer | Edward Thomson <ethomson@microsoft.com> | 2014-07-11 18:46:00 -0400 |
| commit | 529fd30d1f81cc711ce3ca3857d637e84a1ca6e4 (patch) | |
| tree | 237ac8450787374eb3bbf7f202ad1ebb4dcaa588 /src/clone.c | |
| parent | 356b891e3ec53ed937db38b6827c6045fc1beff4 (diff) | |
| download | libgit2-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 'src/clone.c')
| -rw-r--r-- | src/clone.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/clone.c b/src/clone.c index 8f0284ae6..c7a708da7 100644 --- a/src/clone.c +++ b/src/clone.c @@ -371,27 +371,30 @@ cleanup: return error; } -int git_clone__should_clone_local(const char *url, git_clone_local_t local) +int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local) { - const char *path; - int is_url; + git_buf fromurl = GIT_BUF_INIT; + const char *path = url_or_path; + bool is_url, is_local; if (local == GIT_CLONE_NO_LOCAL) - return false; - - is_url = !git__prefixcmp(url, "file://"); + return 0; - if (is_url && local != GIT_CLONE_LOCAL && local != GIT_CLONE_LOCAL_NO_LINKS ) - return false; + if (is_url = git_path_is_local_file_url(url_or_path)) { + if (git_path_fromurl(&fromurl, url_or_path) < 0) { + is_local = -1; + goto done; + } - path = url; - if (is_url) - path = url + strlen("file://"); + path = fromurl.ptr; + } - if ((git_path_exists(path) && git_path_isdir(path)) && local != GIT_CLONE_NO_LOCAL) - return true; + is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) && + git_path_isdir(path); - return false; +done: + git_buf_free(&fromurl); + return is_local; } int git_clone( @@ -434,16 +437,19 @@ int git_clone( return error; if (!(error = create_and_configure_origin(&origin, repo, url, &options))) { - if (git_clone__should_clone_local(url, options.local)) { - int link = options.local != GIT_CLONE_LOCAL_NO_LINKS; + int should_clone = git_clone__should_clone_local(url, options.local); + int link = options.local != GIT_CLONE_LOCAL_NO_LINKS; + + if (should_clone == 1) error = clone_local_into( repo, origin, &options.checkout_opts, options.checkout_branch, link, options.signature); - } else { + else if (should_clone == 0) error = clone_into( repo, origin, &options.checkout_opts, options.checkout_branch, options.signature); - } + else + error = -1; git_remote_free(origin); } |
