Commit Diff


commit - 12d1281eafdb8a13bde8c4b335c0e102f8505e13
commit + 4aa547dbcb2bafca9102632f6594b7854a57c643
blob - 71c7b6e0954d32e70d5aa2bdd54edf1765ec5cc6
blob + 9981ae675edf4e6cc520b4ec823cc315ab048828
--- got/got.c
+++ got/got.c
@@ -1010,6 +1010,32 @@ cmd_clone(int argc, char *argv[])
 
 	if (verbosity >= 0)
 		printf("Connected to %s:%s\n", host, port);
+
+	/* Create a config file git-fetch(1) can understand. */
+	gitconfig_path = got_repo_get_path_gitconfig(repo);
+	if (gitconfig_path == NULL) {
+		error = got_error_from_errno("got_repo_get_path_gitconfig");
+		goto done;
+	}
+	gitconfig_file = fopen(gitconfig_path, "a");
+	if (gitconfig_file == NULL) {
+		error = got_error_from_errno2("fopen", gitconfig_path);
+		goto done;
+	}
+	if (asprintf(&gitconfig,
+	    "[remote \"%s\"]\n"
+	    "\turl = %s\n"
+	    "\tfetch = +refs/heads/*:refs/remotes/%s/*\n",
+	    GOT_FETCH_DEFAULT_REMOTE_NAME, git_url,
+	    GOT_FETCH_DEFAULT_REMOTE_NAME) == -1) {
+		error = got_error_from_errno("asprintf");
+		goto done;
+	}
+	n = fwrite(gitconfig, 1, strlen(gitconfig), gitconfig_file);
+	if (n != strlen(gitconfig)) {
+		error = got_ferror(gitconfig_file, GOT_ERR_IO);
+		goto done;
+	}
 
 	fpa.last_scaled_size[0] = '\0';
 	fpa.last_p_indexed = -1;
@@ -1089,33 +1115,7 @@ cmd_clone(int argc, char *argv[])
 		error = got_ref_write(symref, repo);
 		got_ref_close(symref);
 		break;
-	}
-
-	/* Create a config file so Git can understand this repository. */
-	gitconfig_path = got_repo_get_path_gitconfig(repo);
-	if (gitconfig_path == NULL) {
-		error = got_error_from_errno("got_repo_get_path_gitconfig");
-		goto done;
-	}
-	gitconfig_file = fopen(gitconfig_path, "a");
-	if (gitconfig_file == NULL) {
-		error = got_error_from_errno2("fopen", gitconfig_path);
-		goto done;
-	}
-	if (asprintf(&gitconfig,
-	    "[remote \"%s\"]\n"
-	    "\turl = %s\n"
-	    "\tfetch = +refs/heads/*:refs/remotes/%s/*\n",
-	    GOT_FETCH_DEFAULT_REMOTE_NAME, git_url,
-	    GOT_FETCH_DEFAULT_REMOTE_NAME) == -1) {
-		error = got_error_from_errno("asprintf");
-		goto done;
 	}
-	n = fwrite(gitconfig, 1, strlen(gitconfig), gitconfig_file);
-	if (n != strlen(gitconfig)) {
-		error = got_ferror(gitconfig_file, GOT_ERR_IO);
-		goto done;
-	}
 
 	if (verbosity >= 0)
 		printf("Created cloned repository '%s'\n", repo_path);