create git config file earlier such that interrupted clones can be re-fetched
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/got/got.c b/got/got.c
index 71c7b6e..9981ae6 100644
--- a/got/got.c
+++ b/got/got.c
@@ -1011,6 +1011,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;
fpa.last_p_resolved = -1;
@@ -1091,32 +1117,6 @@ cmd_clone(int argc, char *argv[])
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);
done: