Skip to content

Commit aa19619

Browse files
pks-tgitster
authored andcommitted
setup: introduce GIT_DEFAULT_REF_FORMAT envvar
Introduce a new GIT_DEFAULT_REF_FORMAT environment variable that lets users control the default ref format used by both git-init(1) and git-clone(1). This is modeled after GIT_DEFAULT_OBJECT_FORMAT, which does the same thing for the repository's object format. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7497a4 commit aa19619

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Documentation/git.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ double-quotes and respecting backslash escapes. E.g., the value
556556
is always used. The default is "sha1".
557557
See `--object-format` in linkgit:git-init[1].
558558

559+
`GIT_DEFAULT_REF_FORMAT`::
560+
If this variable is set, the default reference backend format for new
561+
repositories will be set to this value. The default is "files".
562+
See `--ref-format` in linkgit:git-init[1].
563+
559564
Git Commits
560565
~~~~~~~~~~~
561566
`GIT_AUTHOR_NAME`::

setup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,12 +2164,19 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
21642164
static void validate_ref_storage_format(struct repository_format *repo_fmt,
21652165
unsigned int format)
21662166
{
2167+
const char *name = getenv("GIT_DEFAULT_REF_FORMAT");
2168+
21672169
if (repo_fmt->version >= 0 &&
21682170
format != REF_STORAGE_FORMAT_UNKNOWN &&
21692171
format != repo_fmt->ref_storage_format) {
21702172
die(_("attempt to reinitialize repository with different reference storage format"));
21712173
} else if (format != REF_STORAGE_FORMAT_UNKNOWN) {
21722174
repo_fmt->ref_storage_format = format;
2175+
} else if (name) {
2176+
format = ref_storage_format_by_name(name);
2177+
if (format == REF_STORAGE_FORMAT_UNKNOWN)
2178+
die(_("unknown ref storage format '%s'"), name);
2179+
repo_fmt->ref_storage_format = format;
21732180
}
21742181
}
21752182

t/t0001-init.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,24 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back
558558
grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
559559
'
560560

561+
test_expect_success DEFAULT_REPO_FORMAT 'init with GIT_DEFAULT_REF_FORMAT=files' '
562+
test_when_finished "rm -rf refformat" &&
563+
GIT_DEFAULT_REF_FORMAT=files git init refformat &&
564+
echo 0 >expect &&
565+
git -C refformat config core.repositoryformatversion >actual &&
566+
test_cmp expect actual &&
567+
test_must_fail git -C refformat config extensions.refstorage
568+
'
569+
570+
test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
571+
test_when_finished "rm -rf refformat" &&
572+
cat >expect <<-EOF &&
573+
fatal: unknown ref storage format ${SQ}garbage${SQ}
574+
EOF
575+
test_must_fail env GIT_DEFAULT_REF_FORMAT=garbage git init refformat 2>err &&
576+
test_cmp expect err
577+
'
578+
561579
test_expect_success MINGW 'core.hidedotfiles = false' '
562580
git config --global core.hidedotfiles false &&
563581
rm -rf newdir &&

0 commit comments

Comments
 (0)