]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: introduce GIT_DEFAULT_REF_FORMAT envvar
authorPatrick Steinhardt <ps@pks.im>
Fri, 29 Dec 2023 07:26:52 +0000 (08:26 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Jan 2024 17:24:48 +0000 (09:24 -0800)
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>
Documentation/git.txt
setup.c
t/t0001-init.sh

index 4698d7a42b5d4cd23a30b953313928fc73bcb76c..0ab19eef3bfe15b4238b27fb79b7f7c17cd97049 100644 (file)
@@ -556,6 +556,11 @@ double-quotes and respecting backslash escapes. E.g., the value
        is always used. The default is "sha1".
        See `--object-format` in linkgit:git-init[1].
 
+`GIT_DEFAULT_REF_FORMAT`::
+       If this variable is set, the default reference backend format for new
+       repositories will be set to this value. The default is "files".
+       See `--ref-format` in linkgit:git-init[1].
+
 Git Commits
 ~~~~~~~~~~~
 `GIT_AUTHOR_NAME`::
diff --git a/setup.c b/setup.c
index fb1413cabd2fea15261a1c1e867cf7f4dc5d6aba..1ab1a66bcb2b1408b71bfae053597d0c36999e05 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -2164,12 +2164,19 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
 static void validate_ref_storage_format(struct repository_format *repo_fmt,
                                        unsigned int format)
 {
+       const char *name = getenv("GIT_DEFAULT_REF_FORMAT");
+
        if (repo_fmt->version >= 0 &&
            format != REF_STORAGE_FORMAT_UNKNOWN &&
            format != repo_fmt->ref_storage_format) {
                die(_("attempt to reinitialize repository with different reference storage format"));
        } else if (format != REF_STORAGE_FORMAT_UNKNOWN) {
                repo_fmt->ref_storage_format = format;
+       } else if (name) {
+               format = ref_storage_format_by_name(name);
+               if (format == REF_STORAGE_FORMAT_UNKNOWN)
+                       die(_("unknown ref storage format '%s'"), name);
+               repo_fmt->ref_storage_format = format;
        }
 }
 
index 38b3e4c39e875bd881cb5a41d35a9d8b6eb2767a..30ce752cc19e10500a94f134689933d7e431a21b 100755 (executable)
@@ -558,6 +558,24 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back
        grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
 '
 
+test_expect_success DEFAULT_REPO_FORMAT 'init with GIT_DEFAULT_REF_FORMAT=files' '
+       test_when_finished "rm -rf refformat" &&
+       GIT_DEFAULT_REF_FORMAT=files git init refformat &&
+       echo 0 >expect &&
+       git -C refformat config core.repositoryformatversion >actual &&
+       test_cmp expect actual &&
+       test_must_fail git -C refformat config extensions.refstorage
+'
+
+test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
+       test_when_finished "rm -rf refformat" &&
+       cat >expect <<-EOF &&
+       fatal: unknown ref storage format ${SQ}garbage${SQ}
+       EOF
+       test_must_fail env GIT_DEFAULT_REF_FORMAT=garbage git init refformat 2>err &&
+       test_cmp expect err
+'
+
 test_expect_success MINGW 'core.hidedotfiles = false' '
        git config --global core.hidedotfiles false &&
        rm -rf newdir &&