remote: add remote.*.negotiationInclude config

Add a new 'remote.<name>.negotiationInclude' multi-valued config option that provides default values for --negotiation-include when no --negotiation-include arguments are specified over the command line. This is a mirror of how 'remote.<name>.negotiationRestrict' specifies defaults for the --negotiation-restrict arguments. Each value is either an exact ref name or a glob pattern whose tips should always be sent as 'have' lines during negotiation. The config values are resolved through the same resolve_negotiation_include() codepath as the CLI options. This option is additive with the normal negotiation process: the negotiation algorithm still runs and advertises its own selected commits, but the refs matching the config are sent unconditionally on top of those heuristically selected commits. Similar to the negotiationRestrict config, an empty value resets the value list to allow ignoring earlier config values, such as those that might be set in system or global config. Reviewed-by: Matthew John Cheetham <mjcheetham@outlook.com> Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed May 19, 2026 at 16:24 UTC 6f37fecfed7633d47b2c0e16fde0a8ca89e45beb
6 files changed +96
Documentation/config/remote.adoc
+25
@@ -125,6 +125,31 @@ values are not used.
125 Blank values signal to ignore all previous values, allowing a reset of
126 the list from broader config scenarios.
127
128 +remote.<name>.negotiationInclude::
129 + When negotiating with this remote during `git fetch`, the client
130 + advertises a list of commits that exist locally. In repos with
131 + many references, this list of "haves" can be truncated. Depending
132 + on data shape, dropping certain references may be expensive. This
133 + multi-valued config option specifies references, commit hashes,
134 + or ref pattern globs whose tips should always be sent as "have"
135 + commits during fetch negotiation with this remote.
136 ++
137 +Each value is either an exact ref name (e.g. `refs/heads/release`), a
138 +commit hash, or a glob pattern (e.g. `refs/heads/release/*`). The
139 +pattern syntax is the same as for `--negotiation-include`.
140 ++
141 +These config values are used as defaults for the `--negotiation-include`
142 +command-line option. If `--negotiation-include` is specified on the
143 +command line, then the config values are not used.
144 ++
145 +This option is additive with the normal negotiation process: the
146 +negotiation algorithm still runs and advertises its own selected commits,
147 +but the refs matching `remote.<name>.negotiationInclude` are sent
148 +unconditionally on top of those heuristically selected commits.
149 ++
150 +Blank values signal to ignore all previous values, allowing a reset of
151 +the list from broader config scenarios.
152 +
153 remote.<name>.followRemoteHEAD::
154 How linkgit:git-fetch[1] should handle updates to `remotes/<name>/HEAD`
155 when fetching using the configured refspecs of a remote.
Documentation/fetch-options.adoc
+4
@@ -91,6 +91,10 @@ The pattern syntax is the same as for `--negotiation-restrict`.
91 If `--negotiation-restrict` is used, the have set is first restricted by
92 that option and then increased to include the tips specified by
93 `--negotiation-include`.
94 ++
95 +If this option is not specified on the command line, then any
96 +`remote.<name>.negotiationInclude` config values for the current remote
97 +are used instead.
98
99 `--negotiate-only`::
100 Do not fetch anything from the server, and instead print the
builtin/fetch.c
+12
@@ -1634,6 +1634,18 @@ static struct transport *prepare_transport(struct remote *remote, int deepen,
1634 else
1635 warning(_("ignoring %s because the protocol does not support it"),
1636 "--negotiation-include");
1637 + } else if (remote->negotiation_include.nr) {
1638 + if (transport->smart_options) {
1639 + add_negotiation_tips(&remote->negotiation_include,
1640 + &transport->smart_options->negotiation_include_tips,
1641 + "--negotiation-include");
1642 + } else {
1643 + struct strbuf config_name = STRBUF_INIT;
1644 + strbuf_addf(&config_name, "remote.%s.negotiationInclude", remote->name);
1645 + warning(_("ignoring %s because the protocol does not support it"),
1646 + config_name.buf);
1647 + strbuf_release(&config_name);
1648 + }
1649 }
1650 return transport;
1651 }
remote.c
+5
@@ -153,6 +153,7 @@ static struct remote *make_remote(struct remote_state *remote_state,
153 refspec_init_fetch(&ret->fetch);
154 string_list_init_dup(&ret->server_options);
155 string_list_init_dup(&ret->negotiation_restrict);
156 + string_list_init_dup(&ret->negotiation_include);
157
158 ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,
159 remote_state->remotes_alloc);
@@ -181,6 +182,7 @@ static void remote_clear(struct remote *remote)
182 FREE_AND_NULL(remote->http_proxy_authmethod);
183 string_list_clear(&remote->server_options, 0);
184 string_list_clear(&remote->negotiation_restrict, 0);
185 + string_list_clear(&remote->negotiation_include, 0);
186 }
187
188 static void add_merge(struct branch *branch, const char *name)
@@ -567,6 +569,9 @@ static int handle_config(const char *key, const char *value,
569 } else if (!strcmp(subkey, "negotiationrestrict")) {
570 return parse_transport_option(key, value,
571 &remote->negotiation_restrict);
572 + } else if (!strcmp(subkey, "negotiationinclude")) {
573 + return parse_transport_option(key, value,
574 + &remote->negotiation_include);
575 } else if (!strcmp(subkey, "followremotehead")) {
576 const char *no_warn_branch;
577 if (!strcmp(value, "never"))
remote.h
+1
@@ -118,6 +118,7 @@ struct remote {
118
119 struct string_list server_options;
120 struct string_list negotiation_restrict;
121 + struct string_list negotiation_include;
122
123 enum follow_remote_head_settings follow_remote_head;
124 const char *no_warn_branch;
t/t5510-fetch.sh
+49
@@ -1587,6 +1587,55 @@ test_expect_success '--negotiation-include avoids duplicates with negotiator' '
1587 test_line_count = 1 matches
1588 '
1589
1590 +test_expect_success 'remote.<name>.negotiationInclude used as default for --negotiation-include' '
1591 + test_when_finished rm -f trace &&
1592 + setup_negotiation_tip server server 0 &&
1593 +
1594 + # test the reset of the list on an empty value
1595 + git -C client config --add remote.origin.negotiationInclude refs/tags/alpha_1 &&
1596 + git -C client config --add remote.origin.negotiationInclude "" &&
1597 + git -C client config --add remote.origin.negotiationInclude refs/tags/beta_1 &&
1598 + GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1599 + --negotiation-restrict=beta_2 \
1600 + origin alpha_s beta_s &&
1601 +
1602 + ALPHA_1=$(git -C client rev-parse alpha_1) &&
1603 + test_grep ! "fetch> have $ALPHA_1" trace &&
1604 + BETA_1=$(git -C client rev-parse beta_1) &&
1605 + test_grep "fetch> have $BETA_1" trace
1606 +'
1607 +
1608 +test_expect_success 'remote.<name>.negotiationInclude works with glob patterns' '
1609 + test_when_finished rm -f trace &&
1610 + setup_negotiation_tip server server 0 &&
1611 +
1612 + git -C client config --add remote.origin.negotiationInclude "refs/tags/beta_*" &&
1613 + GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1614 + --negotiation-restrict=alpha_1 \
1615 + origin alpha_s beta_s &&
1616 +
1617 + BETA_1=$(git -C client rev-parse beta_1) &&
1618 + test_grep "fetch> have $BETA_1" trace &&
1619 + BETA_2=$(git -C client rev-parse beta_2) &&
1620 + test_grep "fetch> have $BETA_2" trace
1621 +'
1622 +
1623 +test_expect_success 'CLI --negotiation-include overrides remote.<name>.negotiationInclude' '
1624 + test_when_finished rm -f trace &&
1625 + setup_negotiation_tip server server 0 &&
1626 +
1627 + git -C client config --add remote.origin.negotiationInclude refs/tags/beta_2 &&
1628 + GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1629 + --negotiation-restrict=alpha_1 \
1630 + --negotiation-include=refs/tags/beta_1 \
1631 + origin alpha_s beta_s &&
1632 +
1633 + BETA_1=$(git -C client rev-parse beta_1) &&
1634 + test_grep "fetch> have $BETA_1" trace &&
1635 + BETA_2=$(git -C client rev-parse beta_2) &&
1636 + test_grep ! "fetch> have $BETA_2" trace
1637 +'
1638 +
1639 test_expect_success '--negotiation-include avoids duplicates with v0' '
1640 test_when_finished rm -f trace &&
1641 setup_negotiation_tip server server 0 &&