* [PATCH 1/5] promisor-remote: factor out lazy_fetch_objects()
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
@ 2026-08-07 13:55 ` Christian Couder
2026-08-07 13:58 ` Christian Couder
2026-08-07 13:55 ` [PATCH 2/5] setup: extract path_allowlist_apply() Christian Couder
` (10 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Christian Couder @ 2026-08-07 13:55 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder,
Christian Couder
In "promisor-remote.c:fetch_objects()", there is a check to disable
lazy fetching when the `GIT_NO_LAZY_FETCH` environment variable is
set. The fetch_objects() function is called once per promisor remote
though. So the check might be performed more times than necessary.
Also promisor_remote_get_direct() mixes up the logic deciding which
promisor remotes to try with the logic checking that the objects
that could not be fetched are promisor objects.
Let's refactor the lazy fetching logic out of these two functions
into a new lazy_fetch_objects() function.
This is a pure refactoring with no intended behavior change. Two
things shift in ways that are observably equivalent though:
- the `GIT_NO_LAZY_FETCH` check is now performed once up front,
instead of once per promisor remote, and
- promisor_remote_init() is no longer called when lazy fetching
is disabled, which is fine as nothing downstream of it, like
is_promisor_object(), needs it in that case.
While at it, let's also convert try_promisor_remotes() to return
'bool' instead of 'int', as it just returns whether all the objects
could be fetched, and document its return value.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
promisor-remote.c | 76 ++++++++++++++++++++++++++++-------------------
1 file changed, 45 insertions(+), 31 deletions(-)
diff --git a/promisor-remote.c b/promisor-remote.c
index 43505d1e1a..65496c69cf 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -31,15 +31,6 @@ static int fetch_objects(struct repository *repo,
FILE *child_in;
int quiet;
- if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) {
- static int warning_shown;
- if (!warning_shown) {
- warning_shown = 1;
- warning(_("lazy fetching disabled; some objects may not be available"));
- }
- return -1;
- }
-
child.git_cmd = 1;
child.in = -1;
if (repo != the_repository)
@@ -270,10 +261,15 @@ static int remove_fetched_oids(struct repository *repo,
return remaining_nr;
}
-static int try_promisor_remotes(struct repository *repo,
- struct object_id **remaining_oids,
- int *remaining_nr, int *to_free,
- bool accepted_only)
+/*
+ * Return 'true' if all the objects could be fetched from the
+ * (non-)accepted remotes, 'false' otherwise.
+ */
+static bool try_promisor_remotes(struct repository *repo,
+ struct object_id **remaining_oids,
+ int *remaining_nr,
+ int *to_free,
+ bool accepted_only)
{
struct promisor_remote *r = repo->promisor_remote_config->promisors;
@@ -290,9 +286,37 @@ static int try_promisor_remotes(struct repository *repo,
continue;
}
}
- return 1; /* all fetched */
+ return true; /* all fetched */
}
- return 0;
+ return false;
+}
+
+/*
+ * Return 'true' if all the objects could be fetched, 'false' otherwise.
+ */
+static bool lazy_fetch_objects(struct repository *repo,
+ struct object_id **remaining_oids,
+ int *remaining_nr,
+ int *to_free)
+{
+ if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) {
+ static int warning_shown;
+ if (!warning_shown) {
+ warning_shown = 1;
+ warning(_("lazy fetching disabled; some objects may not be available"));
+ }
+ return false;
+ }
+
+ promisor_remote_init(repo);
+
+ /* Try accepted remotes first (those the server told us to use) */
+ if (try_promisor_remotes(repo, remaining_oids, remaining_nr,
+ to_free, true))
+ return true;
+
+ return try_promisor_remotes(repo, remaining_oids, remaining_nr,
+ to_free, false);
}
void promisor_remote_get_direct(struct repository *repo,
@@ -302,28 +326,18 @@ void promisor_remote_get_direct(struct repository *repo,
struct object_id *remaining_oids = (struct object_id *)oids;
int remaining_nr = oid_nr;
int to_free = 0;
- int i;
if (oid_nr == 0)
return;
- promisor_remote_init(repo);
-
- /* Try accepted remotes first (those the server told us to use) */
- if (try_promisor_remotes(repo, &remaining_oids, &remaining_nr,
- &to_free, true))
- goto all_fetched;
- if (try_promisor_remotes(repo, &remaining_oids, &remaining_nr,
- &to_free, false))
- goto all_fetched;
-
- for (i = 0; i < remaining_nr; i++) {
- if (is_promisor_object(repo, &remaining_oids[i]))
- die(_("could not fetch %s from promisor remote"),
- oid_to_hex(&remaining_oids[i]));
+ if (!lazy_fetch_objects(repo, &remaining_oids, &remaining_nr, &to_free)) {
+ for (int i = 0; i < remaining_nr; i++) {
+ if (is_promisor_object(repo, &remaining_oids[i]))
+ die(_("could not fetch %s from promisor remote"),
+ oid_to_hex(&remaining_oids[i]));
+ }
}
-all_fetched:
if (to_free)
free(remaining_oids);
}
--
2.55.0.530.gdb3615d990.dirty
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 2/5] setup: extract path_allowlist_apply()
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
2026-08-07 13:55 ` [PATCH 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
@ 2026-08-07 13:55 ` Christian Couder
2026-08-07 13:55 ` [PATCH 3/5] setup: add 'allow_dot' arg to path_allowlist_apply() Christian Couder
` (9 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-07 13:55 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder,
Christian Couder
In a following commit we are going to check whether a repository is
part of an allowlist specified in a config variable.
To prepare for that let's extract existing code from
safe_directory_cb() into a new path_allowlist_apply() helper that will
help with such checks.
While at it let's make the helper's code simpler and more generic.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
setup.c | 107 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 59 insertions(+), 48 deletions(-)
diff --git a/setup.c b/setup.c
index 95909e9603..39dfa1cc5f 100644
--- a/setup.c
+++ b/setup.c
@@ -1339,6 +1339,64 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
}
}
+static void path_allowlist_apply(const char *key, const char *value,
+ const char *target_path, int *is_match)
+{
+ char *allowed = NULL;
+ char *normalized = NULL;
+
+ if (!value || !*value) {
+ *is_match = 0;
+ return;
+ }
+
+ if (!strcmp(value, "*")) {
+ *is_match = 1;
+ return;
+ }
+
+ if (git_config_pathname(&allowed, key, value) || !allowed)
+ return;
+
+ /*
+ * Setting the config variable to a non-absolute path makes
+ * little sense---it won't be relative to the configuration
+ * file the item is defined in. Except for ".", which means
+ * "if we are at the top level of a repository, then it is
+ * OK", which is slightly tighter than "*" that allows
+ * discovery.
+ */
+ if (!is_absolute_path(allowed) && strcmp(allowed, ".")) {
+ warning(_("%s '%s' not absolute"), key, allowed);
+ goto end;
+ }
+
+ /*
+ * A .gitconfig in $HOME may be shared across different
+ * machines and the config variable entries may or may not
+ * exist as paths on all of these machines. In other words,
+ * it is not a warning worthy event when there is no such path
+ * on this machine---the entry may be useful elsewhere.
+ */
+ normalized = real_pathdup(allowed, 0);
+ if (!normalized)
+ goto end;
+
+ if (ends_with(normalized, "/*")) {
+ size_t len = strlen(normalized);
+ if (!fspathncmp(normalized, target_path, len - 1))
+ *is_match = 1;
+ goto end;
+ }
+
+ if (!fspathcmp(target_path, normalized))
+ *is_match = 1;
+
+end:
+ free(normalized);
+ free(allowed);
+}
+
struct safe_directory_data {
char *path;
int is_safe;
@@ -1352,54 +1410,7 @@ static int safe_directory_cb(const char *key, const char *value,
if (strcmp(key, "safe.directory"))
return 0;
- if (!value || !*value) {
- data->is_safe = 0;
- } else if (!strcmp(value, "*")) {
- data->is_safe = 1;
- } else {
- char *allowed = NULL;
-
- if (!git_config_pathname(&allowed, key, value) && allowed) {
- char *normalized = NULL;
-
- /*
- * Setting safe.directory to a non-absolute path
- * makes little sense---it won't be relative to
- * the configuration file the item is defined in.
- * Except for ".", which means "if we are at the top
- * level of a repository, then it is OK", which is
- * slightly tighter than "*" that allows discovery.
- */
- if (!is_absolute_path(allowed) && strcmp(allowed, ".")) {
- warning(_("safe.directory '%s' not absolute"),
- allowed);
- goto next;
- }
-
- /*
- * A .gitconfig in $HOME may be shared across
- * different machines and safe.directory entries
- * may or may not exist as paths on all of these
- * machines. In other words, it is not a warning
- * worthy event when there is no such path on this
- * machine---the entry may be useful elsewhere.
- */
- normalized = real_pathdup(allowed, 0);
- if (!normalized)
- goto next;
-
- if (ends_with(normalized, "/*")) {
- size_t len = strlen(normalized);
- if (!fspathncmp(normalized, data->path, len - 1))
- data->is_safe = 1;
- } else if (!fspathcmp(data->path, normalized)) {
- data->is_safe = 1;
- }
- next:
- free(normalized);
- free(allowed);
- }
- }
+ path_allowlist_apply(key, value, data->path, &data->is_safe);
return 0;
}
--
2.55.0.530.gdb3615d990.dirty
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 3/5] setup: add 'allow_dot' arg to path_allowlist_apply()
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
2026-08-07 13:55 ` [PATCH 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-08-07 13:55 ` [PATCH 2/5] setup: extract path_allowlist_apply() Christian Couder
@ 2026-08-07 13:55 ` Christian Couder
2026-08-07 13:55 ` [PATCH 4/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
` (8 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-07 13:55 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder,
Christian Couder
A previous commit created path_allowlist_apply() with the goal of later
reusing that function. But when it will be reused in a following commit
this function will need to reject non-absolute paths including those
with a single dot that are currently accepted.
To prepare for reusing path_allowlist_apply(), let's add a
`bool allow_dot` argument to it, and let's export this function.
While at it let's document it properly in "setup.h".
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
setup.c | 9 +++++----
setup.h | 28 ++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/setup.c b/setup.c
index 39dfa1cc5f..a09e697e3a 100644
--- a/setup.c
+++ b/setup.c
@@ -1339,8 +1339,9 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
}
}
-static void path_allowlist_apply(const char *key, const char *value,
- const char *target_path, int *is_match)
+void path_allowlist_apply(const char *key, const char *value,
+ const char *target_path, int *is_match,
+ bool allow_dot)
{
char *allowed = NULL;
char *normalized = NULL;
@@ -1366,7 +1367,7 @@ static void path_allowlist_apply(const char *key, const char *value,
* OK", which is slightly tighter than "*" that allows
* discovery.
*/
- if (!is_absolute_path(allowed) && strcmp(allowed, ".")) {
+ if (!is_absolute_path(allowed) && (!allow_dot || strcmp(allowed, "."))) {
warning(_("%s '%s' not absolute"), key, allowed);
goto end;
}
@@ -1410,7 +1411,7 @@ static int safe_directory_cb(const char *key, const char *value,
if (strcmp(key, "safe.directory"))
return 0;
- path_allowlist_apply(key, value, data->path, &data->is_safe);
+ path_allowlist_apply(key, value, data->path, &data->is_safe, true);
return 0;
}
diff --git a/setup.h b/setup.h
index 654f10e059..d4f8af5457 100644
--- a/setup.h
+++ b/setup.h
@@ -304,4 +304,32 @@ struct startup_info {
extern struct startup_info *startup_info;
extern const char *tmp_original_cwd;
+/*
+ * Apply the path allowlist in 'value' against 'target_path' setting
+ * '*is_match' accordingly.
+ *
+ * `value` is the value of a multi-valued config variable named `key`
+ * that holds an allowlist of paths. `target_path` is the (normalized)
+ * path being tested. `*is_match` is updated in place:
+ *
+ * - an empty value resets it to 0 (so a later, more specific config
+ * scope can clear entries from a broader one),
+ * - "*" sets it to 1 (allow everything),
+ * - "<path>" sets it to 1 if <path> equals `target_path`,
+ * - "<path>" + "/" + "*" sets it to 1 if <path> is a leading
+ * directory of `target_path`,
+ * - any other (unmatching) value leaves `*is_match` unchanged.
+ *
+ * Non-absolute values are rejected with a warning, except "." when
+ * `allow_dot` is set (used by 'safe.directory' to mean "the top level
+ * of the current repository").
+ *
+ * Callers are expected to invoke this once per config value,
+ * typically from a protected-config callback, so that untrusted
+ * repository config cannot influence the decision.
+ */
+void path_allowlist_apply(const char *key, const char *value,
+ const char *target_path, int *is_match,
+ bool allow_dot);
+
#endif /* SETUP_H */
--
2.55.0.530.gdb3615d990.dirty
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 4/5] upload-pack: read uploadpack.lazyFetchTrusted
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (2 preceding siblings ...)
2026-08-07 13:55 ` [PATCH 3/5] setup: add 'allow_dot' arg to path_allowlist_apply() Christian Couder
@ 2026-08-07 13:55 ` Christian Couder
2026-08-07 13:55 ` [PATCH 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
` (7 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-07 13:55 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder,
Christian Couder
Previous commits created and prepared the path_allowlist_apply()
function.
Let's reuse this function for a new "uploadpack.lazyFetchTrusted"
configuration variable.
It allows us to:
- read an allowlist from that config variable,
- check if the current repo is in that list, and
- return the result from a new upload_pack_lazy_fetch_trusted()
function.
The new function will be used in a following commit.
Note that the new config variable should be read only from protected
configuration files.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
upload-pack.c | 37 +++++++++++++++++++++++++++++++++++++
upload-pack.h | 3 +++
2 files changed, 40 insertions(+)
diff --git a/upload-pack.c b/upload-pack.c
index a52856d869..29e700e43b 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -34,6 +34,8 @@
#include "json-writer.h"
#include "strmap.h"
#include "promisor-remote.h"
+#include "setup.h"
+#include "abspath.h"
/* Remember to update object flag allocation in object.h */
#define THEY_HAVE (1u << 11)
@@ -1378,6 +1380,41 @@ static int upload_pack_config(const char *var, const char *value,
return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs);
}
+struct lazy_fetch_trusted {
+ int trusted;
+ char *repo_path;
+};
+
+static int upload_pack_protected_lazy_fetch_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
+{
+ struct lazy_fetch_trusted *data = cb_data;
+
+ if (!strcmp("uploadpack.lazyfetchtrusted", var)) {
+ path_allowlist_apply(var, value, data->repo_path,
+ &data->trusted, false);
+ return 0;
+ }
+
+ return 0;
+}
+
+bool upload_pack_lazy_fetch_trusted(struct repository *r)
+{
+ struct lazy_fetch_trusted data = { 0 };
+
+ data.repo_path = real_pathdup(r->worktree ? r->worktree : r->gitdir, 0);
+ if (!data.repo_path)
+ return false;
+
+ git_protected_config(upload_pack_protected_lazy_fetch_config, &data);
+
+ free(data.repo_path);
+
+ return !!data.trusted;
+}
+
static int upload_pack_protected_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *cb_data)
diff --git a/upload-pack.h b/upload-pack.h
index d6ee25ea98..b2212992c3 100644
--- a/upload-pack.h
+++ b/upload-pack.h
@@ -12,4 +12,7 @@ struct strbuf;
int upload_pack_advertise(struct repository *r,
struct strbuf *value);
+/* Is this repo trusted for lazy fetching? */
+bool upload_pack_lazy_fetch_trusted(struct repository *r);
+
#endif /* UPLOAD_PACK_H */
--
2.55.0.530.gdb3615d990.dirty
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (3 preceding siblings ...)
2026-08-07 13:55 ` [PATCH 4/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
@ 2026-08-07 13:55 ` Christian Couder
2026-08-07 18:31 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Junio C Hamano
` (6 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-07 13:55 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder,
Christian Couder
A previous commit added a new "uploadpack.lazyFetchTrusted" protected
config variable that can contain an allowlist of repos, as well as
functions to check if the current repo is in that list. But when the
current repo is in that list, we currently do nothing.
Let's instead set `GIT_NO_LAZY_FETCH` to `0`, which allows
`upload-pack` and its `pack-objects` child process to lazily fetch the
objects they need to serve a client, for example when the filter used
by the client and the one used by the server don't match.
This allows server operators to properly control lazy fetching. It is
their responsibility, not the client's, to decide if the served repo is
trusted, as the main security issue is that lazily fetching runs `git
fetch`, which may execute arbitrary commands specified in the
configuration and hooks of the served repo.
As `GIT_NO_LAZY_FETCH` is passed down to child processes through the
environment, this works for `pack-objects`, which performs the lazy
fetch when serving a client, without any further plumbing.
Now that "uploadpack.lazyFetchTrusted" is actually doing something,
let's document it and reference it from GIT_NO_LAZY_FETCH's docs.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
Documentation/config/uploadpack.adoc | 42 ++++++++++++++++
Documentation/git-upload-pack.adoc | 5 ++
Documentation/git.adoc | 4 +-
builtin/upload-pack.c | 11 +++++
t/t5710-promisor-remote-capability.sh | 70 +++++++++++++++++++++++++++
5 files changed, 131 insertions(+), 1 deletion(-)
diff --git a/Documentation/config/uploadpack.adoc b/Documentation/config/uploadpack.adoc
index 0e1dda944a..e960879c16 100644
--- a/Documentation/config/uploadpack.adoc
+++ b/Documentation/config/uploadpack.adoc
@@ -86,3 +86,45 @@ uploadpack.allowRefInWant::
is intended for the benefit of load-balanced servers which may
not have the same view of what OIDs their refs point to due to
replication delay.
+
+uploadpack.lazyFetchTrusted::
+ These config entries specify repositories that `upload-pack` is
+ allowed to lazily fetch missing objects for. By default,
+ `upload-pack` refuses to lazily fetch (see the description of the
+ `GIT_NO_LAZY_FETCH` environment variable in
+ linkgit:git-upload-pack[1]), because doing so would run `git fetch`,
+ which may execute arbitrary commands specified in the configuration
+ and hooks of the served repository. Listing a repository here tells
+ `upload-pack` that it is trusted, so lazy fetching from the promisor
+ remotes configured in it is allowed. This is equivalent to setting
+ `GIT_NO_LAZY_FETCH` to `0` for the matching repositories. An
+ explicitly set `GIT_NO_LAZY_FETCH` takes precedence over this
+ setting.
++
+Note that this allows lazy fetching from any promisor remote
+configured in the served repository, not only from the promisor
+remotes that the client accepted using the "promisor-remote" protocol
+v2 capability (see linkgit:gitprotocol-v2[5]). The served repository
+is trusted as a whole, including its configuration, so the promisor
+remotes it configures are trusted too. It is the server operator's
+responsibility to make sure that the promisor remotes of a trusted
+repository are also trustworthy.
++
+This is a multi-valued setting, i.e. you can add more than one
+repository via `git config (--global|--system) --add`. To reset the
+list of trusted repositories (e.g. to override any such repositories
+specified in the system config), add a `uploadpack.lazyFetchTrusted`
+entry with an empty value.
++
+A repository is identified by its worktree, or its git directory for a bare
+repository, and the value must be an absolute path. Giving a path with `/*`
+appended to it will trust all repositories under the named directory. To trust
+all served repositories, set `uploadpack.lazyFetchTrusted` to the string `*`.
++
+The value of this setting is interpolated, i.e. `~/<path>` expands to a
+path relative to the home directory and `%(prefix)/<path>` expands to a
+path relative to Git's (runtime) prefix.
++
+Note that this configuration variable is only respected when it is specified
+in protected configuration (see <<SCOPES>>). This prevents untrusted
+repositories from tampering with this value.
diff --git a/Documentation/git-upload-pack.adoc b/Documentation/git-upload-pack.adoc
index 9167a321d0..90c2ba1194 100644
--- a/Documentation/git-upload-pack.adoc
+++ b/Documentation/git-upload-pack.adoc
@@ -71,6 +71,11 @@ This is implemented by having `upload-pack` internally set the
(because you are fetching from a partial clone, and you are sure
you trust it), you can explicitly set `GIT_NO_LAZY_FETCH` to
`0`.
++
+Instead of setting `GIT_NO_LAZY_FETCH` to `0` in the environment, a
+server operator can allow lazy fetching on a per-repository basis by
+listing trusted repositories in the `uploadpack.lazyFetchTrusted`
+configuration variable. See linkgit:git-config[1].
SECURITY
--------
diff --git a/Documentation/git.adoc b/Documentation/git.adoc
index 8a5cdd3b3d..2e763d1f93 100644
--- a/Documentation/git.adoc
+++ b/Documentation/git.adoc
@@ -949,7 +949,9 @@ for full details.
`GIT_NO_LAZY_FETCH`::
Setting this Boolean environment variable to true tells Git
not to lazily fetch missing objects from the promisor remote
- on demand.
+ on demand. On the server side, the `uploadpack.lazyFetchTrusted`
+ configuration variable can control this per-repository. See
+ linkgit:git-upload-pack[1].
`GIT_REFLOG_ACTION`::
When a ref is updated, reflog entries are created to keep
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index 32831fb879..8b531ca724 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -42,10 +42,13 @@ int cmd_upload_pack(int argc,
OPT_END()
};
unsigned enter_repo_flags = ENTER_REPO_ANY_OWNER_OK;
+ bool no_lazy_fetch_set;
packet_trace_identity("upload-pack");
disable_replace_refs();
save_commit_buffer = 0;
+
+ no_lazy_fetch_set = !!getenv(NO_LAZY_FETCH_ENVIRONMENT);
xsetenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 0);
argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
@@ -62,6 +65,14 @@ int cmd_upload_pack(int argc,
if (!enter_repo(the_repository, dir, enter_repo_flags))
die("'%s' does not appear to be a git repository", dir);
+ /*
+ * Relax the GIT_NO_LAZY_FETCH=1 default if the served repo is in
+ * the "uploadpack.lazyFetchTrusted" protected allowlist and
+ * GIT_NO_LAZY_FETCH was not already set explicitly.
+ */
+ if (!no_lazy_fetch_set && upload_pack_lazy_fetch_trusted(the_repository))
+ xsetenv(NO_LAZY_FETCH_ENVIRONMENT, "0", 1);
+
switch (determine_protocol_version_server()) {
case protocol_v2:
if (advertise_refs)
diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh
index 549acff23f..e6993f2761 100755
--- a/t/t5710-promisor-remote-capability.sh
+++ b/t/t5710-promisor-remote-capability.sh
@@ -173,6 +173,76 @@ test_expect_success "clone with promisor.acceptfromserver set to 'None'" '
initialize_server 1 "$oid"
'
+test_expect_success "clone with uploadpack.lazyFetchTrusted" '
+ # No promisors are advertised
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # The served repo is trusted for lazy fetching
+ test_config_global uploadpack.lazyFetchTrusted "$(pwd)/server" &&
+
+ # Clone without GIT_NO_LAZY_FETCH=0
+ git clone --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is not missing on the server
+ # This means the server lazy fetched it
+ check_missing_objects server 0 "" &&
+
+ # Reinitialize server so that the largest object is missing again
+ initialize_server 1 "$oid"
+'
+
+test_expect_success "clone without uploadpack.lazyFetchTrusted fails" '
+ # No promisors are advertised
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # Note: no uploadpack.lazyFetchTrusted config is set here, so
+ # the served repo is NOT trusted for lazy fetching.
+
+ # Clone without GIT_NO_LAZY_FETCH=0 fails
+ test_must_fail git clone --no-local --filter="blob:limit=5k" server client 2>err &&
+ test_grep "lazy fetching disabled" err &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "uploadpack.lazyFetchTrusted is ignored in repo config" '
+ # No promisors are advertised
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # The served repo is trusted for lazy fetching, but this is
+ # done in the repo config, not in protected config, so this is
+ # ignored.
+ test_config -C server uploadpack.lazyFetchTrusted "$(pwd)/server" &&
+
+ # Clone without GIT_NO_LAZY_FETCH=0 fails
+ test_must_fail git clone --no-local --filter="blob:limit=5k" server client 2>err &&
+ test_grep "lazy fetching disabled" err &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "explicit GIT_NO_LAZY_FETCH overrides uploadpack.lazyFetchTrusted" '
+ # No promisors are advertised
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # The served repo is trusted for lazy fetching
+ test_config_global uploadpack.lazyFetchTrusted "$(pwd)/server" &&
+
+ # But GIT_NO_LAZY_FETCH=1 disables lazy fetching, so clone fails
+ test_must_fail env GIT_NO_LAZY_FETCH=1 git clone --no-local \
+ --filter="blob:limit=5k" server client 2>err &&
+ test_grep "lazy fetching disabled" err &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
test_expect_success "init + fetch with promisor.advertise set to 'true'" '
git -C server config promisor.advertise true &&
test_when_finished "rm -rf client" &&
--
2.55.0.530.gdb3615d990.dirty
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted'
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (4 preceding siblings ...)
2026-08-07 13:55 ` [PATCH 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
@ 2026-08-07 18:31 ` Junio C Hamano
2026-08-10 8:06 ` Christian Couder
2026-08-13 15:47 ` [PATCH v2 " Christian Couder
` (5 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Junio C Hamano @ 2026-08-07 18:31 UTC (permalink / raw)
To: Christian Couder
Cc: git, brian m . carlson, Patrick Steinhardt, Karthik Nayak,
Jeff King, Elijah Newren
Christian Couder <christian.couder@gmail.com> writes:
> Range diff with previous series
> ===============================
>
> The range diff with the previous ("Introduce a 'fromAccepted' option
> to GIT_NO_LAZY_FETCH") series is not very interesting as only the
> first patch has been saved, but anyway here it is:
>
> 1: 8dd67ddaca ! 1: b5b0836d19 promisor-remote: factor out lazy_fetch_objects()
> @@ Commit message
> that could not be fetched are promisor objects.
>
> Let's refactor the lazy fetching logic out of these two functions
> - into a new lazy_fetch_objects() function. This will make it easier
> - to extend the lazy fetching logic in following commits.
> + into a new lazy_fetch_objects() function.
>
> This is a pure refactoring with no intended behavior change. Two
> things shift in ways that are observably equivalent though:
> 2: 314c61cbbe < -: ---------- promisor-remote: introduce enum allow_lazy_fetch
> 3: cb2f5447e2 < -: ---------- promisor-remote: teach 'fromAccepted' to GIT_NO_LAZY_FETCH
> -: ---------- > 2: 879e3a34e3 setup: extract path_allowlist_apply()
> -: ---------- > 3: 98431ab7b3 setup: add 'allow_dot' arg to path_allowlist_apply()
> -: ---------- > 4: a46f4c1bb8 upload-pack: read uploadpack.lazyFetchTrusted
> -: ---------- > 5: 4063f233aa builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo
>
>
> Christian Couder (5):
> promisor-remote: factor out lazy_fetch_objects()
> setup: extract path_allowlist_apply()
> setup: add 'allow_dot' arg to path_allowlist_apply()
> upload-pack: read uploadpack.lazyFetchTrusted
> builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo
>
> Documentation/config/uploadpack.adoc | 42 ++++++++++
> Documentation/git-upload-pack.adoc | 5 ++
> Documentation/git.adoc | 4 +-
> builtin/upload-pack.c | 11 +++
> promisor-remote.c | 76 ++++++++++--------
> setup.c | 108 ++++++++++++++------------
> setup.h | 28 +++++++
> t/t5710-promisor-remote-capability.sh | 70 +++++++++++++++++
> upload-pack.c | 37 +++++++++
> upload-pack.h | 3 +
> 10 files changed, 304 insertions(+), 80 deletions(-)
What's missing is the information on the base. I tried applying
these patches to 'v2.55.0' and the recent tips of 'master':
2c78326f81 The 11th batch
5b2471720c The 10th batch
a97fcc37c2 The 9th batch
13c7afec21 The 8th batch
9a0c4701dc The 7th batch
5d2e770923 The 6th batch
48bbf81c29 The 5th batch
41365c2a9b The 4th batch for Git 2.56
d35c5399e3 The 3rd batch for Git 2.56
55526a1826 The 2nd batch for Git 2.56
but the series did not apply to any of them.
It turns out the reason has nothing to do with your choice of
base. It is because the series structure is not understood by 'b4'.
The cover letter I am responding to is a reply to another series,
but the patches in this round are not marked as 'v2'. This seems
to cause 'b4' to grab patches from both series and smash them
together, resulting in an inapplicable mess. It seems you cannot
have your cake and eat it, too 😠.
Next time, please do not thread the two topics together unless you
are marking the newer iteration with a higher 'vN' number.
Thanks.
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted'
2026-08-07 18:31 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Junio C Hamano
@ 2026-08-10 8:06 ` Christian Couder
2026-08-11 5:55 ` Junio C Hamano
0 siblings, 1 reply; 22+ messages in thread
From: Christian Couder @ 2026-08-10 8:06 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, brian m . carlson, Patrick Steinhardt, Karthik Nayak,
Jeff King, Elijah Newren
On Fri, Aug 7, 2026 at 8:31 PM Junio C Hamano <gitster@pobox.com> wrote:
> > Documentation/config/uploadpack.adoc | 42 ++++++++++
> > Documentation/git-upload-pack.adoc | 5 ++
> > Documentation/git.adoc | 4 +-
> > builtin/upload-pack.c | 11 +++
> > promisor-remote.c | 76 ++++++++++--------
> > setup.c | 108 ++++++++++++++------------
> > setup.h | 28 +++++++
> > t/t5710-promisor-remote-capability.sh | 70 +++++++++++++++++
> > upload-pack.c | 37 +++++++++
> > upload-pack.h | 3 +
> > 10 files changed, 304 insertions(+), 80 deletions(-)
>
> What's missing is the information on the base. I tried applying
> these patches to 'v2.55.0' and the recent tips of 'master':
>
> 2c78326f81 The 11th batch
> 5b2471720c The 10th batch
> a97fcc37c2 The 9th batch
> 13c7afec21 The 8th batch
> 9a0c4701dc The 7th batch
> 5d2e770923 The 6th batch
> 48bbf81c29 The 5th batch
> 41365c2a9b The 4th batch for Git 2.56
> d35c5399e3 The 3rd batch for Git 2.56
> 55526a1826 The 2nd batch for Git 2.56
>
> but the series did not apply to any of them.
>
> It turns out the reason has nothing to do with your choice of
> base. It is because the series structure is not understood by 'b4'.
>
> The cover letter I am responding to is a reply to another series,
> but the patches in this round are not marked as 'v2'. This seems
> to cause 'b4' to grab patches from both series and smash them
> together, resulting in an inapplicable mess. It seems you cannot
> have your cake and eat it, too 😠.
I guess b4 should have, or grow, an option for that, because it's not
uncommon that someone would post an alternative patch or patch series
in reply to some patch(es).
> Next time, please do not thread the two topics together unless you
> are marking the newer iteration with a higher 'vN' number.
Ok, I will not do that. I will start a separate thread. Now I hope it
will work if I send a v2 in reply to the latest series.
Thanks.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted'
2026-08-10 8:06 ` Christian Couder
@ 2026-08-11 5:55 ` Junio C Hamano
0 siblings, 0 replies; 22+ messages in thread
From: Junio C Hamano @ 2026-08-11 5:55 UTC (permalink / raw)
To: Christian Couder
Cc: git, brian m . carlson, Patrick Steinhardt, Karthik Nayak,
Jeff King, Elijah Newren
Christian Couder <christian.couder@gmail.com> writes:
>> It turns out the reason has nothing to do with your choice of
>> base. It is because the series structure is not understood by 'b4'.
>>
>> The cover letter I am responding to is a reply to another series,
>> but the patches in this round are not marked as 'v2'. This seems
>> to cause 'b4' to grab patches from both series and smash them
>> together, resulting in an inapplicable mess. It seems you cannot
>> have your cake and eat it, too 😠.
>
> I guess b4 should have, or grow, an option for that, because it's not
> uncommon that someone would post an alternative patch or patch series
> in reply to some patch(es).
There is an option that tells it not to crawl up the parent article
to find siblings, and it would have worked fine in this case, but
then it would prevent us from noticing that a newer iteration
exists.
But it should not be the norm.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 0/5] Introduce 'uploadpack.lazyFetchTrusted'
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (5 preceding siblings ...)
2026-08-07 18:31 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Junio C Hamano
@ 2026-08-13 15:47 ` Christian Couder
2026-08-13 15:47 ` [PATCH v2 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
` (4 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-13 15:47 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder
Recently the "promisor-remote" capability was added to protocol v2,
allowing servers and clients to agree on the promisor remotes they can
safely use.
The more servers use promisor remotes, the more it is important to
properly control if they can lazy fetch when responding to a clone or
fetch request from the client.
For example, in the context of large object promisors (see
"Documentation/technical/large-object-promisors.adoc"), if a client
clones with a filter set to 100kB while the server has moved all of
the blobs >= 10kB to a promisor remote, the server will not be able to
provide blobs between 10kB and 100kB to the client, which will make
the clone fail.
Even if the `--filter=auto` option is available since ef2f1845ec
(fetch-pack: wire up and enable auto filter logic, 2026-02-16) it's
still a good idea to provide more control over lazy fetching on the
server side to server operators, as lazy fetching on the server side
could be useful in corporate environments.
Since 7b70e9efb1 (upload-pack: disable lazy-fetching by default,
2024-04-16), lazy fetching has been controlled by the
`GIT_NO_LAZY_FETCH` environment variable. This is a boolean that is
set to 'true' by default when calling `git upload-pack` for security
reasons.
The main security issue on the server side is making sure the served
repo itself is also trusted, as lazily fetching runs `git fetch`,
which may execute arbitrary commands specified in the configuration
and hooks of the served repo. The operator of the server should decide
and mark that trust, not the served repo itself, nor the client.
This series introduces a new 'uploadpack.lazyFetchTrusted' protected
configuration variable similar to 'safe.directory' (see
"Documentation/config/safe.adoc") to mark trusted repos where lazy
fetching is allowed. As it is protected, this config variable will
only take effect if it is set in global or system scope, so only
server operators can control it.
Previous related work
=====================
A previous series called "Introduce a 'fromAccepted' option to
GIT_NO_LAZY_FETCH" [1] took a different approach as it wanted to make
it easier to allow lazy fetching from accepted promisor remotes. But
after brian replied that he didn't think it was a good idea, and after
thinking about this more, my opinion now is that some promisor remotes
being accepted or not is not really relevant to the issue.
In my reply to brian, I said:
"""
Different features could be developed (in future work) to improve on
the current state:
- a way for lazy fetching to work without reading config files,
triggering hooks, or doing potentially sensitive things,
- an explicit way for operators to mark trusted repos (like
perhaps a server-side config the operator sets per-repo),
- operator-defined allow/deny rules, or maybe
- some ways/scripts/commands to scan repos and check configuration
information, remote settings and everything potentially sensitive to
decide if a repo looks safe enough to allow lazy fetching or not.
"""
So I decided to go with "an explicit way for operators to mark trusted
repos" and this series is an implementation of that.
Note that the feature developed in this series applies to protocol
v0/v1 as well as v2 while the previous one was only related to v2.
[1]: https://lore.kernel.org/git/CAP8UFD0_S9eg_w42tcNRnT9E2ntLr_eHLnzE4c2dSu67DzZoXg@mail.gmail.com/
Overview of the patches
=======================
- Patch 1/5 is the only patch saved from the "Introduce a
'fromAccepted' option to GIT_NO_LAZY_FETCH" series. It's not
necessary for the rest of this series and its main feature to
work, but I think it's a nice refactoring related to lazy
fetching, so it might as well be part of this series. There is a
small change in the commit message (to not mention following
commits) compared to the version in the previous series.
- Patches 2/5 and 3/5 extract and modify code used by the
'safe.directory' config variable in a path_allowlist_apply()
function, so that this function can be reused to process
'uploadpack.lazyFetchTrusted' in the next patch.
- Patch 4/5 actually uses path_allowlist_apply() from a new
upload_pack_lazy_fetch_trusted() function to process
'uploadpack.lazyFetchTrusted', but the result from that processing
isn't actually used to have a practical effect.
- Patch 5/5 wires up the new upload_pack_lazy_fetch_trusted()
function to decide if lazy fetching can actually be enabled.
Changes since v1
================
The only change is that the Signed-off-by email address has been fixed
to "christian.couder@gmail.com", which is my primary address in
".mailmap" since 6375b40aea (mailmap: change primary address for
Christian Couder, 2026-08-03).
This version is also sent as a separate 'v2' iteration in reply to v1,
instead of being threaded onto the previous "Introduce a
'fromAccepted' option to GIT_NO_LAZY_FETCH" series, and it now
contains a 'base-commit' trailer, so that 'b4' and other tools can
find the right base and the right patches.
CI tests
========
I didn't run them as only commit messages changed since v1.
Range diff with v1
==================
1: b5b0836d19 ! 1: 1605740203 promisor-remote: factor out lazy_fetch_objects()
@@ Commit message
'bool' instead of 'int', as it just returns whether all the objects
could be fetched, and document its return value.
- Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
+ Signed-off-by: Christian Couder <christian.couder@gmail.com>
## promisor-remote.c ##
@@ promisor-remote.c: static int fetch_objects(struct repository *repo,
2: 879e3a34e3 ! 2: 5f226b6508 setup: extract path_allowlist_apply()
@@ Commit message
While at it let's make the helper's code simpler and more generic.
- Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
+ Signed-off-by: Christian Couder <christian.couder@gmail.com>
## setup.c ##
@@ setup.c: static int canonicalize_ceiling_entry(struct string_list_item *item,
3: 98431ab7b3 ! 3: 051aa11fc9 setup: add 'allow_dot' arg to path_allowlist_apply()
@@ Commit message
While at it let's document it properly in "setup.h".
- Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
+ Signed-off-by: Christian Couder <christian.couder@gmail.com>
## setup.c ##
@@ setup.c: static int canonicalize_ceiling_entry(struct string_list_item *item,
4: a46f4c1bb8 ! 4: 045b5e647b upload-pack: read uploadpack.lazyFetchTrusted
@@ Commit message
Note that the new config variable should be read only from protected
configuration files.
- Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
+ Signed-off-by: Christian Couder <christian.couder@gmail.com>
## upload-pack.c ##
@@
5: 4063f233aa ! 5: c116661202 builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo
@@ Commit message
Now that "uploadpack.lazyFetchTrusted" is actually doing something,
let's document it and reference it from GIT_NO_LAZY_FETCH's docs.
- Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
+ Signed-off-by: Christian Couder <christian.couder@gmail.com>
## Documentation/config/uploadpack.adoc ##
@@ Documentation/config/uploadpack.adoc: uploadpack.allowRefInWant::
Christian Couder (5):
promisor-remote: factor out lazy_fetch_objects()
setup: extract path_allowlist_apply()
setup: add 'allow_dot' arg to path_allowlist_apply()
upload-pack: read uploadpack.lazyFetchTrusted
builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo
Documentation/config/uploadpack.adoc | 42 ++++++++++
Documentation/git-upload-pack.adoc | 5 ++
Documentation/git.adoc | 4 +-
builtin/upload-pack.c | 11 +++
promisor-remote.c | 76 ++++++++++--------
setup.c | 108 ++++++++++++++------------
setup.h | 28 +++++++
t/t5710-promisor-remote-capability.sh | 70 +++++++++++++++++
upload-pack.c | 37 +++++++++
upload-pack.h | 3 +
10 files changed, 304 insertions(+), 80 deletions(-)
base-commit: 745601a9a94110d74769ab605ccd4f61339758d2
--
2.55.0.565.gc116661202
^ permalink raw reply [flat|nested] 22+ messages in thread* [PATCH v2 1/5] promisor-remote: factor out lazy_fetch_objects()
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (6 preceding siblings ...)
2026-08-13 15:47 ` [PATCH v2 " Christian Couder
@ 2026-08-13 15:47 ` Christian Couder
2026-08-13 15:47 ` [PATCH v2 2/5] setup: extract path_allowlist_apply() Christian Couder
` (3 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-13 15:47 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder
In "promisor-remote.c:fetch_objects()", there is a check to disable
lazy fetching when the `GIT_NO_LAZY_FETCH` environment variable is
set. The fetch_objects() function is called once per promisor remote
though. So the check might be performed more times than necessary.
Also promisor_remote_get_direct() mixes up the logic deciding which
promisor remotes to try with the logic checking that the objects
that could not be fetched are promisor objects.
Let's refactor the lazy fetching logic out of these two functions
into a new lazy_fetch_objects() function.
This is a pure refactoring with no intended behavior change. Two
things shift in ways that are observably equivalent though:
- the `GIT_NO_LAZY_FETCH` check is now performed once up front,
instead of once per promisor remote, and
- promisor_remote_init() is no longer called when lazy fetching
is disabled, which is fine as nothing downstream of it, like
is_promisor_object(), needs it in that case.
While at it, let's also convert try_promisor_remotes() to return
'bool' instead of 'int', as it just returns whether all the objects
could be fetched, and document its return value.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
promisor-remote.c | 76 ++++++++++++++++++++++++++++-------------------
1 file changed, 45 insertions(+), 31 deletions(-)
diff --git a/promisor-remote.c b/promisor-remote.c
index 43505d1e1a..65496c69cf 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -31,15 +31,6 @@ static int fetch_objects(struct repository *repo,
FILE *child_in;
int quiet;
- if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) {
- static int warning_shown;
- if (!warning_shown) {
- warning_shown = 1;
- warning(_("lazy fetching disabled; some objects may not be available"));
- }
- return -1;
- }
-
child.git_cmd = 1;
child.in = -1;
if (repo != the_repository)
@@ -270,10 +261,15 @@ static int remove_fetched_oids(struct repository *repo,
return remaining_nr;
}
-static int try_promisor_remotes(struct repository *repo,
- struct object_id **remaining_oids,
- int *remaining_nr, int *to_free,
- bool accepted_only)
+/*
+ * Return 'true' if all the objects could be fetched from the
+ * (non-)accepted remotes, 'false' otherwise.
+ */
+static bool try_promisor_remotes(struct repository *repo,
+ struct object_id **remaining_oids,
+ int *remaining_nr,
+ int *to_free,
+ bool accepted_only)
{
struct promisor_remote *r = repo->promisor_remote_config->promisors;
@@ -290,9 +286,37 @@ static int try_promisor_remotes(struct repository *repo,
continue;
}
}
- return 1; /* all fetched */
+ return true; /* all fetched */
}
- return 0;
+ return false;
+}
+
+/*
+ * Return 'true' if all the objects could be fetched, 'false' otherwise.
+ */
+static bool lazy_fetch_objects(struct repository *repo,
+ struct object_id **remaining_oids,
+ int *remaining_nr,
+ int *to_free)
+{
+ if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) {
+ static int warning_shown;
+ if (!warning_shown) {
+ warning_shown = 1;
+ warning(_("lazy fetching disabled; some objects may not be available"));
+ }
+ return false;
+ }
+
+ promisor_remote_init(repo);
+
+ /* Try accepted remotes first (those the server told us to use) */
+ if (try_promisor_remotes(repo, remaining_oids, remaining_nr,
+ to_free, true))
+ return true;
+
+ return try_promisor_remotes(repo, remaining_oids, remaining_nr,
+ to_free, false);
}
void promisor_remote_get_direct(struct repository *repo,
@@ -302,28 +326,18 @@ void promisor_remote_get_direct(struct repository *repo,
struct object_id *remaining_oids = (struct object_id *)oids;
int remaining_nr = oid_nr;
int to_free = 0;
- int i;
if (oid_nr == 0)
return;
- promisor_remote_init(repo);
-
- /* Try accepted remotes first (those the server told us to use) */
- if (try_promisor_remotes(repo, &remaining_oids, &remaining_nr,
- &to_free, true))
- goto all_fetched;
- if (try_promisor_remotes(repo, &remaining_oids, &remaining_nr,
- &to_free, false))
- goto all_fetched;
-
- for (i = 0; i < remaining_nr; i++) {
- if (is_promisor_object(repo, &remaining_oids[i]))
- die(_("could not fetch %s from promisor remote"),
- oid_to_hex(&remaining_oids[i]));
+ if (!lazy_fetch_objects(repo, &remaining_oids, &remaining_nr, &to_free)) {
+ for (int i = 0; i < remaining_nr; i++) {
+ if (is_promisor_object(repo, &remaining_oids[i]))
+ die(_("could not fetch %s from promisor remote"),
+ oid_to_hex(&remaining_oids[i]));
+ }
}
-all_fetched:
if (to_free)
free(remaining_oids);
}
--
2.55.0.565.gc116661202
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH v2 2/5] setup: extract path_allowlist_apply()
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (7 preceding siblings ...)
2026-08-13 15:47 ` [PATCH v2 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
@ 2026-08-13 15:47 ` Christian Couder
2026-08-13 15:47 ` [PATCH v2 3/5] setup: add 'allow_dot' arg to path_allowlist_apply() Christian Couder
` (2 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-13 15:47 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder
In a following commit we are going to check whether a repository is
part of an allowlist specified in a config variable.
To prepare for that let's extract existing code from
safe_directory_cb() into a new path_allowlist_apply() helper that will
help with such checks.
While at it let's make the helper's code simpler and more generic.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
setup.c | 107 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 59 insertions(+), 48 deletions(-)
diff --git a/setup.c b/setup.c
index 95909e9603..39dfa1cc5f 100644
--- a/setup.c
+++ b/setup.c
@@ -1339,6 +1339,64 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
}
}
+static void path_allowlist_apply(const char *key, const char *value,
+ const char *target_path, int *is_match)
+{
+ char *allowed = NULL;
+ char *normalized = NULL;
+
+ if (!value || !*value) {
+ *is_match = 0;
+ return;
+ }
+
+ if (!strcmp(value, "*")) {
+ *is_match = 1;
+ return;
+ }
+
+ if (git_config_pathname(&allowed, key, value) || !allowed)
+ return;
+
+ /*
+ * Setting the config variable to a non-absolute path makes
+ * little sense---it won't be relative to the configuration
+ * file the item is defined in. Except for ".", which means
+ * "if we are at the top level of a repository, then it is
+ * OK", which is slightly tighter than "*" that allows
+ * discovery.
+ */
+ if (!is_absolute_path(allowed) && strcmp(allowed, ".")) {
+ warning(_("%s '%s' not absolute"), key, allowed);
+ goto end;
+ }
+
+ /*
+ * A .gitconfig in $HOME may be shared across different
+ * machines and the config variable entries may or may not
+ * exist as paths on all of these machines. In other words,
+ * it is not a warning worthy event when there is no such path
+ * on this machine---the entry may be useful elsewhere.
+ */
+ normalized = real_pathdup(allowed, 0);
+ if (!normalized)
+ goto end;
+
+ if (ends_with(normalized, "/*")) {
+ size_t len = strlen(normalized);
+ if (!fspathncmp(normalized, target_path, len - 1))
+ *is_match = 1;
+ goto end;
+ }
+
+ if (!fspathcmp(target_path, normalized))
+ *is_match = 1;
+
+end:
+ free(normalized);
+ free(allowed);
+}
+
struct safe_directory_data {
char *path;
int is_safe;
@@ -1352,54 +1410,7 @@ static int safe_directory_cb(const char *key, const char *value,
if (strcmp(key, "safe.directory"))
return 0;
- if (!value || !*value) {
- data->is_safe = 0;
- } else if (!strcmp(value, "*")) {
- data->is_safe = 1;
- } else {
- char *allowed = NULL;
-
- if (!git_config_pathname(&allowed, key, value) && allowed) {
- char *normalized = NULL;
-
- /*
- * Setting safe.directory to a non-absolute path
- * makes little sense---it won't be relative to
- * the configuration file the item is defined in.
- * Except for ".", which means "if we are at the top
- * level of a repository, then it is OK", which is
- * slightly tighter than "*" that allows discovery.
- */
- if (!is_absolute_path(allowed) && strcmp(allowed, ".")) {
- warning(_("safe.directory '%s' not absolute"),
- allowed);
- goto next;
- }
-
- /*
- * A .gitconfig in $HOME may be shared across
- * different machines and safe.directory entries
- * may or may not exist as paths on all of these
- * machines. In other words, it is not a warning
- * worthy event when there is no such path on this
- * machine---the entry may be useful elsewhere.
- */
- normalized = real_pathdup(allowed, 0);
- if (!normalized)
- goto next;
-
- if (ends_with(normalized, "/*")) {
- size_t len = strlen(normalized);
- if (!fspathncmp(normalized, data->path, len - 1))
- data->is_safe = 1;
- } else if (!fspathcmp(data->path, normalized)) {
- data->is_safe = 1;
- }
- next:
- free(normalized);
- free(allowed);
- }
- }
+ path_allowlist_apply(key, value, data->path, &data->is_safe);
return 0;
}
--
2.55.0.565.gc116661202
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH v2 3/5] setup: add 'allow_dot' arg to path_allowlist_apply()
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (8 preceding siblings ...)
2026-08-13 15:47 ` [PATCH v2 2/5] setup: extract path_allowlist_apply() Christian Couder
@ 2026-08-13 15:47 ` Christian Couder
2026-08-13 15:47 ` [PATCH v2 4/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
2026-08-13 15:47 ` [PATCH v2 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-13 15:47 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder
A previous commit created path_allowlist_apply() with the goal of later
reusing that function. But when it will be reused in a following commit
this function will need to reject non-absolute paths including those
with a single dot that are currently accepted.
To prepare for reusing path_allowlist_apply(), let's add a
`bool allow_dot` argument to it, and let's export this function.
While at it let's document it properly in "setup.h".
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
setup.c | 9 +++++----
setup.h | 28 ++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/setup.c b/setup.c
index 39dfa1cc5f..a09e697e3a 100644
--- a/setup.c
+++ b/setup.c
@@ -1339,8 +1339,9 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
}
}
-static void path_allowlist_apply(const char *key, const char *value,
- const char *target_path, int *is_match)
+void path_allowlist_apply(const char *key, const char *value,
+ const char *target_path, int *is_match,
+ bool allow_dot)
{
char *allowed = NULL;
char *normalized = NULL;
@@ -1366,7 +1367,7 @@ static void path_allowlist_apply(const char *key, const char *value,
* OK", which is slightly tighter than "*" that allows
* discovery.
*/
- if (!is_absolute_path(allowed) && strcmp(allowed, ".")) {
+ if (!is_absolute_path(allowed) && (!allow_dot || strcmp(allowed, "."))) {
warning(_("%s '%s' not absolute"), key, allowed);
goto end;
}
@@ -1410,7 +1411,7 @@ static int safe_directory_cb(const char *key, const char *value,
if (strcmp(key, "safe.directory"))
return 0;
- path_allowlist_apply(key, value, data->path, &data->is_safe);
+ path_allowlist_apply(key, value, data->path, &data->is_safe, true);
return 0;
}
diff --git a/setup.h b/setup.h
index 654f10e059..d4f8af5457 100644
--- a/setup.h
+++ b/setup.h
@@ -304,4 +304,32 @@ struct startup_info {
extern struct startup_info *startup_info;
extern const char *tmp_original_cwd;
+/*
+ * Apply the path allowlist in 'value' against 'target_path' setting
+ * '*is_match' accordingly.
+ *
+ * `value` is the value of a multi-valued config variable named `key`
+ * that holds an allowlist of paths. `target_path` is the (normalized)
+ * path being tested. `*is_match` is updated in place:
+ *
+ * - an empty value resets it to 0 (so a later, more specific config
+ * scope can clear entries from a broader one),
+ * - "*" sets it to 1 (allow everything),
+ * - "<path>" sets it to 1 if <path> equals `target_path`,
+ * - "<path>" + "/" + "*" sets it to 1 if <path> is a leading
+ * directory of `target_path`,
+ * - any other (unmatching) value leaves `*is_match` unchanged.
+ *
+ * Non-absolute values are rejected with a warning, except "." when
+ * `allow_dot` is set (used by 'safe.directory' to mean "the top level
+ * of the current repository").
+ *
+ * Callers are expected to invoke this once per config value,
+ * typically from a protected-config callback, so that untrusted
+ * repository config cannot influence the decision.
+ */
+void path_allowlist_apply(const char *key, const char *value,
+ const char *target_path, int *is_match,
+ bool allow_dot);
+
#endif /* SETUP_H */
--
2.55.0.565.gc116661202
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH v2 4/5] upload-pack: read uploadpack.lazyFetchTrusted
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (9 preceding siblings ...)
2026-08-13 15:47 ` [PATCH v2 3/5] setup: add 'allow_dot' arg to path_allowlist_apply() Christian Couder
@ 2026-08-13 15:47 ` Christian Couder
2026-08-13 15:47 ` [PATCH v2 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-13 15:47 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder
Previous commits created and prepared the path_allowlist_apply()
function.
Let's reuse this function for a new "uploadpack.lazyFetchTrusted"
configuration variable.
It allows us to:
- read an allowlist from that config variable,
- check if the current repo is in that list, and
- return the result from a new upload_pack_lazy_fetch_trusted()
function.
The new function will be used in a following commit.
Note that the new config variable should be read only from protected
configuration files.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
upload-pack.c | 37 +++++++++++++++++++++++++++++++++++++
upload-pack.h | 3 +++
2 files changed, 40 insertions(+)
diff --git a/upload-pack.c b/upload-pack.c
index a52856d869..29e700e43b 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -34,6 +34,8 @@
#include "json-writer.h"
#include "strmap.h"
#include "promisor-remote.h"
+#include "setup.h"
+#include "abspath.h"
/* Remember to update object flag allocation in object.h */
#define THEY_HAVE (1u << 11)
@@ -1378,6 +1380,41 @@ static int upload_pack_config(const char *var, const char *value,
return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs);
}
+struct lazy_fetch_trusted {
+ int trusted;
+ char *repo_path;
+};
+
+static int upload_pack_protected_lazy_fetch_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
+{
+ struct lazy_fetch_trusted *data = cb_data;
+
+ if (!strcmp("uploadpack.lazyfetchtrusted", var)) {
+ path_allowlist_apply(var, value, data->repo_path,
+ &data->trusted, false);
+ return 0;
+ }
+
+ return 0;
+}
+
+bool upload_pack_lazy_fetch_trusted(struct repository *r)
+{
+ struct lazy_fetch_trusted data = { 0 };
+
+ data.repo_path = real_pathdup(r->worktree ? r->worktree : r->gitdir, 0);
+ if (!data.repo_path)
+ return false;
+
+ git_protected_config(upload_pack_protected_lazy_fetch_config, &data);
+
+ free(data.repo_path);
+
+ return !!data.trusted;
+}
+
static int upload_pack_protected_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
void *cb_data)
diff --git a/upload-pack.h b/upload-pack.h
index d6ee25ea98..b2212992c3 100644
--- a/upload-pack.h
+++ b/upload-pack.h
@@ -12,4 +12,7 @@ struct strbuf;
int upload_pack_advertise(struct repository *r,
struct strbuf *value);
+/* Is this repo trusted for lazy fetching? */
+bool upload_pack_lazy_fetch_trusted(struct repository *r);
+
#endif /* UPLOAD_PACK_H */
--
2.55.0.565.gc116661202
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH v2 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
` (10 preceding siblings ...)
2026-08-13 15:47 ` [PATCH v2 4/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
@ 2026-08-13 15:47 ` Christian Couder
11 siblings, 0 replies; 22+ messages in thread
From: Christian Couder @ 2026-08-13 15:47 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, brian m . carlson, Patrick Steinhardt,
Karthik Nayak, Jeff King, Elijah Newren, Christian Couder
A previous commit added a new "uploadpack.lazyFetchTrusted" protected
config variable that can contain an allowlist of repos, as well as
functions to check if the current repo is in that list. But when the
current repo is in that list, we currently do nothing.
Let's instead set `GIT_NO_LAZY_FETCH` to `0`, which allows
`upload-pack` and its `pack-objects` child process to lazily fetch the
objects they need to serve a client, for example when the filter used
by the client and the one used by the server don't match.
This allows server operators to properly control lazy fetching. It is
their responsibility, not the client's, to decide if the served repo is
trusted, as the main security issue is that lazily fetching runs `git
fetch`, which may execute arbitrary commands specified in the
configuration and hooks of the served repo.
As `GIT_NO_LAZY_FETCH` is passed down to child processes through the
environment, this works for `pack-objects`, which performs the lazy
fetch when serving a client, without any further plumbing.
Now that "uploadpack.lazyFetchTrusted" is actually doing something,
let's document it and reference it from GIT_NO_LAZY_FETCH's docs.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
Documentation/config/uploadpack.adoc | 42 ++++++++++++++++
Documentation/git-upload-pack.adoc | 5 ++
Documentation/git.adoc | 4 +-
builtin/upload-pack.c | 11 +++++
t/t5710-promisor-remote-capability.sh | 70 +++++++++++++++++++++++++++
5 files changed, 131 insertions(+), 1 deletion(-)
diff --git a/Documentation/config/uploadpack.adoc b/Documentation/config/uploadpack.adoc
index 0e1dda944a..e960879c16 100644
--- a/Documentation/config/uploadpack.adoc
+++ b/Documentation/config/uploadpack.adoc
@@ -86,3 +86,45 @@ uploadpack.allowRefInWant::
is intended for the benefit of load-balanced servers which may
not have the same view of what OIDs their refs point to due to
replication delay.
+
+uploadpack.lazyFetchTrusted::
+ These config entries specify repositories that `upload-pack` is
+ allowed to lazily fetch missing objects for. By default,
+ `upload-pack` refuses to lazily fetch (see the description of the
+ `GIT_NO_LAZY_FETCH` environment variable in
+ linkgit:git-upload-pack[1]), because doing so would run `git fetch`,
+ which may execute arbitrary commands specified in the configuration
+ and hooks of the served repository. Listing a repository here tells
+ `upload-pack` that it is trusted, so lazy fetching from the promisor
+ remotes configured in it is allowed. This is equivalent to setting
+ `GIT_NO_LAZY_FETCH` to `0` for the matching repositories. An
+ explicitly set `GIT_NO_LAZY_FETCH` takes precedence over this
+ setting.
++
+Note that this allows lazy fetching from any promisor remote
+configured in the served repository, not only from the promisor
+remotes that the client accepted using the "promisor-remote" protocol
+v2 capability (see linkgit:gitprotocol-v2[5]). The served repository
+is trusted as a whole, including its configuration, so the promisor
+remotes it configures are trusted too. It is the server operator's
+responsibility to make sure that the promisor remotes of a trusted
+repository are also trustworthy.
++
+This is a multi-valued setting, i.e. you can add more than one
+repository via `git config (--global|--system) --add`. To reset the
+list of trusted repositories (e.g. to override any such repositories
+specified in the system config), add a `uploadpack.lazyFetchTrusted`
+entry with an empty value.
++
+A repository is identified by its worktree, or its git directory for a bare
+repository, and the value must be an absolute path. Giving a path with `/*`
+appended to it will trust all repositories under the named directory. To trust
+all served repositories, set `uploadpack.lazyFetchTrusted` to the string `*`.
++
+The value of this setting is interpolated, i.e. `~/<path>` expands to a
+path relative to the home directory and `%(prefix)/<path>` expands to a
+path relative to Git's (runtime) prefix.
++
+Note that this configuration variable is only respected when it is specified
+in protected configuration (see <<SCOPES>>). This prevents untrusted
+repositories from tampering with this value.
diff --git a/Documentation/git-upload-pack.adoc b/Documentation/git-upload-pack.adoc
index 9167a321d0..90c2ba1194 100644
--- a/Documentation/git-upload-pack.adoc
+++ b/Documentation/git-upload-pack.adoc
@@ -71,6 +71,11 @@ This is implemented by having `upload-pack` internally set the
(because you are fetching from a partial clone, and you are sure
you trust it), you can explicitly set `GIT_NO_LAZY_FETCH` to
`0`.
++
+Instead of setting `GIT_NO_LAZY_FETCH` to `0` in the environment, a
+server operator can allow lazy fetching on a per-repository basis by
+listing trusted repositories in the `uploadpack.lazyFetchTrusted`
+configuration variable. See linkgit:git-config[1].
SECURITY
--------
diff --git a/Documentation/git.adoc b/Documentation/git.adoc
index 8a5cdd3b3d..2e763d1f93 100644
--- a/Documentation/git.adoc
+++ b/Documentation/git.adoc
@@ -949,7 +949,9 @@ for full details.
`GIT_NO_LAZY_FETCH`::
Setting this Boolean environment variable to true tells Git
not to lazily fetch missing objects from the promisor remote
- on demand.
+ on demand. On the server side, the `uploadpack.lazyFetchTrusted`
+ configuration variable can control this per-repository. See
+ linkgit:git-upload-pack[1].
`GIT_REFLOG_ACTION`::
When a ref is updated, reflog entries are created to keep
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index 32831fb879..8b531ca724 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -42,10 +42,13 @@ int cmd_upload_pack(int argc,
OPT_END()
};
unsigned enter_repo_flags = ENTER_REPO_ANY_OWNER_OK;
+ bool no_lazy_fetch_set;
packet_trace_identity("upload-pack");
disable_replace_refs();
save_commit_buffer = 0;
+
+ no_lazy_fetch_set = !!getenv(NO_LAZY_FETCH_ENVIRONMENT);
xsetenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 0);
argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
@@ -62,6 +65,14 @@ int cmd_upload_pack(int argc,
if (!enter_repo(the_repository, dir, enter_repo_flags))
die("'%s' does not appear to be a git repository", dir);
+ /*
+ * Relax the GIT_NO_LAZY_FETCH=1 default if the served repo is in
+ * the "uploadpack.lazyFetchTrusted" protected allowlist and
+ * GIT_NO_LAZY_FETCH was not already set explicitly.
+ */
+ if (!no_lazy_fetch_set && upload_pack_lazy_fetch_trusted(the_repository))
+ xsetenv(NO_LAZY_FETCH_ENVIRONMENT, "0", 1);
+
switch (determine_protocol_version_server()) {
case protocol_v2:
if (advertise_refs)
diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh
index 549acff23f..e6993f2761 100755
--- a/t/t5710-promisor-remote-capability.sh
+++ b/t/t5710-promisor-remote-capability.sh
@@ -173,6 +173,76 @@ test_expect_success "clone with promisor.acceptfromserver set to 'None'" '
initialize_server 1 "$oid"
'
+test_expect_success "clone with uploadpack.lazyFetchTrusted" '
+ # No promisors are advertised
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # The served repo is trusted for lazy fetching
+ test_config_global uploadpack.lazyFetchTrusted "$(pwd)/server" &&
+
+ # Clone without GIT_NO_LAZY_FETCH=0
+ git clone --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is not missing on the server
+ # This means the server lazy fetched it
+ check_missing_objects server 0 "" &&
+
+ # Reinitialize server so that the largest object is missing again
+ initialize_server 1 "$oid"
+'
+
+test_expect_success "clone without uploadpack.lazyFetchTrusted fails" '
+ # No promisors are advertised
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # Note: no uploadpack.lazyFetchTrusted config is set here, so
+ # the served repo is NOT trusted for lazy fetching.
+
+ # Clone without GIT_NO_LAZY_FETCH=0 fails
+ test_must_fail git clone --no-local --filter="blob:limit=5k" server client 2>err &&
+ test_grep "lazy fetching disabled" err &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "uploadpack.lazyFetchTrusted is ignored in repo config" '
+ # No promisors are advertised
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # The served repo is trusted for lazy fetching, but this is
+ # done in the repo config, not in protected config, so this is
+ # ignored.
+ test_config -C server uploadpack.lazyFetchTrusted "$(pwd)/server" &&
+
+ # Clone without GIT_NO_LAZY_FETCH=0 fails
+ test_must_fail git clone --no-local --filter="blob:limit=5k" server client 2>err &&
+ test_grep "lazy fetching disabled" err &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "explicit GIT_NO_LAZY_FETCH overrides uploadpack.lazyFetchTrusted" '
+ # No promisors are advertised
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # The served repo is trusted for lazy fetching
+ test_config_global uploadpack.lazyFetchTrusted "$(pwd)/server" &&
+
+ # But GIT_NO_LAZY_FETCH=1 disables lazy fetching, so clone fails
+ test_must_fail env GIT_NO_LAZY_FETCH=1 git clone --no-local \
+ --filter="blob:limit=5k" server client 2>err &&
+ test_grep "lazy fetching disabled" err &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
test_expect_success "init + fetch with promisor.advertise set to 'true'" '
git -C server config promisor.advertise true &&
test_when_finished "rm -rf client" &&
--
2.55.0.565.gc116661202
^ permalink raw reply related [flat|nested] 22+ messages in thread