commit - ee448f5f104f873da32b5aa9139702b0377ebf3f
commit + b46f3e7182c65f46c60e1b9db7c90dc213f52584
blob - 294153fb62870c454e30ddbf7055af7975cc7ae0
blob + 7b17cf38ea32edfa0ba03d521ba4c6ae1edc89c0
--- got/got.c
+++ got/got.c
struct got_object_id *pack_hash = NULL;
int ch, fetchfd = -1;
struct got_fetch_progress_arg fpa;
+ char *git_url = NULL;
+ char *gitconfig_path = NULL;
+ char *gitconfig = NULL;
+ FILE *gitconfig_file = NULL;
+ ssize_t n;
TAILQ_INIT(&refs);
TAILQ_INIT(&symrefs);
if (error)
goto done;
-#ifndef PROFILE
if (strcmp(proto, "git") == 0) {
+#ifndef PROFILE
if (pledge("stdio rpath wpath cpath fattr flock proc exec "
"sendfd dns inet unveil", NULL) == -1)
err(1, "pledge");
+#endif
+ git_url = strdup(argv[0]);
+ if (git_url == NULL) {
+ error = got_error_from_errno("strdup");
+ goto done;
+ }
} else if (strcmp(proto, "git+ssh") == 0 ||
strcmp(proto, "ssh") == 0) {
+#ifndef PROFILE
if (pledge("stdio rpath wpath cpath fattr flock proc exec "
"sendfd unveil", NULL) == -1)
err(1, "pledge");
+#endif
+ if (asprintf(&git_url, "%s:%s", host, server_path) == -1) {
+ error = got_error_from_errno("asprintf");
+ goto done;
+ }
} else if (strcmp(proto, "http") == 0 ||
strcmp(proto, "git+http") == 0) {
error = got_error_path(proto, GOT_ERR_NOT_IMPL);
error = got_error_path(proto, GOT_ERR_BAD_PROTO);
goto done;
}
-#endif
if (dirname == NULL) {
if (asprintf(&default_destdir, "%s.git", repo_name) == -1) {
error = got_error_from_errno("asprintf");
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, "w");
+ if (gitconfig_file == NULL) {
+ error = got_error_from_errno2("fopen", gitconfig_path);
+ goto done;
+ }
+ if (asprintf(&gitconfig,
+ "[core]\n"
+ "\trepositoryformatversion = 0\n"
+ "\tbare = true\n"
+ "[remote \"origin\"]\n"
+ "\turl = %s\n"
+ "\tfetch = +refs/heads/*:refs/remotes/origin/*\n",
+ git_url) == -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);
done:
if (fetchfd != -1 && close(fetchfd) == -1 && error == NULL)
error = got_error_from_errno("close");
+ if (gitconfig_file && fclose(gitconfig_file) == EOF && error == NULL)
+ error = got_error_from_errno("fclose");
if (repo)
got_repo_close(repo);
TAILQ_FOREACH(pe, &refs, entry) {
free(server_path);
free(repo_name);
free(default_destdir);
+ free(gitconfig_path);
+ free(git_url);
return error;
}
blob - d3b000f562ba9a602722f0d0855655cb2703138b
blob + 106390c3755823cde7aec38e7f08f87dd09e1afc
--- include/got_repository.h
+++ include/got_repository.h
char *got_repo_get_path_objects_pack(struct got_repository *);
char *got_repo_get_path_refs(struct got_repository *);
char *got_repo_get_path_packed_refs(struct got_repository *);
+char *got_repo_get_path_gitconfig(struct got_repository *);
struct got_reference;
blob - 734d7b19d5e8436d00ee7297763958bb44a01877
blob + 1c7c3d1f214491493e2c64d9a0a7abee0317d35e
--- lib/repository.c
+++ lib/repository.c
return get_path_git_child(repo, GOT_HEAD_FILE);
}
-static const struct got_error *
-get_path_gitconfig(char **p, struct got_repository *repo)
+char *
+got_repo_get_path_gitconfig(struct got_repository *repo)
{
- *p = get_path_git_child(repo, GOT_GITCONFIG);
- if (*p == NULL)
- return got_error_from_errno("asprintf");
- return NULL;
+ return get_path_git_child(repo, GOT_GITCONFIG);
}
void
}
/* Read repository's .git/config file. */
- err = get_path_gitconfig(&repo_gitconfig_path, repo);
- if (err)
- return err;
+ repo_gitconfig_path = got_repo_get_path_gitconfig(repo);
+ if (repo_gitconfig_path == NULL)
+ return got_error_from_errno("got_repo_get_path_gitconfig");
err = parse_gitconfig_file(&repo->gitconfig_repository_format_version,
&repo->gitconfig_author_name, &repo->gitconfig_author_email,