Merge branch 'tb/fetch-all-configuration'

"git fetch" learned to pay attention to "fetch.all" configuration
variable, which pretends as if "--all" was passed from the command
line when no remote parameter was given.

* tb/fetch-all-configuration:
  fetch: add new config option fetch.all
This commit is contained in:
Junio C Hamano
2024-01-19 15:04:45 -08:00
4 changed files with 186 additions and 3 deletions

View File

@ -100,6 +100,7 @@ static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP;
struct fetch_config {
enum display_format display_format;
int all;
int prune;
int prune_tags;
int show_forced_updates;
@ -113,6 +114,11 @@ static int git_fetch_config(const char *k, const char *v,
{
struct fetch_config *fetch_config = cb;
if (!strcmp(k, "fetch.all")) {
fetch_config->all = git_config_bool(k, v);
return 0;
}
if (!strcmp(k, "fetch.prune")) {
fetch_config->prune = git_config_bool(k, v);
return 0;
@ -2130,7 +2136,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
const char *bundle_uri;
struct string_list list = STRING_LIST_INIT_DUP;
struct remote *remote = NULL;
int all = 0, multiple = 0;
int all = -1, multiple = 0;
int result = 0;
int prune_tags_ok = 1;
int enable_auto_gc = 1;
@ -2335,11 +2341,20 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
fetch_bundle_uri(the_repository, bundle_uri, NULL))
warning(_("failed to fetch bundles from '%s'"), bundle_uri);
if (all < 0) {
/*
* no --[no-]all given;
* only use config option if no remote was explicitly specified
*/
all = (!argc) ? config.all : 0;
}
if (all) {
if (argc == 1)
die(_("fetch --all does not take a repository argument"));
else if (argc > 1)
die(_("fetch --all does not make sense with refspecs"));
(void) for_each_remote(get_one_remote_for_fetch, &list);
/* do not do fetch_multiple() of one */