Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c4a602e

Browse files
committed
clone: don't test remote url against filesystem
1 parent edf41ba commit c4a602e

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/libgit2/clone.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "fs_path.h"
2323
#include "repository.h"
2424
#include "odb.h"
25+
#include "net.h"
2526

2627
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);
2728

@@ -336,8 +337,9 @@ static int create_and_configure_origin(
336337
git_remote_create_cb remote_create = options->remote_cb;
337338
void *payload = options->remote_cb_payload;
338339

339-
/* If the path exists and is a dir, the url should be the absolute path */
340-
if (git_fs_path_root(url) < 0 && git_fs_path_exists(url) && git_fs_path_isdir(url)) {
340+
/* If the path is local and exists it should be the absolute path. */
341+
if (!git_net_str_is_url(url) && git_fs_path_root(url) < 0 &&
342+
git_fs_path_exists(url)) {
341343
if (p_realpath(url, buf) == NULL)
342344
return -1;
343345

@@ -458,26 +460,25 @@ static int clone_into(
458460
int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t local)
459461
{
460462
git_str fromurl = GIT_STR_INIT;
461-
const char *path = url_or_path;
462-
bool is_url, is_local;
463+
bool is_local;
463464

464465
if (local == GIT_CLONE_NO_LOCAL)
465466
return 0;
466467

467-
if ((is_url = git_fs_path_is_local_file_url(url_or_path)) != 0) {
468-
if (git_fs_path_fromurl(&fromurl, url_or_path) < 0) {
469-
is_local = -1;
470-
goto done;
471-
}
468+
if (git_net_str_is_url(url_or_path)) {
469+
/* If GIT_CLONE_LOCAL_AUTO is specified, any url should be treated as remote */
470+
if (local == GIT_CLONE_LOCAL_AUTO ||
471+
!git_fs_path_is_local_file_url(url_or_path))
472+
return 0;
472473

473-
path = fromurl.ptr;
474+
if (git_fs_path_fromurl(&fromurl, url_or_path) == 0)
475+
is_local = git_fs_path_isdir(git_str_cstr(&fromurl));
476+
else
477+
is_local = -1;
478+
git_str_dispose(&fromurl);
479+
} else {
480+
is_local = git_fs_path_isdir(url_or_path);
474481
}
475-
476-
is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) &&
477-
git_fs_path_isdir(path);
478-
479-
done:
480-
git_str_dispose(&fromurl);
481482
return is_local;
482483
}
483484

0 commit comments

Comments
 (0)