@matheusbsbs / matheus-bagliano / commits / 6476b38b1f
Fork 0

replace: use a GIT_NO_REPLACE_OBJECTS env variable

This has the same effect as --no-replace-objects option; git ignores the replace refs. When --no-replace-objects option is passed to git, this environment variable is set to "1" and exported to subprocesses in order to propagate the same setting. It is useful for example for scripts, as the git commands used in them can now be aware that they must not read replace refs. Tested-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Nov 18, 2009 at 07:50 UTC 6476b38b1f3d258006566c3c9c6c80cc07fda354
5 files changed +24
cache.h
+1
@@ -369,6 +369,7 @@ static inline enum object_type object_type(unsigned int mode)
369 #define CONFIG_ENVIRONMENT "GIT_CONFIG"
370 #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
371 #define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
372 +#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
373 #define GITATTRIBUTES_FILE ".gitattributes"
374 #define INFOATTRIBUTES_FILE "info/attributes"
375 #define ATTRIBUTE_MACRO_PREFIX "[attr]"
connect.c
+1
@@ -630,6 +630,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
630 GIT_WORK_TREE_ENVIRONMENT,
631 GRAFT_ENVIRONMENT,
632 INDEX_ENVIRONMENT,
633 + NO_REPLACE_OBJECTS_ENVIRONMENT,
634 NULL
635 };
636 conn->env = env;
environment.c
+2
@@ -83,6 +83,8 @@ static void setup_git_env(void)
83 git_graft_file = getenv(GRAFT_ENVIRONMENT);
84 if (!git_graft_file)
85 git_graft_file = git_pathdup("info/grafts");
86 + if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
87 + read_replace_refs = 0;
88 }
89
90 int is_bare_repository(void)
git.c
+3
@@ -89,6 +89,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
89 *envchanged = 1;
90 } else if (!strcmp(cmd, "--no-replace-objects")) {
91 read_replace_refs = 0;
92 + setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
93 + if (envchanged)
94 + *envchanged = 1;
95 } else if (!strcmp(cmd, "--git-dir")) {
96 if (*argc < 2) {
97 fprintf(stderr, "No directory given for --git-dir.\n" );
t/t6050-replace.sh
+17
@@ -77,6 +77,11 @@ test_expect_success 'test --no-replace-objects option' '
77 git --no-replace-objects show $HASH2 | grep "A U Thor"
78 '
79
80 +test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' '
81 + GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 | grep "author A U Thor" &&
82 + GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor"
83 +'
84 +
85 cat >tag.sig <<EOF
86 object $HASH2
87 type commit
@@ -202,6 +207,18 @@ test_expect_success 'fetch branch with replacement' '
207 cd ..
208 '
209
210 +test_expect_success 'bisect and replacements' '
211 + git bisect start $HASH7 $HASH1 &&
212 + test "$S" = "$(git rev-parse --verify HEAD)" &&
213 + git bisect reset &&
214 + GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 &&
215 + test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
216 + git bisect reset &&
217 + git --no-replace-objects bisect start $HASH7 $HASH1 &&
218 + test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
219 + git bisect reset
220 +'
221 +
222 #
223 #
224 test_done