mirror of
https://github.com/git/git.git
synced 2024-11-23 09:56:28 +08:00
refs: introduce reftable backend
Due to scalability issues, Shawn Pearce has originally proposed a new
"reftable" format more than six years ago [1]. Initially, this new
format was implemented in JGit with promising results. Around two years
ago, we have then added the "reftable" library to the Git codebase via
a4bbd13be3
(Merge branch 'hn/reftable', 2021-12-15). With this we have
landed all the low-level code to read and write reftables. Notably
missing though was the integration of this low-level code into the Git
code base in the form of a new ref backend that ties all of this
together.
This gap is now finally closed by introducing a new "reftable" backend
into the Git codebase. This new backend promises to bring some notable
improvements to Git repositories:
- It becomes possible to do truly atomic writes where either all refs
are committed to disk or none are. This was not possible with the
"files" backend because ref updates were split across multiple loose
files.
- The disk space required to store many refs is reduced, both compared
to loose refs and packed-refs. This is enabled both by the reftable
format being a binary format, which is more compact, and by prefix
compression.
- We can ignore filesystem-specific behaviour as ref names are not
encoded via paths anymore. This means there is no need to handle
case sensitivity on Windows systems or Unicode precomposition on
macOS.
- There is no need to rewrite the complete refdb anymore every time a
ref is being deleted like it was the case for packed-refs. This
means that ref deletions are now constant time instead of scaling
linearly with the number of refs.
- We can ignore file/directory conflicts so that it becomes possible
to store both "refs/heads/foo" and "refs/heads/foo/bar".
- Due to this property we can retain reflogs for deleted refs. We have
previously been deleting reflogs together with their refs to avoid
file/directory conflicts, which is not necessary anymore.
- We can properly enumerate all refs. With the "files" backend it is
not easily possible to distinguish between refs and non-refs because
they may live side by side in the gitdir.
Not all of these improvements are realized with the current "reftable"
backend implementation. At this point, the new backend is supposed to be
a drop-in replacement for the "files" backend that is used by basically
all Git repositories nowadays. It strives for 1:1 compatibility, which
means that a user can expect the same behaviour regardless of whether
they use the "reftable" backend or the "files" backend for most of the
part.
Most notably, this means we artificially limit the capabilities of the
"reftable" backend to match the limits of the "files" backend. It is not
possible to create refs that would end up with file/directory conflicts,
we do not retain reflogs, we perform stricter-than-necessary checks.
This is done intentionally due to two main reasons:
- It makes it significantly easier to land the "reftable" backend as
tests behave the same. It would be tough to argue for each and every
single test that doesn't pass with the "reftable" backend.
- It ensures compatibility between repositories that use the "files"
backend and repositories that use the "reftable" backend. Like this,
hosters can migrate their repositories to use the "reftable" backend
without causing issues for clients that use the "files" backend in
their clones.
It is expected that these artificial limitations may eventually go away
in the long term.
Performance-wise things very much depend on the actual workload. The
following benchmarks compare the "files" and "reftable" backends in the
current version:
- Creating N refs in separate transactions shows that the "files"
backend is ~50% faster. This is not surprising given that creating a
ref only requires us to create a single loose ref. The "reftable"
backend will also perform auto compaction on updates. In real-world
workloads we would likely also want to perform pack loose refs,
which would likely change the picture.
Benchmark 1: update-ref: create refs sequentially (refformat = files, refcount = 1)
Time (mean ± σ): 2.1 ms ± 0.3 ms [User: 0.6 ms, System: 1.7 ms]
Range (min … max): 1.8 ms … 4.3 ms 133 runs
Benchmark 2: update-ref: create refs sequentially (refformat = reftable, refcount = 1)
Time (mean ± σ): 2.7 ms ± 0.1 ms [User: 0.6 ms, System: 2.2 ms]
Range (min … max): 2.4 ms … 2.9 ms 132 runs
Benchmark 3: update-ref: create refs sequentially (refformat = files, refcount = 1000)
Time (mean ± σ): 1.975 s ± 0.006 s [User: 0.437 s, System: 1.535 s]
Range (min … max): 1.969 s … 1.980 s 3 runs
Benchmark 4: update-ref: create refs sequentially (refformat = reftable, refcount = 1000)
Time (mean ± σ): 2.611 s ± 0.013 s [User: 0.782 s, System: 1.825 s]
Range (min … max): 2.597 s … 2.622 s 3 runs
Benchmark 5: update-ref: create refs sequentially (refformat = files, refcount = 100000)
Time (mean ± σ): 198.442 s ± 0.241 s [User: 43.051 s, System: 155.250 s]
Range (min … max): 198.189 s … 198.670 s 3 runs
Benchmark 6: update-ref: create refs sequentially (refformat = reftable, refcount = 100000)
Time (mean ± σ): 294.509 s ± 4.269 s [User: 104.046 s, System: 190.326 s]
Range (min … max): 290.223 s … 298.761 s 3 runs
- Creating N refs in a single transaction shows that the "files"
backend is significantly slower once we start to write many refs.
The "reftable" backend only needs to update two files, whereas the
"files" backend needs to write one file per ref.
Benchmark 1: update-ref: create many refs (refformat = files, refcount = 1)
Time (mean ± σ): 1.9 ms ± 0.1 ms [User: 0.4 ms, System: 1.4 ms]
Range (min … max): 1.8 ms … 2.6 ms 151 runs
Benchmark 2: update-ref: create many refs (refformat = reftable, refcount = 1)
Time (mean ± σ): 2.5 ms ± 0.1 ms [User: 0.7 ms, System: 1.7 ms]
Range (min … max): 2.4 ms … 3.4 ms 148 runs
Benchmark 3: update-ref: create many refs (refformat = files, refcount = 1000)
Time (mean ± σ): 152.5 ms ± 5.2 ms [User: 19.1 ms, System: 133.1 ms]
Range (min … max): 148.5 ms … 167.8 ms 15 runs
Benchmark 4: update-ref: create many refs (refformat = reftable, refcount = 1000)
Time (mean ± σ): 58.0 ms ± 2.5 ms [User: 28.4 ms, System: 29.4 ms]
Range (min … max): 56.3 ms … 72.9 ms 40 runs
Benchmark 5: update-ref: create many refs (refformat = files, refcount = 1000000)
Time (mean ± σ): 152.752 s ± 0.710 s [User: 20.315 s, System: 131.310 s]
Range (min … max): 152.165 s … 153.542 s 3 runs
Benchmark 6: update-ref: create many refs (refformat = reftable, refcount = 1000000)
Time (mean ± σ): 51.912 s ± 0.127 s [User: 26.483 s, System: 25.424 s]
Range (min … max): 51.769 s … 52.012 s 3 runs
- Deleting a ref in a fully-packed repository shows that the "files"
backend scales with the number of refs. The "reftable" backend has
constant-time deletions.
Benchmark 1: update-ref: delete ref (refformat = files, refcount = 1)
Time (mean ± σ): 1.7 ms ± 0.1 ms [User: 0.4 ms, System: 1.2 ms]
Range (min … max): 1.6 ms … 2.1 ms 316 runs
Benchmark 2: update-ref: delete ref (refformat = reftable, refcount = 1)
Time (mean ± σ): 1.8 ms ± 0.1 ms [User: 0.4 ms, System: 1.3 ms]
Range (min … max): 1.7 ms … 2.1 ms 294 runs
Benchmark 3: update-ref: delete ref (refformat = files, refcount = 1000)
Time (mean ± σ): 2.0 ms ± 0.1 ms [User: 0.5 ms, System: 1.4 ms]
Range (min … max): 1.9 ms … 2.5 ms 287 runs
Benchmark 4: update-ref: delete ref (refformat = reftable, refcount = 1000)
Time (mean ± σ): 1.9 ms ± 0.1 ms [User: 0.5 ms, System: 1.3 ms]
Range (min … max): 1.8 ms … 2.1 ms 217 runs
Benchmark 5: update-ref: delete ref (refformat = files, refcount = 1000000)
Time (mean ± σ): 229.8 ms ± 7.9 ms [User: 182.6 ms, System: 46.8 ms]
Range (min … max): 224.6 ms … 245.2 ms 6 runs
Benchmark 6: update-ref: delete ref (refformat = reftable, refcount = 1000000)
Time (mean ± σ): 2.0 ms ± 0.0 ms [User: 0.6 ms, System: 1.3 ms]
Range (min … max): 2.0 ms … 2.1 ms 3 runs
- Listing all refs shows no significant advantage for either of the
backends. The "files" backend is a bit faster, but not by a
significant margin. When repositories are not packed the "reftable"
backend outperforms the "files" backend because the "reftable"
backend performs auto-compaction.
Benchmark 1: show-ref: print all refs (refformat = files, refcount = 1, packed = true)
Time (mean ± σ): 1.6 ms ± 0.1 ms [User: 0.4 ms, System: 1.1 ms]
Range (min … max): 1.5 ms … 2.0 ms 1729 runs
Benchmark 2: show-ref: print all refs (refformat = reftable, refcount = 1, packed = true)
Time (mean ± σ): 1.6 ms ± 0.1 ms [User: 0.4 ms, System: 1.1 ms]
Range (min … max): 1.5 ms … 1.8 ms 1816 runs
Benchmark 3: show-ref: print all refs (refformat = files, refcount = 1000, packed = true)
Time (mean ± σ): 4.3 ms ± 0.1 ms [User: 0.9 ms, System: 3.3 ms]
Range (min … max): 4.1 ms … 4.6 ms 645 runs
Benchmark 4: show-ref: print all refs (refformat = reftable, refcount = 1000, packed = true)
Time (mean ± σ): 4.5 ms ± 0.2 ms [User: 1.0 ms, System: 3.3 ms]
Range (min … max): 4.2 ms … 5.9 ms 643 runs
Benchmark 5: show-ref: print all refs (refformat = files, refcount = 1000000, packed = true)
Time (mean ± σ): 2.537 s ± 0.034 s [User: 0.488 s, System: 2.048 s]
Range (min … max): 2.511 s … 2.627 s 10 runs
Benchmark 6: show-ref: print all refs (refformat = reftable, refcount = 1000000, packed = true)
Time (mean ± σ): 2.712 s ± 0.017 s [User: 0.653 s, System: 2.059 s]
Range (min … max): 2.692 s … 2.752 s 10 runs
Benchmark 7: show-ref: print all refs (refformat = files, refcount = 1, packed = false)
Time (mean ± σ): 1.6 ms ± 0.1 ms [User: 0.4 ms, System: 1.1 ms]
Range (min … max): 1.5 ms … 1.9 ms 1834 runs
Benchmark 8: show-ref: print all refs (refformat = reftable, refcount = 1, packed = false)
Time (mean ± σ): 1.6 ms ± 0.1 ms [User: 0.4 ms, System: 1.1 ms]
Range (min … max): 1.4 ms … 2.0 ms 1840 runs
Benchmark 9: show-ref: print all refs (refformat = files, refcount = 1000, packed = false)
Time (mean ± σ): 13.8 ms ± 0.2 ms [User: 2.8 ms, System: 10.8 ms]
Range (min … max): 13.3 ms … 14.5 ms 208 runs
Benchmark 10: show-ref: print all refs (refformat = reftable, refcount = 1000, packed = false)
Time (mean ± σ): 4.5 ms ± 0.2 ms [User: 1.2 ms, System: 3.3 ms]
Range (min … max): 4.3 ms … 6.2 ms 624 runs
Benchmark 11: show-ref: print all refs (refformat = files, refcount = 1000000, packed = false)
Time (mean ± σ): 12.127 s ± 0.129 s [User: 2.675 s, System: 9.451 s]
Range (min … max): 11.965 s … 12.370 s 10 runs
Benchmark 12: show-ref: print all refs (refformat = reftable, refcount = 1000000, packed = false)
Time (mean ± σ): 2.799 s ± 0.022 s [User: 0.735 s, System: 2.063 s]
Range (min … max): 2.769 s … 2.836 s 10 runs
- Printing a single ref shows no real difference between the "files"
and "reftable" backends.
Benchmark 1: show-ref: print single ref (refformat = files, refcount = 1)
Time (mean ± σ): 1.5 ms ± 0.1 ms [User: 0.4 ms, System: 1.0 ms]
Range (min … max): 1.4 ms … 1.8 ms 1779 runs
Benchmark 2: show-ref: print single ref (refformat = reftable, refcount = 1)
Time (mean ± σ): 1.6 ms ± 0.1 ms [User: 0.4 ms, System: 1.1 ms]
Range (min … max): 1.4 ms … 2.5 ms 1753 runs
Benchmark 3: show-ref: print single ref (refformat = files, refcount = 1000)
Time (mean ± σ): 1.5 ms ± 0.1 ms [User: 0.3 ms, System: 1.1 ms]
Range (min … max): 1.4 ms … 1.9 ms 1840 runs
Benchmark 4: show-ref: print single ref (refformat = reftable, refcount = 1000)
Time (mean ± σ): 1.6 ms ± 0.1 ms [User: 0.4 ms, System: 1.1 ms]
Range (min … max): 1.5 ms … 2.0 ms 1831 runs
Benchmark 5: show-ref: print single ref (refformat = files, refcount = 1000000)
Time (mean ± σ): 1.6 ms ± 0.1 ms [User: 0.4 ms, System: 1.1 ms]
Range (min … max): 1.5 ms … 2.1 ms 1848 runs
Benchmark 6: show-ref: print single ref (refformat = reftable, refcount = 1000000)
Time (mean ± σ): 1.6 ms ± 0.1 ms [User: 0.4 ms, System: 1.1 ms]
Range (min … max): 1.5 ms … 2.1 ms 1762 runs
So overall, performance depends on the usecases. Except for many
sequential writes the "reftable" backend is roughly on par or
significantly faster than the "files" backend though. Given that the
"files" backend has received 18 years of optimizations by now this can
be seen as a win. Furthermore, we can expect that the "reftable" backend
will grow faster over time when attention turns more towards
optimizations.
The complete test suite passes, except for those tests explicitly marked
to require the REFFILES prerequisite. Some tests in t0610 are marked as
failing because they depend on still-in-flight bug fixes. Tests can be
run with the new backend by setting the GIT_TEST_DEFAULT_REF_FORMAT
environment variable to "reftable".
There is a single known conceptual incompatibility with the dumb HTTP
transport. As "info/refs" SHOULD NOT contain the HEAD reference, and
because the "HEAD" file is not valid anymore, it is impossible for the
remote client to figure out the default branch without changing the
protocol. This shortcoming needs to be handled in a subsequent patch
series.
As the reftable library has already been introduced a while ago, this
commit message will not go into the details of how exactly the on-disk
format works. Please refer to our preexisting technical documentation at
Documentation/technical/reftable for this.
[1]: https://public-inbox.org/git/CAJo=hJtyof=HRy=2sLP0ng0uZ4=S-DpZ5dR1aF+VHVETKG20OQ@mail.gmail.com/
Original-idea-by: Shawn Pearce <spearce@spearce.org>
Based-on-patch-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
235986be82
commit
57db2a094d
@ -1 +1,3 @@
|
||||
* `files` for loose files with packed-refs. This is the default.
|
||||
* `reftable` for the reftable format. This format is experimental and its
|
||||
internals are subject to change.
|
||||
|
@ -103,5 +103,6 @@ GIT_COMMON_DIR/worktrees/<id>/config.worktree)
|
||||
|
||||
==== `refStorage`
|
||||
|
||||
Specifies the file format for the ref database. The only valid value
|
||||
is `files` (loose references with a packed-refs file).
|
||||
Specifies the file format for the ref database. The valid values are
|
||||
`files` (loose references with a packed-refs file) and `reftable` (see
|
||||
Documentation/technical/reftable.txt).
|
||||
|
1
Makefile
1
Makefile
@ -1127,6 +1127,7 @@ LIB_OBJS += reflog.o
|
||||
LIB_OBJS += refs.o
|
||||
LIB_OBJS += refs/debug.o
|
||||
LIB_OBJS += refs/files-backend.o
|
||||
LIB_OBJS += refs/reftable-backend.o
|
||||
LIB_OBJS += refs/iterator.o
|
||||
LIB_OBJS += refs/packed-backend.o
|
||||
LIB_OBJS += refs/ref-cache.o
|
||||
|
@ -79,7 +79,7 @@ trap cleanup $siglist
|
||||
# create the links to the original repo. explicitly exclude index, HEAD and
|
||||
# logs/HEAD from the list since they are purely related to the current working
|
||||
# directory, and should not be shared.
|
||||
for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
|
||||
for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn reftable
|
||||
do
|
||||
# create a containing directory if needed
|
||||
case $x in
|
||||
|
2
path.c
2
path.c
@ -871,7 +871,7 @@ const char *enter_repo(const char *path, int strict)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int calc_shared_perm(int mode)
|
||||
int calc_shared_perm(int mode)
|
||||
{
|
||||
int tweak;
|
||||
|
||||
|
1
path.h
1
path.h
@ -181,6 +181,7 @@ const char *git_path_shallow(struct repository *r);
|
||||
int ends_with_path_components(const char *path, const char *components);
|
||||
int validate_headref(const char *ref);
|
||||
|
||||
int calc_shared_perm(int mode);
|
||||
int adjust_shared_perm(const char *path);
|
||||
|
||||
char *interpolate_path(const char *path, int real_home);
|
||||
|
1
refs.c
1
refs.c
@ -35,6 +35,7 @@
|
||||
*/
|
||||
static const struct ref_storage_be *refs_backends[] = {
|
||||
[REF_STORAGE_FORMAT_FILES] = &refs_be_files,
|
||||
[REF_STORAGE_FORMAT_REFTABLE] = &refs_be_reftable,
|
||||
};
|
||||
|
||||
static const struct ref_storage_be *find_ref_storage_backend(unsigned int ref_storage_format)
|
||||
|
@ -693,6 +693,7 @@ struct ref_storage_be {
|
||||
};
|
||||
|
||||
extern struct ref_storage_be refs_be_files;
|
||||
extern struct ref_storage_be refs_be_reftable;
|
||||
extern struct ref_storage_be refs_be_packed;
|
||||
|
||||
/*
|
||||
|
2297
refs/reftable-backend.c
Normal file
2297
refs/reftable-backend.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -24,8 +24,9 @@ enum fetch_negotiation_setting {
|
||||
FETCH_NEGOTIATION_NOOP,
|
||||
};
|
||||
|
||||
#define REF_STORAGE_FORMAT_UNKNOWN 0
|
||||
#define REF_STORAGE_FORMAT_FILES 1
|
||||
#define REF_STORAGE_FORMAT_UNKNOWN 0
|
||||
#define REF_STORAGE_FORMAT_FILES 1
|
||||
#define REF_STORAGE_FORMAT_REFTABLE 2
|
||||
|
||||
struct repo_settings {
|
||||
int initialized;
|
||||
|
887
t/t0610-reftable-basics.sh
Executable file
887
t/t0610-reftable-basics.sh
Executable file
@ -0,0 +1,887 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2020 Google LLC
|
||||
#
|
||||
|
||||
test_description='reftable basics'
|
||||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
||||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
if ! test_have_prereq REFTABLE
|
||||
then
|
||||
skip_all='skipping reftable tests; set GIT_TEST_DEFAULT_REF_FORMAT=reftable'
|
||||
test_done
|
||||
fi
|
||||
|
||||
INVALID_OID=$(test_oid 001)
|
||||
|
||||
test_expect_success 'init: creates basic reftable structures' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_path_is_dir repo/.git/reftable &&
|
||||
test_path_is_file repo/.git/reftable/tables.list &&
|
||||
echo reftable >expect &&
|
||||
git -C repo rev-parse --show-ref-format >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'init: sha256 object format via environment variable' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
GIT_DEFAULT_HASH=sha256 git init repo &&
|
||||
cat >expect <<-EOF &&
|
||||
sha256
|
||||
reftable
|
||||
EOF
|
||||
git -C repo rev-parse --show-object-format --show-ref-format >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'init: sha256 object format via option' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init --object-format=sha256 repo &&
|
||||
cat >expect <<-EOF &&
|
||||
sha256
|
||||
reftable
|
||||
EOF
|
||||
git -C repo rev-parse --show-object-format --show-ref-format >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'init: reinitializing reftable backend succeeds' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
|
||||
git -C repo for-each-ref >expect &&
|
||||
git init --ref-format=reftable repo &&
|
||||
git -C repo for-each-ref >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'init: reinitializing files with reftable backend fails' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init --ref-format=files repo &&
|
||||
test_commit -C repo file &&
|
||||
|
||||
cp repo/.git/HEAD expect &&
|
||||
test_must_fail git init --ref-format=reftable repo &&
|
||||
test_cmp expect repo/.git/HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'init: reinitializing reftable with files backend fails' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init --ref-format=reftable repo &&
|
||||
test_commit -C repo file &&
|
||||
|
||||
cp repo/.git/HEAD expect &&
|
||||
test_must_fail git init --ref-format=files repo &&
|
||||
test_cmp expect repo/.git/HEAD
|
||||
'
|
||||
|
||||
test_expect_perms () {
|
||||
local perms="$1"
|
||||
local file="$2"
|
||||
local actual=$(ls -l "$file") &&
|
||||
|
||||
case "$actual" in
|
||||
$perms*)
|
||||
: happy
|
||||
;;
|
||||
*)
|
||||
echo "$(basename $2) is not $perms but $actual"
|
||||
false
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
for umask in 002 022
|
||||
do
|
||||
test_expect_success POSIXPERM 'init: honors core.sharedRepository' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
(
|
||||
umask $umask &&
|
||||
git init --shared=true repo &&
|
||||
test 1 = "$(git -C repo config core.sharedrepository)"
|
||||
) &&
|
||||
test_expect_perms "-rw-rw-r--" repo/.git/reftable/tables.list &&
|
||||
for table in repo/.git/reftable/*.ref
|
||||
do
|
||||
test_expect_perms "-rw-rw-r--" "$table" ||
|
||||
return 1
|
||||
done
|
||||
'
|
||||
done
|
||||
|
||||
test_expect_success 'clone: can clone reftable repository' '
|
||||
test_when_finished "rm -rf repo clone" &&
|
||||
git init repo &&
|
||||
test_commit -C repo message1 file1 &&
|
||||
|
||||
git clone repo cloned &&
|
||||
echo reftable >expect &&
|
||||
git -C cloned rev-parse --show-ref-format >actual &&
|
||||
test_cmp expect actual &&
|
||||
test_path_is_file cloned/file1
|
||||
'
|
||||
|
||||
test_expect_success 'clone: can clone reffiles into reftable repository' '
|
||||
test_when_finished "rm -rf reffiles reftable" &&
|
||||
git init --ref-format=files reffiles &&
|
||||
test_commit -C reffiles A &&
|
||||
git clone --ref-format=reftable ./reffiles reftable &&
|
||||
|
||||
git -C reffiles rev-parse HEAD >expect &&
|
||||
git -C reftable rev-parse HEAD >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
git -C reftable rev-parse --show-ref-format >actual &&
|
||||
echo reftable >expect &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
git -C reffiles rev-parse --show-ref-format >actual &&
|
||||
echo files >expect &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'clone: can clone reftable into reffiles repository' '
|
||||
test_when_finished "rm -rf reffiles reftable" &&
|
||||
git init --ref-format=reftable reftable &&
|
||||
test_commit -C reftable A &&
|
||||
git clone --ref-format=files ./reftable reffiles &&
|
||||
|
||||
git -C reftable rev-parse HEAD >expect &&
|
||||
git -C reffiles rev-parse HEAD >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
git -C reftable rev-parse --show-ref-format >actual &&
|
||||
echo reftable >expect &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
git -C reffiles rev-parse --show-ref-format >actual &&
|
||||
echo files >expect &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: corrupted tables cause failure' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit file1 &&
|
||||
for f in .git/reftable/*.ref
|
||||
do
|
||||
: >"$f" || return 1
|
||||
done &&
|
||||
test_must_fail git update-ref refs/heads/main HEAD
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: corrupted tables.list cause failure' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit file1 &&
|
||||
echo garbage >.git/reftable/tables.list &&
|
||||
test_must_fail git update-ref refs/heads/main HEAD
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: refuses to write ref causing F/D conflict' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo file &&
|
||||
test_must_fail git -C repo update-ref refs/heads/main/forbidden
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: deleting ref with invalid name fails' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo file &&
|
||||
test_must_fail git -C repo update-ref -d ../../my-private-file
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: can skip object ID verification' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_must_fail test-tool -C repo ref-store main update-ref msg refs/heads/branch $INVALID_OID $ZERO_OID 0 &&
|
||||
test-tool -C repo ref-store main update-ref msg refs/heads/branch $INVALID_OID $ZERO_OID REF_SKIP_OID_VERIFICATION
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: updating same ref multiple times fails' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
cat >updates <<-EOF &&
|
||||
update refs/heads/main $A
|
||||
update refs/heads/main $A
|
||||
EOF
|
||||
cat >expect <<-EOF &&
|
||||
fatal: multiple updates for ref ${SQ}refs/heads/main${SQ} not allowed
|
||||
EOF
|
||||
test_must_fail git -C repo update-ref --stdin <updates 2>err &&
|
||||
test_cmp expect err
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: can delete symbolic self-reference with git-symbolic-ref(1)' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
git -C repo symbolic-ref refs/heads/self refs/heads/self &&
|
||||
git -C repo symbolic-ref -d refs/heads/self
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: deleting symbolic self-reference without --no-deref fails' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
git -C repo symbolic-ref refs/heads/self refs/heads/self &&
|
||||
cat >expect <<-EOF &&
|
||||
error: multiple updates for ${SQ}refs/heads/self${SQ} (including one via symref ${SQ}refs/heads/self${SQ}) are not allowed
|
||||
EOF
|
||||
test_must_fail git -C repo update-ref -d refs/heads/self 2>err &&
|
||||
test_cmp expect err
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: deleting symbolic self-reference with --no-deref succeeds' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
git -C repo symbolic-ref refs/heads/self refs/heads/self &&
|
||||
git -C repo update-ref -d --no-deref refs/heads/self
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: creating symbolic ref fails with F/D conflict' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
cat >expect <<-EOF &&
|
||||
error: unable to write symref for refs/heads: file/directory conflict
|
||||
EOF
|
||||
test_must_fail git -C repo symbolic-ref refs/heads refs/heads/foo 2>err &&
|
||||
test_cmp expect err
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: ref deletion' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit file &&
|
||||
HEAD_OID=$(git show-ref -s --verify HEAD) &&
|
||||
cat >expect <<-EOF &&
|
||||
$HEAD_OID refs/heads/main
|
||||
$HEAD_OID refs/tags/file
|
||||
EOF
|
||||
git show-ref >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
test_must_fail git update-ref -d refs/tags/file $INVALID_OID &&
|
||||
git show-ref >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
git update-ref -d refs/tags/file $HEAD_OID &&
|
||||
echo "$HEAD_OID refs/heads/main" >expect &&
|
||||
git show-ref >actual &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'ref transaction: writes cause auto-compaction' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
|
||||
git init repo &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list &&
|
||||
|
||||
test_commit -C repo --no-tag A &&
|
||||
test_line_count = 2 repo/.git/reftable/tables.list &&
|
||||
|
||||
test_commit -C repo --no-tag B &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
check_fsync_events () {
|
||||
local trace="$1" &&
|
||||
shift &&
|
||||
|
||||
cat >expect &&
|
||||
sed -n \
|
||||
-e '/^{"event":"counter",.*"category":"fsync",/ {
|
||||
s/.*"category":"fsync",//;
|
||||
s/}$//;
|
||||
p;
|
||||
}' \
|
||||
<"$trace" >actual &&
|
||||
test_cmp expect actual
|
||||
}
|
||||
|
||||
test_expect_success 'ref transaction: writes are synced' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo initial &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
|
||||
GIT_TEST_FSYNC=true \
|
||||
git -C repo -c core.fsync=reference \
|
||||
-c core.fsyncMethod=fsync update-ref refs/heads/branch HEAD &&
|
||||
check_fsync_events trace2.txt <<-EOF
|
||||
"name":"hardware-flush","count":2
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'pack-refs: compacts tables' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
|
||||
test_commit -C repo A &&
|
||||
ls -1 repo/.git/reftable >table-files &&
|
||||
test_line_count = 4 table-files &&
|
||||
test_line_count = 3 repo/.git/reftable/tables.list &&
|
||||
|
||||
git -C repo pack-refs &&
|
||||
ls -1 repo/.git/reftable >table-files &&
|
||||
test_line_count = 2 table-files &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'pack-refs: prunes stale tables' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
touch repo/.git/reftable/stale-table.ref &&
|
||||
git -C repo pack-refs &&
|
||||
test_path_is_missing repo/.git/reftable/stable-ref.ref
|
||||
'
|
||||
|
||||
test_expect_success 'pack-refs: does not prune non-table files' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
touch repo/.git/reftable/garbage &&
|
||||
git -C repo pack-refs &&
|
||||
test_path_is_file repo/.git/reftable/garbage
|
||||
'
|
||||
|
||||
for umask in 002 022
|
||||
do
|
||||
test_expect_success POSIXPERM 'pack-refs: honors core.sharedRepository' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
(
|
||||
umask $umask &&
|
||||
git init --shared=true repo &&
|
||||
test_commit -C repo A &&
|
||||
test_line_count = 3 repo/.git/reftable/tables.list
|
||||
) &&
|
||||
git -C repo pack-refs &&
|
||||
test_expect_perms "-rw-rw-r--" repo/.git/reftable/tables.list &&
|
||||
for table in repo/.git/reftable/*.ref
|
||||
do
|
||||
test_expect_perms "-rw-rw-r--" "$table" ||
|
||||
return 1
|
||||
done
|
||||
'
|
||||
done
|
||||
|
||||
test_expect_success 'packed-refs: writes are synced' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo initial &&
|
||||
test_line_count = 2 table-files &&
|
||||
|
||||
: >trace2.txt &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
|
||||
GIT_TEST_FSYNC=true \
|
||||
git -C repo -c core.fsync=reference \
|
||||
-c core.fsyncMethod=fsync pack-refs &&
|
||||
check_fsync_events trace2.txt <<-EOF
|
||||
"name":"hardware-flush","count":2
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'ref iterator: bogus names are flagged' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit --no-tag file &&
|
||||
test-tool ref-store main update-ref msg "refs/heads/bogus..name" $(git rev-parse HEAD) $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
$ZERO_OID refs/heads/bogus..name 0xc
|
||||
$(git rev-parse HEAD) refs/heads/main 0x0
|
||||
EOF
|
||||
test-tool ref-store main for-each-ref "" >actual &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'ref iterator: missing object IDs are not flagged' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test-tool ref-store main update-ref msg "refs/heads/broken-hash" $INVALID_OID $ZERO_OID REF_SKIP_OID_VERIFICATION &&
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
$INVALID_OID refs/heads/broken-hash 0x0
|
||||
EOF
|
||||
test-tool ref-store main for-each-ref "" >actual &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'basic: commit and list refs' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo file &&
|
||||
test_write_lines refs/heads/main refs/tags/file >expect &&
|
||||
git -C repo for-each-ref --format="%(refname)" >actual &&
|
||||
test_cmp actual expect
|
||||
'
|
||||
|
||||
test_expect_success 'basic: can write large commit message' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
perl -e "
|
||||
print \"this is a long commit message\" x 50000
|
||||
" >commit-msg &&
|
||||
git -C repo commit --allow-empty --file=../commit-msg
|
||||
'
|
||||
|
||||
test_expect_success 'basic: show-ref fails with empty repository' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_must_fail git -C repo show-ref >actual &&
|
||||
test_must_be_empty actual
|
||||
'
|
||||
|
||||
test_expect_success 'basic: can check out unborn branch' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
git -C repo checkout -b main
|
||||
'
|
||||
|
||||
test_expect_success 'basic: peeled tags are stored' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
test_commit -C repo file &&
|
||||
git -C repo tag -m "annotated tag" test_tag HEAD &&
|
||||
for ref in refs/heads/main refs/tags/file refs/tags/test_tag refs/tags/test_tag^{}
|
||||
do
|
||||
echo "$(git -C repo rev-parse "$ref") $ref" || return 1
|
||||
done >expect &&
|
||||
git -C repo show-ref -d >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'basic: for-each-ref can print symrefs' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit file &&
|
||||
git branch &&
|
||||
git symbolic-ref refs/heads/sym refs/heads/main &&
|
||||
cat >expected <<-EOF &&
|
||||
refs/heads/main
|
||||
EOF
|
||||
git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
|
||||
test_cmp expected actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'basic: notes' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
write_script fake_editor <<-\EOF &&
|
||||
echo "$MSG" >"$1"
|
||||
echo "$MSG" >&2
|
||||
EOF
|
||||
|
||||
test_commit 1st &&
|
||||
test_commit 2nd &&
|
||||
GIT_EDITOR=./fake_editor MSG=b4 git notes add &&
|
||||
GIT_EDITOR=./fake_editor MSG=b3 git notes edit &&
|
||||
echo b4 >expect &&
|
||||
git notes --ref commits@{1} show >actual &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'basic: stash' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit file &&
|
||||
git stash list >expect &&
|
||||
test_line_count = 0 expect &&
|
||||
|
||||
echo hoi >>file.t &&
|
||||
git stash push -m stashed &&
|
||||
git stash list >expect &&
|
||||
test_line_count = 1 expect &&
|
||||
|
||||
git stash clear &&
|
||||
git stash list >expect &&
|
||||
test_line_count = 0 expect
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'basic: cherry-pick' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit message1 file1 &&
|
||||
test_commit message2 file2 &&
|
||||
git branch source &&
|
||||
git checkout HEAD^ &&
|
||||
test_commit message3 file3 &&
|
||||
git cherry-pick source &&
|
||||
test_path_is_file file2
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'basic: rebase' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit message1 file1 &&
|
||||
test_commit message2 file2 &&
|
||||
git branch source &&
|
||||
git checkout HEAD^ &&
|
||||
test_commit message3 file3 &&
|
||||
git rebase source &&
|
||||
test_path_is_file file2
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: can delete separate reflog entries' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
|
||||
test_commit file &&
|
||||
test_commit file2 &&
|
||||
test_commit file3 &&
|
||||
test_commit file4 &&
|
||||
git reflog >actual &&
|
||||
grep file3 actual &&
|
||||
|
||||
git reflog delete HEAD@{1} &&
|
||||
git reflog >actual &&
|
||||
! grep file3 actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: can switch to previous branch' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit file1 &&
|
||||
git checkout -b branch1 &&
|
||||
test_commit file2 &&
|
||||
git checkout -b branch2 &&
|
||||
git switch - &&
|
||||
git rev-parse --symbolic-full-name HEAD >actual &&
|
||||
echo refs/heads/branch1 >expect &&
|
||||
test_cmp actual expect
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: copying branch writes reflog entry' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit file1 &&
|
||||
test_commit file2 &&
|
||||
oid=$(git rev-parse --short HEAD) &&
|
||||
git branch src &&
|
||||
cat >expect <<-EOF &&
|
||||
${oid} dst@{0}: Branch: copied refs/heads/src to refs/heads/dst
|
||||
${oid} dst@{1}: branch: Created from main
|
||||
EOF
|
||||
git branch -c src dst &&
|
||||
git reflog dst >actual &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: renaming branch writes reflog entry' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
git symbolic-ref HEAD refs/heads/before &&
|
||||
test_commit file &&
|
||||
git show-ref >expected.refs &&
|
||||
sed s/before/after/g <expected.refs >expected &&
|
||||
git branch -M after &&
|
||||
git show-ref >actual &&
|
||||
test_cmp expected actual &&
|
||||
echo refs/heads/after >expected &&
|
||||
git symbolic-ref HEAD >actual &&
|
||||
test_cmp expected actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: can store empty logs' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
|
||||
test_must_fail test-tool ref-store main reflog-exists refs/heads/branch &&
|
||||
test-tool ref-store main create-reflog refs/heads/branch &&
|
||||
test-tool ref-store main reflog-exists refs/heads/branch &&
|
||||
test-tool ref-store main for-each-reflog-ent-reverse refs/heads/branch >actual &&
|
||||
test_must_be_empty actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: expiry empties reflog' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
|
||||
test_commit initial &&
|
||||
git checkout -b branch &&
|
||||
test_commit fileA &&
|
||||
test_commit fileB &&
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
commit: fileB
|
||||
commit: fileA
|
||||
branch: Created from HEAD
|
||||
EOF
|
||||
git reflog show --format="%gs" refs/heads/branch >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
git reflog expire branch --expire=all &&
|
||||
git reflog show --format="%gs" refs/heads/branch >actual &&
|
||||
test_must_be_empty actual &&
|
||||
test-tool ref-store main reflog-exists refs/heads/branch
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: can be deleted' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit initial &&
|
||||
test-tool ref-store main reflog-exists refs/heads/main &&
|
||||
test-tool ref-store main delete-reflog refs/heads/main &&
|
||||
test_must_fail test-tool ref-store main reflog-exists refs/heads/main
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: garbage collection deletes reflog entries' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
|
||||
for count in $(test_seq 1 10)
|
||||
do
|
||||
test_commit "number $count" file.t $count number-$count ||
|
||||
return 1
|
||||
done &&
|
||||
git reflog refs/heads/main >actual &&
|
||||
test_line_count = 10 actual &&
|
||||
grep "commit (initial): number 1" actual &&
|
||||
grep "commit: number 10" actual &&
|
||||
|
||||
git gc &&
|
||||
git reflog refs/heads/main >actual &&
|
||||
test_line_count = 0 actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reflog: updates via HEAD update HEAD reflog' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
test_commit main-one &&
|
||||
git checkout -b new-branch &&
|
||||
test_commit new-one &&
|
||||
test_commit new-two &&
|
||||
|
||||
echo new-one >expect &&
|
||||
git log -1 --format=%s HEAD@{1} >actual &&
|
||||
test_cmp expect actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: adding worktree creates separate stack' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
|
||||
git -C repo worktree add ../worktree &&
|
||||
test_path_is_file repo/.git/worktrees/worktree/refs/heads &&
|
||||
echo "ref: refs/heads/.invalid" >expect &&
|
||||
test_cmp expect repo/.git/worktrees/worktree/HEAD &&
|
||||
test_path_is_dir repo/.git/worktrees/worktree/reftable &&
|
||||
test_path_is_file repo/.git/worktrees/worktree/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: pack-refs in main repo packs main refs' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
git -C repo worktree add ../worktree &&
|
||||
|
||||
test_line_count = 3 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 4 repo/.git/reftable/tables.list &&
|
||||
git -C repo pack-refs &&
|
||||
test_line_count = 3 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: pack-refs in worktree packs worktree refs' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
git -C repo worktree add ../worktree &&
|
||||
|
||||
test_line_count = 3 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 4 repo/.git/reftable/tables.list &&
|
||||
git -C worktree pack-refs &&
|
||||
test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 4 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: creating shared ref updates main stack' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
|
||||
git -C repo worktree add ../worktree &&
|
||||
git -C repo pack-refs &&
|
||||
git -C worktree pack-refs &&
|
||||
test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list &&
|
||||
|
||||
git -C worktree update-ref refs/heads/shared HEAD &&
|
||||
test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 2 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: creating per-worktree ref updates worktree stack' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
|
||||
git -C repo worktree add ../worktree &&
|
||||
git -C repo pack-refs &&
|
||||
git -C worktree pack-refs &&
|
||||
test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list &&
|
||||
|
||||
git -C worktree update-ref refs/bisect/per-worktree HEAD &&
|
||||
test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: creating per-worktree ref from main repo' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
|
||||
git -C repo worktree add ../worktree &&
|
||||
git -C repo pack-refs &&
|
||||
git -C worktree pack-refs &&
|
||||
test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list &&
|
||||
|
||||
git -C repo update-ref worktrees/worktree/refs/bisect/per-worktree HEAD &&
|
||||
test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: creating per-worktree ref from second worktree' '
|
||||
test_when_finished "rm -rf repo wt1 wt2" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
|
||||
git -C repo worktree add ../wt1 &&
|
||||
git -C repo worktree add ../wt2 &&
|
||||
git -C repo pack-refs &&
|
||||
git -C wt1 pack-refs &&
|
||||
git -C wt2 pack-refs &&
|
||||
test_line_count = 1 repo/.git/worktrees/wt1/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/worktrees/wt2/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list &&
|
||||
|
||||
git -C wt1 update-ref worktrees/wt2/refs/bisect/per-worktree HEAD &&
|
||||
test_line_count = 1 repo/.git/worktrees/wt1/reftable/tables.list &&
|
||||
test_line_count = 2 repo/.git/worktrees/wt2/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: can create shared and per-worktree ref in one transaction' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
|
||||
git -C repo worktree add ../worktree &&
|
||||
git -C repo pack-refs &&
|
||||
git -C worktree pack-refs &&
|
||||
test_line_count = 1 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 1 repo/.git/reftable/tables.list &&
|
||||
|
||||
cat >stdin <<-EOF &&
|
||||
create worktrees/worktree/refs/bisect/per-worktree HEAD
|
||||
create refs/branches/shared HEAD
|
||||
EOF
|
||||
git -C repo update-ref --stdin <stdin &&
|
||||
test_line_count = 2 repo/.git/worktrees/worktree/reftable/tables.list &&
|
||||
test_line_count = 2 repo/.git/reftable/tables.list
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: can access common refs' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
git init repo &&
|
||||
test_commit -C repo file1 &&
|
||||
git -C repo branch branch1 &&
|
||||
git -C repo worktree add ../worktree &&
|
||||
|
||||
echo refs/heads/worktree >expect &&
|
||||
git -C worktree symbolic-ref HEAD >actual &&
|
||||
test_cmp expect actual &&
|
||||
git -C worktree checkout branch1
|
||||
'
|
||||
|
||||
test_expect_success 'worktree: adds worktree with detached HEAD' '
|
||||
test_when_finished "rm -rf repo worktree" &&
|
||||
|
||||
git init repo &&
|
||||
test_commit -C repo A &&
|
||||
git -C repo rev-parse main >expect &&
|
||||
|
||||
git -C repo worktree add --detach ../worktree main &&
|
||||
git -C worktree rev-parse HEAD >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'fetch: accessing FETCH_HEAD special ref works' '
|
||||
test_when_finished "rm -rf repo sub" &&
|
||||
|
||||
git init sub &&
|
||||
test_commit -C sub two &&
|
||||
git -C sub rev-parse HEAD >expect &&
|
||||
|
||||
git init repo &&
|
||||
test_commit -C repo one &&
|
||||
git -C repo fetch ../sub &&
|
||||
git -C repo rev-parse FETCH_HEAD >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_done
|
26
t/t0611-reftable-httpd.sh
Executable file
26
t/t0611-reftable-httpd.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='reftable HTTPD tests'
|
||||
|
||||
. ./test-lib.sh
|
||||
. "$TEST_DIRECTORY"/lib-httpd.sh
|
||||
|
||||
start_httpd
|
||||
|
||||
REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
|
||||
|
||||
test_expect_success 'serving ls-remote' '
|
||||
git init --ref-format=reftable -b main "$REPO" &&
|
||||
cd "$REPO" &&
|
||||
test_commit m1 &&
|
||||
>.git/git-daemon-export-ok &&
|
||||
git ls-remote "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" | cut -f 2-2 -d " " >actual &&
|
||||
cat >expect <<-EOF &&
|
||||
HEAD
|
||||
refs/heads/main
|
||||
refs/tags/m1
|
||||
EOF
|
||||
test_cmp actual expect
|
||||
'
|
||||
|
||||
test_done
|
@ -1755,6 +1755,8 @@ esac
|
||||
case "$GIT_DEFAULT_REF_FORMAT" in
|
||||
files)
|
||||
test_set_prereq REFFILES;;
|
||||
reftable)
|
||||
test_set_prereq REFTABLE;;
|
||||
*)
|
||||
echo 2>&1 "error: unknown ref format $GIT_DEFAULT_REF_FORMAT"
|
||||
exit 1
|
||||
|
Loading…
Reference in New Issue
Block a user