Skip to content

Commit 2c206fc

Browse files
committed
Merge branch 'jc/no-lazy-fetch'
"git --no-lazy-fetch cmd" allows to run "cmd" while disabling lazy fetching of objects from the promisor remote, which may be handy for debugging. * jc/no-lazy-fetch: git: extend --no-lazy-fetch to work across subprocesses git: document GIT_NO_REPLACE_OBJECTS environment variable git: --no-lazy-fetch option
2 parents 43072b4 + e6d5479 commit 2c206fc

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

Documentation/git.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,17 @@ If you just want to run git as if it was started in `<path>` then use
174174
directory.
175175

176176
--no-replace-objects::
177-
Do not use replacement refs to replace Git objects. See
178-
linkgit:git-replace[1] for more information.
177+
Do not use replacement refs to replace Git objects.
178+
This is equivalent to exporting the `GIT_NO_REPLACE_OBJECTS`
179+
environment variable with any value.
180+
See linkgit:git-replace[1] for more information.
181+
182+
--no-lazy-fetch::
183+
Do not fetch missing objects from the promisor remote on
184+
demand. Useful together with `git cat-file -e <object>` to
185+
see if the object is locally available.
186+
This is equivalent to setting the `GIT_NO_LAZY_FETCH`
187+
environment variable to `1`.
179188

180189
--literal-pathspecs::
181190
Treat pathspecs literally (i.e. no globbing, no pathspec magic).
@@ -872,6 +881,10 @@ for full details.
872881
header and packfile URIs. Set this Boolean environment variable to false to prevent this
873882
redaction.
874883

884+
`GIT_NO_REPLACE_OBJECTS`::
885+
Setting and exporting this environment variable tells Git to
886+
ignore replacement refs and do not replace Git objects.
887+
875888
`GIT_LITERAL_PATHSPECS`::
876889
Setting this Boolean environment variable to true will cause Git to treat all
877890
pathspecs literally, rather than as glob patterns. For example,
@@ -893,6 +906,11 @@ for full details.
893906
Setting this Boolean environment variable to true will cause Git to treat all
894907
pathspecs as case-insensitive.
895908

909+
`GIT_NO_LAZY_FETCH`::
910+
Setting this Boolean environment variable to true tells Git
911+
not to lazily fetch missing objects from the promisor remote
912+
on demand.
913+
896914
`GIT_REFLOG_ACTION`::
897915
When a ref is updated, reflog entries are created to keep
898916
track of the reason why the ref was updated (which is

environment.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ void setup_git_env(const char *git_dir)
207207
shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
208208
if (shallow_file)
209209
set_alternate_shallow_file(the_repository, shallow_file, 0);
210+
211+
if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0))
212+
fetch_if_missing = 0;
210213
}
211214

212215
int is_bare_repository(void)

environment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const char *getenv_safe(struct strvec *argv, const char *name);
3636
#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
3737
#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
3838
#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE"
39+
#define NO_LAZY_FETCH_ENVIRONMENT "GIT_NO_LAZY_FETCH"
3940
#define GITATTRIBUTES_FILE ".gitattributes"
4041
#define INFOATTRIBUTES_FILE "info/attributes"
4142
#define ATTRIBUTE_MACRO_PREFIX "[attr]"

git.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "exec-cmd.h"
55
#include "gettext.h"
66
#include "help.h"
7+
#include "object-file.h"
78
#include "pager.h"
89
#include "read-cache-ll.h"
910
#include "run-command.h"
@@ -186,6 +187,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
186187
use_pager = 0;
187188
if (envchanged)
188189
*envchanged = 1;
190+
} else if (!strcmp(cmd, "--no-lazy-fetch")) {
191+
fetch_if_missing = 0;
192+
setenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 1);
193+
if (envchanged)
194+
*envchanged = 1;
189195
} else if (!strcmp(cmd, "--no-replace-objects")) {
190196
disable_replace_refs();
191197
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);

t/t0410-partial-clone.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,21 @@ test_expect_success 'lazy-fetch when accessing object not in the_repository' '
665665
git -C partial.git rev-list --objects --missing=print HEAD >out &&
666666
grep "[?]$FILE_HASH" out &&
667667
668+
# The no-lazy-fetch mechanism prevents Git from fetching
669+
test_must_fail env GIT_NO_LAZY_FETCH=1 \
670+
git -C partial.git cat-file -e "$FILE_HASH" &&
671+
672+
# The same with command line option to "git"
673+
test_must_fail git --no-lazy-fetch -C partial.git cat-file -e "$FILE_HASH" &&
674+
675+
# The same, forcing a subprocess via an alias
676+
test_must_fail git --no-lazy-fetch -C partial.git \
677+
-c alias.foo="!git cat-file" foo -e "$FILE_HASH" &&
678+
679+
# Sanity check that the file is still missing
680+
git -C partial.git rev-list --objects --missing=print HEAD >out &&
681+
grep "[?]$FILE_HASH" out &&
682+
668683
git -C full cat-file -s "$FILE_HASH" >expect &&
669684
test-tool partial-clone object-info partial.git "$FILE_HASH" >actual &&
670685
test_cmp expect actual &&

0 commit comments

Comments
 (0)