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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 29, 2023 at 08:26 UTC
aa19619a9835a9558630c25a5b8f361343af75ce
3 files changed
+30
Documentation/git.txt
+5
@@ -556,6 +556,11 @@ double-quotes and respecting backslash escapes. E.g., the value
556
is always used. The default is "sha1".
557
See `--object-format` in linkgit:git-init[1].
558
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
+
564
Git Commits
565
~~~~~~~~~~~
566
`GIT_AUTHOR_NAME`::
setup.c
+7
@@ -2164,12 +2164,19 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
2164
static void validate_ref_storage_format(struct repository_format *repo_fmt,
2165
unsigned int format)
2166
{
2167
+ const char *name = getenv("GIT_DEFAULT_REF_FORMAT");
2168
+
2169
if (repo_fmt->version >= 0 &&
2170
format != REF_STORAGE_FORMAT_UNKNOWN &&
2171
format != repo_fmt->ref_storage_format) {
2172
die(_("attempt to reinitialize repository with different reference storage format"));
2173
} else if (format != REF_STORAGE_FORMAT_UNKNOWN) {
2174
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;
2180
}
2181
}
2182
t/t0001-init.sh
+18
@@ -558,6 +558,24 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back
558
grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
559
'
560
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
+
579
test_expect_success MINGW 'core.hidedotfiles = false' '
580
git config --global core.hidedotfiles false &&
581
rm -rf newdir &&