let 'got clone' try to connect to server before creating repository contents
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/got/got.c b/got/got.c
index 6d084db..16044da 100644
--- a/got/got.c
+++ b/got/got.c
@@ -1193,15 +1193,15 @@ cmd_clone(int argc, char *argv[])
if (!list_refs_only) {
error = got_path_mkdir(repo_path);
- if (error)
- goto done;
-
- error = got_repo_init(repo_path);
- if (error)
+ if (error &&
+ (!(error->code == GOT_ERR_ERRNO && errno == EISDIR) &&
+ !(error->code == GOT_ERR_ERRNO && errno == EEXIST)))
goto done;
- error = got_repo_open(&repo, repo_path, NULL);
- if (error)
+ if (!got_path_dir_is_empty(repo_path)) {
+ error = got_error_path(repo_path,
+ GOT_ERR_DIR_NOT_EMPTY);
goto done;
+ }
}
if (strcmp(proto, "git+ssh") == 0 || strcmp(proto, "ssh") == 0) {
@@ -1224,6 +1224,15 @@ cmd_clone(int argc, char *argv[])
if (error)
goto done;
+ if (!list_refs_only) {
+ error = got_repo_init(repo_path);
+ if (error)
+ goto done;
+ error = got_repo_open(&repo, repo_path, NULL);
+ if (error)
+ goto done;
+ }
+
fpa.last_scaled_size[0] = '\0';
fpa.last_p_indexed = -1;
fpa.last_p_resolved = -1;