commit 0c8b29c50669cb8958428fbf923f02a5b69184db from: Stefan Sperling date: Tue Jan 05 17:22:14 2021 UTC add a 'fetch-all-branches' configuration setting to got.conf(5) Set fetch-all-branches in the got.conf(5) file created by 'got clone -a' in order to make a future 'got fetch' act like 'got fetch -a' by default. commit - 98f64f14c3dc52ec6afc00acc53dc9f42399d363 commit + 0c8b29c50669cb8958428fbf923f02a5b69184db blob - 02dba0611ec49e96e7b8bcaf78fe8563f3b23dfb blob + 0c9b09363064bf04ebce70c997b86d14d97d6b78 --- got/got.1 +++ got/got.1 @@ -362,6 +362,8 @@ are as follows: Fetch all branches from the remote repository's .Dq refs/heads/ reference namespace. +This option can be enabled by default for specific repositories in +.Xr got.conf 5 . If this option is not specified, a branch resolved via the remote repository's HEAD reference will be fetched. Cannot be used together with the blob - 4c56b96c153df47ae9d07b608972fe5625f79d5e blob + 53829fbd5cf6cd49d4f93619417cf7218d2bbd1e --- got/got.c +++ got/got.c @@ -1164,8 +1164,8 @@ create_wanted_ref(const char *refname, struct got_obje static const struct got_error * create_gotconfig(const char *proto, const char *host, const char *port, const char *remote_repo_path, const char *default_branch, - struct got_pathlist_head *wanted_branches, int mirror_references, - struct got_repository *repo) + int fetch_all_branches, struct got_pathlist_head *wanted_branches, + int mirror_references, struct got_repository *repo) { const struct got_error *err = NULL; char *gotconfig_path = NULL; @@ -1175,7 +1175,7 @@ create_gotconfig(const char *proto, const char *host, char *branches = NULL; ssize_t n; - if (!TAILQ_EMPTY(wanted_branches)) { + if (!fetch_all_branches && !TAILQ_EMPTY(wanted_branches)) { struct got_pathlist_entry *pe; TAILQ_FOREACH(pe, wanted_branches, entry) { char *s; @@ -1190,7 +1190,7 @@ create_gotconfig(const char *proto, const char *host, free(branches); branches = s; } - } else if (default_branch) { + } else if (!fetch_all_branches && default_branch) { branchname = default_branch; if (strncmp(branchname, "refs/heads/", 11) == 0) branchname += 11; @@ -1219,12 +1219,14 @@ create_gotconfig(const char *proto, const char *host, "\trepository \"%s\"\n" "%s%s%s" "%s" + "%s" "}\n", GOT_FETCH_DEFAULT_REMOTE_NAME, host, proto, port ? "\tport " : "", port ? port : "", port ? "\n" : "", remote_repo_path, branches ? "\tbranch { " : "", branches ? branches : "", branches ? "}\n" : "", - mirror_references ? "\tmirror-references yes\n" : "") == -1) { + mirror_references ? "\tmirror-references yes\n" : "", + fetch_all_branches ? "\tfetch-all-branches yes\n" : "") == -1) { err = got_error_from_errno("asprintf"); goto done; } @@ -1373,7 +1375,8 @@ create_config_files(const char *proto, const char *hos /* Create got.conf(5). */ err = create_gotconfig(proto, host, port, remote_repo_path, - default_branch, wanted_branches, mirror_references, repo); + default_branch, fetch_all_branches, wanted_branches, + mirror_references, repo); if (err) return err; @@ -2209,12 +2212,13 @@ cmd_fetch(int argc, char *argv[]) goto done; } - if (TAILQ_EMPTY(&wanted_branches) && remote->nbranches > 0) { + if (TAILQ_EMPTY(&wanted_branches)) { + if (!fetch_all_branches) + fetch_all_branches = remote->fetch_all_branches; for (i = 0; i < remote->nbranches; i++) { got_pathlist_append(&wanted_branches, remote->branches[i], NULL); } - } error = got_fetch_parse_uri(&proto, &host, &port, &server_path, blob - 4995cf2a725ee8bd5c325bcf65e0bafcf67f4f87 blob + b4fe08c8227db5b27b1d37237b58cef45adbbdb8 --- got/got.conf.5 +++ got/got.conf.5 @@ -114,6 +114,17 @@ The list of branches specified here can be overridden command line with the .Fl b option. +.It Ic fetch-all-branches Ar yes | no +This option controls whether +.Cm got fetch +will fetch all branches from the remote repository by default. +If enabled, this behaviour can be overridden at the +.Cm got fetch +command line with the +.Fl b +option, and any +.Cm branch +configuration settings for this remote repository will be ignored. .It Ic mirror-references Ar yes | no This option controls the behaviour of .Cm got fetch blob - 1b274cc91e744b2672ce8c785379d258cd79f4cb blob + 8cc337b5791e1261b077f0b81458c6a6fa7a3672 --- include/got_repository.h +++ include/got_repository.h @@ -61,6 +61,12 @@ struct got_remote_repo { */ int mirror_references; + /* + * If set, fetch all branches by default and ignore the list of + * branches below. + */ + int fetch_all_branches; + /* Branches to fetch by default. */ int nbranches; char **branches; blob - f4815b5fc99e9f8665fd85b9326c64f18b176d04 blob + fba84c449fe93dd2034e7f391c26ffcc869e1bd9 --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -378,6 +378,7 @@ struct got_imsg_remote { size_t name_len; size_t url_len; int mirror_references; + int fetch_all_branches; int nbranches; /* Followed by name_len + url_len data bytes. */ blob - a17a8788d58b000507ac5d3d079dfaba0fe6ac2d blob + a4c526b34cd96016e55eeea3f87de869709e3eed --- lib/privsep.c +++ lib/privsep.c @@ -1889,6 +1889,7 @@ got_privsep_recv_gitconfig_remotes(struct got_remote_r break; } remote->mirror_references = iremote.mirror_references; + remote->fetch_all_branches = iremote.fetch_all_branches; remote->nbranches = 0; remote->branches = NULL; (*nremotes)++; @@ -2095,6 +2096,7 @@ got_privsep_recv_gotconfig_remotes(struct got_remote_r break; } remote->mirror_references = iremote.mirror_references; + remote->fetch_all_branches = iremote.fetch_all_branches; if (iremote.nbranches > 0) { remote->branches = recallocarray(NULL, 0, iremote.nbranches, sizeof(char *)); blob - 631e11236b4eb40c77f4df72632afabd30ee931e blob + 70e993212984e95be5ad134c51a5705fd98e7417 --- libexec/got-read-gotconfig/got-read-gotconfig.c +++ libexec/got-read-gotconfig/got-read-gotconfig.c @@ -153,6 +153,7 @@ send_gotconfig_remotes(struct imsgbuf *ibuf, iremote.nbranches = nbranches; iremote.mirror_references = repo->mirror_references; + iremote.fetch_all_branches = repo->fetch_all_branches; iremote.name_len = strlen(repo->name); len += iremote.name_len; blob - a909f144a9ab2a4715e7975ad3fcbd8764181cde blob + 212b87b75f0b8d817b88f63b9c5d417d6499a93c --- libexec/got-read-gotconfig/gotconfig.h +++ libexec/got-read-gotconfig/gotconfig.h @@ -29,6 +29,7 @@ struct gotconfig_remote_repo { char *protocol; int port; int mirror_references; + int fetch_all_branches; struct node_branch *branch; }; TAILQ_HEAD(gotconfig_remote_repo_list, gotconfig_remote_repo); blob - df2c1d75f7705837e1cd37d49b209df5a83700c3 blob + 07d4556e67f6c9a4b929b7ada11df90e97e2ebd7 --- libexec/got-read-gotconfig/parse.y +++ libexec/got-read-gotconfig/parse.y @@ -95,7 +95,7 @@ typedef struct { %token ERROR %token REMOTE REPOSITORY SERVER PORT PROTOCOL MIRROR_REFERENCES BRANCH -%token AUTHOR +%token AUTHOR FETCH_ALL_BRANCHES %token STRING %token NUMBER %type boolean portplain @@ -196,6 +196,9 @@ remoteopts1 : REPOSITORY STRING { } | MIRROR_REFERENCES boolean { remote->mirror_references = $2; + } + | FETCH_ALL_BRANCHES boolean { + remote->fetch_all_branches = $2; } | PORT portplain { remote->port = $2; @@ -286,6 +289,7 @@ lookup(char *s) static const struct keywords keywords[] = { {"author", AUTHOR}, {"branch", BRANCH}, + {"fetch-all-branches", FETCH_ALL_BRANCHES}, {"mirror-references", MIRROR_REFERENCES}, {"port", PORT}, {"protocol", PROTOCOL}, blob - cf7f3aca59153463bc475a9b2dbb9cc872537bc8 blob + b36a5f40a0b3db3547f0990d5fd2b2b947fc4821 --- regress/cmdline/clone.sh +++ regress/cmdline/clone.sh @@ -270,7 +270,7 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "master" } + fetch-all-branches yes } EOF cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected @@ -414,8 +414,8 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "master" } - mirror-references yes + mirror-references yes + fetch-all-branches yes } EOF cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected