From d728cb610bfa36c81a38a50fd32ae66d29b6c271 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Sat, 1 Jan 2022 14:50:15 +0100 Subject: [PATCH 1/2] ci: add url-like path to online clone tests --- tests/libgit2/online/clone.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c index 7a8f5ead780..207dd839172 100644 --- a/tests/libgit2/online/clone.c +++ b/tests/libgit2/online/clone.c @@ -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); From 26b08d4c6d524d21ba95b0d08650c7b4c2aeb576 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Thu, 12 Aug 2021 13:46:03 +0200 Subject: [PATCH 2/2] clone: don't test remote url against filesystem --- src/libgit2/clone.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/libgit2/clone.c b/src/libgit2/clone.c index 27bae1ac499..3df28f80aed 100644 --- a/src/libgit2/clone.c +++ b/src/libgit2/clone.c @@ -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 @@ static int clone_into( 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; }