Skip to content

Commit

Permalink
replace: use a GIT_NO_REPLACE_OBJECTS env variable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christian Couder authored and Junio C Hamano committed Nov 21, 2009
1 parent e36e6c0 commit 6476b38
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ static inline enum object_type object_type(unsigned int mode)
#define CONFIG_ENVIRONMENT "GIT_CONFIG"
#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
#define GITATTRIBUTES_FILE ".gitattributes"
#define INFOATTRIBUTES_FILE "info/attributes"
#define ATTRIBUTE_MACRO_PREFIX "[attr]"
Expand Down
1 change: 1 addition & 0 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
GIT_WORK_TREE_ENVIRONMENT,
GRAFT_ENVIRONMENT,
INDEX_ENVIRONMENT,
NO_REPLACE_OBJECTS_ENVIRONMENT,
NULL
};
conn->env = env;
Expand Down
2 changes: 2 additions & 0 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ static void setup_git_env(void)
git_graft_file = getenv(GRAFT_ENVIRONMENT);
if (!git_graft_file)
git_graft_file = git_pathdup("info/grafts");
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
read_replace_refs = 0;
}

int is_bare_repository(void)
Expand Down
3 changes: 3 additions & 0 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--no-replace-objects")) {
read_replace_refs = 0;
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--git-dir")) {
if (*argc < 2) {
fprintf(stderr, "No directory given for --git-dir.\n" );
Expand Down
17 changes: 17 additions & 0 deletions t/t6050-replace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ test_expect_success 'test --no-replace-objects option' '
git --no-replace-objects show $HASH2 | grep "A U Thor"
'

test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' '
GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 | grep "author A U Thor" &&
GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor"
'

cat >tag.sig <<EOF
object $HASH2
type commit
Expand Down Expand Up @@ -202,6 +207,18 @@ test_expect_success 'fetch branch with replacement' '
cd ..
'

test_expect_success 'bisect and replacements' '
git bisect start $HASH7 $HASH1 &&
test "$S" = "$(git rev-parse --verify HEAD)" &&
git bisect reset &&
GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 &&
test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
git bisect reset &&
git --no-replace-objects bisect start $HASH7 $HASH1 &&
test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
git bisect reset
'

#
#
test_done

0 comments on commit 6476b38

Please sign in to comment.