commit 22b6b4901ad36a6f5cfe1dc2355449d23bbd4816 from: Stefan Sperling date: Wed Mar 18 16:10:31 2020 UTC add a .git suffix to cloned repositories by default commit - a251e40e110f1b745d1be771f304a7e31e2167ba commit + 22b6b4901ad36a6f5cfe1dc2355449d23bbd4816 blob - 0a308b0ba10453c978f0b5ed3d1f34c2f1234f14 blob + 7c5ea03802b44902eb819f4ae290a12547b6ee54 --- lib/fetch.c +++ lib/fetch.c @@ -248,7 +248,7 @@ got_parse_uri(char *uri, char *proto, char *host, char } const struct got_error* -got_clone(char *uri, char *branch_filter, char *dirname) +got_clone(char *uri, char *branch_filter, char *destdir) { char proto[GOT_PROTOMAX], host[GOT_HOSTMAX], port[GOT_PORTMAX]; char repo[GOT_REPOMAX], path[GOT_PATHMAX]; @@ -258,17 +258,19 @@ got_clone(char *uri, char *branch_filter, char *dirnam const struct got_error *err; struct imsgbuf ibuf; pid_t pid; - char *packpath = NULL, *idxpath = NULL; + char *packpath = NULL, *idxpath = NULL, *default_destdir = NULL; fetchfd = -1; if (got_parse_uri(uri, proto, host, port, path, repo) == -1) return got_error(GOT_ERR_PARSE_URI); - if (dirname == NULL) - dirname = repo; - err = got_repo_init(dirname); + if (destdir == NULL) { + if (asprintf(&default_destdir, "%s.git", repo) == -1) + return got_error_from_errno("asprintf"); + } + err = got_repo_init(destdir ? destdir : default_destdir); if (err != NULL) return err; - if (chdir(dirname)) + if (chdir(destdir ? destdir : default_destdir)) return got_error_from_errno("enter new repo"); if (mkpath(".git/objects/pack") == -1) return got_error_from_errno("mkpath"); @@ -355,6 +357,7 @@ got_clone(char *uri, char *branch_filter, char *dirnam free(packpath); free(idxpath); + free(default_destdir); return NULL;