mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Git allows setting a different object directory via
'GIT_OBJECT_DIRECTORY', but provides no equivalent for references.
This asymmetry makes it difficult to test different reference backends
or use alternative reference storage locations without modifying the
repository structure.
Add a new environment variable 'GIT_REF_URI' that specifies both the
reference backend and directory path using a URI format:
<ref_backend>://<URI-for-resource>
When set, this variable is used to obtain the main reference store for
all Git commands. The variable is checked in `get_main_ref_store()`
when lazily assigning `repo->refs_private`. We cannot initialize this
earlier in `repo_set_gitdir()` because the repository's hash algorithm
isn't known at that point, and the reftable backend requires this
information during initialization.
When used with worktrees, the specified directory is treated as the
reference directory for all worktree operations.
Add a new test file 't1423-ref-backend.sh' to test this environment
variable.
Helped-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
122 lines
2.8 KiB
Bash
Executable File
122 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='Test different reference backend URIs'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'empty uri provided' '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init --ref-format=files repo &&
|
|
(
|
|
cd repo &&
|
|
GIT_REF_URI="" &&
|
|
export GIT_REF_URI &&
|
|
test_must_fail git refs list 2>err &&
|
|
test_grep "invalid reference backend uri format" err
|
|
)
|
|
'
|
|
|
|
test_expect_success 'invalid uri provided' '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init --ref-format=files repo &&
|
|
(
|
|
cd repo &&
|
|
GIT_REF_URI="reftable@/home/reftable" &&
|
|
export GIT_REF_URI &&
|
|
test_must_fail git refs list 2>err &&
|
|
test_grep "invalid reference backend uri format" err
|
|
)
|
|
'
|
|
|
|
test_expect_success 'empty path in uri' '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init --ref-format=files repo &&
|
|
(
|
|
cd repo &&
|
|
GIT_REF_URI="reftable://" &&
|
|
export GIT_REF_URI &&
|
|
test_must_fail git refs list 2>err &&
|
|
test_grep "invalid path in uri" err
|
|
)
|
|
'
|
|
|
|
test_expect_success 'uri ends at colon' '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init --ref-format=files repo &&
|
|
(
|
|
cd repo &&
|
|
GIT_REF_URI="reftable:" &&
|
|
export GIT_REF_URI &&
|
|
test_must_fail git refs list 2>err &&
|
|
test_grep "invalid reference backend uri format" err
|
|
)
|
|
'
|
|
|
|
test_expect_success 'unknown reference backend' '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init --ref-format=files repo &&
|
|
(
|
|
cd repo &&
|
|
GIT_REF_URI="db://.git" &&
|
|
export GIT_REF_URI &&
|
|
test_must_fail git refs list 2>err &&
|
|
test_grep "unknown reference backend" err
|
|
)
|
|
'
|
|
|
|
ref_formats="files reftable"
|
|
for from_format in $ref_formats
|
|
do
|
|
for to_format in $ref_formats
|
|
do
|
|
if test "$from_format" = "$to_format"
|
|
then
|
|
continue
|
|
fi
|
|
|
|
test_expect_success "read from $to_format backend" '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init --ref-format=$from_format repo &&
|
|
(
|
|
cd repo &&
|
|
test_commit 1 &&
|
|
test_commit 2 &&
|
|
test_commit 3 &&
|
|
|
|
git refs migrate --dry-run --ref-format=$to_format >out &&
|
|
BACKEND_PATH=$(cat out | sed "s/.* ${SQ}\(.*\)${SQ}/\1/") &&
|
|
git refs list >expect &&
|
|
GIT_REF_URI="$to_format://$BACKEND_PATH" git refs list >actual &&
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
|
|
test_expect_success "write to $to_format backend" '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init --ref-format=$from_format repo &&
|
|
(
|
|
cd repo &&
|
|
test_commit 1 &&
|
|
test_commit 2 &&
|
|
test_commit 3 &&
|
|
|
|
git refs migrate --dry-run --ref-format=$to_format >out &&
|
|
git refs list >expect &&
|
|
|
|
BACKEND_PATH=$(cat out | sed "s/.* ${SQ}\(.*\)${SQ}/\1/") &&
|
|
GIT_REF_URI="$to_format://$BACKEND_PATH" git tag -d 1 &&
|
|
|
|
git refs list >actual &&
|
|
test_cmp expect actual &&
|
|
|
|
GIT_REF_URI="$to_format://$BACKEND_PATH" git refs list >expect &&
|
|
git refs list >out &&
|
|
cat out | grep -v "refs/tags/1" >actual &&
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
done
|
|
done
|
|
|
|
test_done
|