Skip to content

Commit 783cfaf

Browse files
committed
Merge branch 'cc/replace'
* cc/replace: Documentation: talk a little bit about GIT_NO_REPLACE_OBJECTS Documentation: fix typos and spelling in replace documentation replace: use a GIT_NO_REPLACE_OBJECTS env variable
2 parents 75a7ea2 + 0de8b94 commit 783cfaf

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

Documentation/git-replace.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,35 @@ DESCRIPTION
1717
Adds a 'replace' reference in `.git/refs/replace/`
1818

1919
The name of the 'replace' reference is the SHA1 of the object that is
20-
replaced. The content of the replace reference is the SHA1 of the
20+
replaced. The content of the 'replace' reference is the SHA1 of the
2121
replacement object.
2222

23-
Unless `-f` is given, the replace reference must not yet exist in
23+
Unless `-f` is given, the 'replace' reference must not yet exist in
2424
`.git/refs/replace/` directory.
2525

26-
Replace references will be used by default by all git commands except
27-
those doing reachability traversal (prune, pack transfer and fsck).
26+
Replacement references will be used by default by all git commands
27+
except those doing reachability traversal (prune, pack transfer and
28+
fsck).
2829

29-
It is possible to disable use of replacement refs for any command
30-
using the --no-replace-objects option just after "git".
30+
It is possible to disable use of replacement references for any
31+
command using the `--no-replace-objects` option just after 'git'.
3132

32-
For example if commit "foo" has been replaced by commit "bar":
33+
For example if commit 'foo' has been replaced by commit 'bar':
3334

3435
------------------------------------------------
35-
$ git --no-replace-object cat-file commit foo
36+
$ git --no-replace-objects cat-file commit foo
3637
------------------------------------------------
3738

38-
show information about commit "foo", while:
39+
shows information about commit 'foo', while:
3940

4041
------------------------------------------------
4142
$ git cat-file commit foo
4243
------------------------------------------------
4344

44-
show information about commit "bar".
45+
shows information about commit 'bar'.
46+
47+
The 'GIT_NO_REPLACE_OBJECTS' environment variable can be set to
48+
achieve the same effect as the `--no-replace-objects` option.
4549

4650
OPTIONS
4751
-------

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ static inline enum object_type object_type(unsigned int mode)
369369
#define CONFIG_ENVIRONMENT "GIT_CONFIG"
370370
#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH"
371371
#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES"
372+
#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS"
372373
#define GITATTRIBUTES_FILE ".gitattributes"
373374
#define INFOATTRIBUTES_FILE "info/attributes"
374375
#define ATTRIBUTE_MACRO_PREFIX "[attr]"

connect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
609609
GIT_WORK_TREE_ENVIRONMENT,
610610
GRAFT_ENVIRONMENT,
611611
INDEX_ENVIRONMENT,
612+
NO_REPLACE_OBJECTS_ENVIRONMENT,
612613
NULL
613614
};
614615
conn->env = env;

environment.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ static void setup_git_env(void)
8484
git_graft_file = getenv(GRAFT_ENVIRONMENT);
8585
if (!git_graft_file)
8686
git_graft_file = git_pathdup("info/grafts");
87+
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
88+
read_replace_refs = 0;
8789
}
8890

8991
int is_bare_repository(void)

git.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
8989
*envchanged = 1;
9090
} else if (!strcmp(cmd, "--no-replace-objects")) {
9191
read_replace_refs = 0;
92+
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
93+
if (envchanged)
94+
*envchanged = 1;
9295
} else if (!strcmp(cmd, "--git-dir")) {
9396
if (*argc < 2) {
9497
fprintf(stderr, "No directory given for --git-dir.\n" );

t/t6050-replace.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ test_expect_success 'test --no-replace-objects option' '
7777
git --no-replace-objects show $HASH2 | grep "A U Thor"
7878
'
7979

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+
8085
cat >tag.sig <<EOF
8186
object $HASH2
8287
type commit
@@ -202,6 +207,18 @@ test_expect_success 'fetch branch with replacement' '
202207
cd ..
203208
'
204209

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+
205222
#
206223
#
207224
test_done

0 commit comments

Comments
 (0)