Unverified Commit 2d744e9c by Edward Thomson Committed by GitHub

Merge pull request #6361 from boretrk/localclone3

clone: don't mix up "http://url" with "http:/url" when figuring out if we should do a local clone
parents 03a582b1 26b08d4c
......@@ -22,6 +22,7 @@
#include "fs_path.h"
#include "repository.h"
#include "odb.h"
#include "net.h"
static int clone_local_into(git_repository *repo, git_remote *remote, const git_fetch_options *fetch_opts, const git_checkout_options *co_opts, const char *branch, int link);
......@@ -336,8 +337,9 @@ static int create_and_configure_origin(
git_remote_create_cb remote_create = options->remote_cb;
void *payload = options->remote_cb_payload;
/* If the path exists and is a dir, the url should be the absolute path */
if (git_fs_path_root(url) < 0 && git_fs_path_exists(url) && git_fs_path_isdir(url)) {
/* If the path is local and exists it should be the absolute path. */
if (!git_net_str_is_url(url) && git_fs_path_root(url) < 0 &&
git_fs_path_exists(url)) {
if (p_realpath(url, buf) == NULL)
return -1;
......@@ -458,26 +460,25 @@ cleanup:
int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local)
{
git_str fromurl = GIT_STR_INIT;
const char *path = url_or_path;
bool is_url, is_local;
bool is_local;
if (local == GIT_CLONE_NO_LOCAL)
return 0;
if ((is_url = git_fs_path_is_local_file_url(url_or_path)) != 0) {
if (git_fs_path_fromurl(&fromurl, url_or_path) < 0) {
is_local = -1;
goto done;
}
if (git_net_str_is_url(url_or_path)) {
/* If GIT_CLONE_LOCAL_AUTO is specified, any url should be treated as remote */
if (local == GIT_CLONE_LOCAL_AUTO ||
!git_fs_path_is_local_file_url(url_or_path))
return 0;
path = fromurl.ptr;
if (git_fs_path_fromurl(&fromurl, url_or_path) == 0)
is_local = git_fs_path_isdir(git_str_cstr(&fromurl));
else
is_local = -1;
git_str_dispose(&fromurl);
} else {
is_local = git_fs_path_isdir(url_or_path);
}
is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) &&
git_fs_path_isdir(path);
done:
git_str_dispose(&fromurl);
return is_local;
}
......
......@@ -7,6 +7,7 @@
#include "refs.h"
#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
#define LIVE_REPO_AS_DIR "http:/github.com/libgit2/TestGitRepository"
#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
#define BB_REPO_URL "https://libgit2-test@bitbucket.org/libgit2-test/testgitrepository.git"
#define BB_REPO_URL_WITH_PASS "https://libgit2-test:YT77Ppm2nq8w4TYjGS8U@bitbucket.org/libgit2-test/testgitrepository.git"
......@@ -115,6 +116,16 @@ void test_online_clone__initialize(void)
if (_remote_expectcontinue)
git_libgit2_opts(GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, 1);
#if !defined(GIT_WIN32)
/*
* On system that allows ':' in filenames "http://path" can be misinterpreted
* as the local path "http:/path".
* Create a local non-repository path that looks like LIVE_REPO_URL to make
* sure we can handle cloning despite this directory being around.
*/
git_futils_mkdir_r(LIVE_REPO_AS_DIR, 0777);
#endif
}
void test_online_clone__cleanup(void)
......@@ -127,6 +138,10 @@ void test_online_clone__cleanup(void)
cl_fixture_cleanup("./initial");
cl_fixture_cleanup("./subsequent");
#if !defined(GIT_WIN32)
cl_fixture_cleanup("http:");
#endif
git__free(_remote_url);
git__free(_remote_user);
git__free(_remote_pass);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment