Commit Diff


commit - 29c68398c5b5c7fc7ff5534ed3921b6faa9912a9
commit + 2751fe645d77dcd3e68167c7d2c26bb9146996d2
blob - 6d084dbeab1fa1eadc21ffbd54e530f79199acb5
blob + 16044da028a60088852c19c49c0f5e341d3658b2
--- got/got.c
+++ 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;