aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Makefile15
-rw-r--r--t/README4
-rw-r--r--t/helper/meson.build1
-rw-r--r--t/helper/test-hash-speed.c8
-rw-r--r--t/helper/test-hash.c6
-rw-r--r--t/helper/test-name-hash.c23
-rw-r--r--t/helper/test-path-walk.c22
-rw-r--r--t/helper/test-tool.c1
-rw-r--r--t/helper/test-tool.h1
-rw-r--r--t/meson.build10
-rwxr-xr-xt/perf/p5313-pack-objects.sh70
-rwxr-xr-xt/perf/p5314-name-hash.sh31
-rwxr-xr-xt/t0001-init.sh30
-rwxr-xr-xt/t0060-path-utils.sh10
-rw-r--r--t/t0450/txt-help-mismatches1
-rwxr-xr-xt/t3200-branch.sh14
-rwxr-xr-xt/t4100-apply-stat.sh13
-rwxr-xr-xt/t5300-pack-object.sh34
-rwxr-xr-xt/t5310-pack-bitmaps.sh35
-rwxr-xr-xt/t5333-pseudo-merge-bitmaps.sh3
-rwxr-xr-xt/t5401-update-hooks.sh16
-rwxr-xr-xt/t5504-fetch-receive-strict.sh35
-rwxr-xr-xt/t5505-remote.sh10
-rwxr-xr-xt/t5510-fetch.sh24
-rwxr-xr-xt/t5543-atomic-push.sh30
-rwxr-xr-xt/t5548-push-porcelain.sh443
-rwxr-xr-xt/t5620-backfill.sh211
-rwxr-xr-xt/t5621-clone-revision.sh122
-rwxr-xr-xt/t6020-bundle-misc.sh6
-rwxr-xr-xt/t6423-merge-rename-directories.sh9
-rwxr-xr-xt/t6500-gc.sh33
-rwxr-xr-xt/t6601-path-walk.sh32
-rwxr-xr-xt/t7406-submodule-update.sh4
-rwxr-xr-xt/t7422-submodule-output.sh43
-rwxr-xr-xt/t7700-repack.sh16
-rwxr-xr-xt/t7701-repack-unpack-unreachable.sh16
-rwxr-xr-xt/t9003-help-autocorrect.sh17
-rw-r--r--t/test-lib-functions.sh26
-rw-r--r--t/unit-tests/t-example-decorate.c74
-rw-r--r--t/unit-tests/t-reftable-stack.c54
-rw-r--r--t/unit-tests/t-strbuf.c122
-rw-r--r--t/unit-tests/t-strcmp-offset.c35
-rw-r--r--t/unit-tests/u-example-decorate.c64
-rw-r--r--t/unit-tests/u-hash.c6
-rw-r--r--t/unit-tests/u-hashmap.c (renamed from t/unit-tests/t-hashmap.c)226
-rw-r--r--t/unit-tests/u-strbuf.c119
-rw-r--r--t/unit-tests/u-strcmp-offset.c45
47 files changed, 1638 insertions, 532 deletions
diff --git a/t/Makefile b/t/Makefile
index daa5fcae86..2994eb5fa9 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -177,3 +177,18 @@ perf:
.PHONY: pre-clean $(T) aggregate-results clean valgrind perf \
check-chainlint clean-chainlint test-chainlint $(UNIT_TESTS)
+
+.PHONY: libgit-sys-test libgit-rs-test
+libgit-sys-test:
+ $(QUIET)(\
+ cd ../contrib/libgit-sys && \
+ cargo test \
+ )
+libgit-rs-test:
+ $(QUIET)(\
+ cd ../contrib/libgit-rs && \
+ cargo test \
+ )
+ifdef INCLUDE_LIBGIT_RS
+all:: libgit-sys-test libgit-rs-test
+endif
diff --git a/t/README b/t/README
index e84824dc00..53e5b4a710 100644
--- a/t/README
+++ b/t/README
@@ -471,6 +471,10 @@ a test and then fails then the whole test run will abort. This can help to make
sure the expected tests are executed and not silently skipped when their
dependency breaks or is simply not present in a new environment.
+GIT_TEST_NAME_HASH_VERSION=<int>, when set, causes 'git pack-objects' to
+assume '--name-hash-version=<n>'.
+
+
Naming Tests
------------
diff --git a/t/helper/meson.build b/t/helper/meson.build
index f502d1aaa3..1d6154ce97 100644
--- a/t/helper/meson.build
+++ b/t/helper/meson.build
@@ -34,6 +34,7 @@ test_tool_sources = [
'test-match-trees.c',
'test-mergesort.c',
'test-mktemp.c',
+ 'test-name-hash.c',
'test-online-cpus.c',
'test-pack-mtimes.c',
'test-parse-options.c',
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index 80df1aae66..fbf67fe6bd 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -3,16 +3,16 @@
#define NUM_SECONDS 3
-static inline void compute_hash(const struct git_hash_algo *algo, git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
+static inline void compute_hash(const struct git_hash_algo *algo, struct git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
{
algo->init_fn(ctx);
- algo->update_fn(ctx, p, len);
- algo->final_fn(final, ctx);
+ git_hash_update(ctx, p, len);
+ git_hash_final(final, ctx);
}
int cmd__hash_speed(int ac, const char **av)
{
- git_hash_ctx ctx;
+ struct git_hash_ctx ctx;
unsigned char hash[GIT_MAX_RAWSZ];
clock_t initial, start, end;
unsigned bufsizes[] = { 64, 256, 1024, 8192, 16384 };
diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c
index aa82638c62..f0ee61c8b4 100644
--- a/t/helper/test-hash.c
+++ b/t/helper/test-hash.c
@@ -3,7 +3,7 @@
int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
{
- git_hash_ctx ctx;
+ struct git_hash_ctx ctx;
unsigned char hash[GIT_MAX_HEXSZ];
unsigned bufsz = 8192;
int binary = 0;
@@ -48,9 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
}
if (this_sz == 0)
break;
- algop->update_fn(&ctx, buffer, this_sz);
+ git_hash_update(&ctx, buffer, this_sz);
}
- algop->final_fn(hash, &ctx);
+ git_hash_final(hash, &ctx);
if (binary)
fwrite(hash, 1, algop->rawsz, stdout);
diff --git a/t/helper/test-name-hash.c b/t/helper/test-name-hash.c
new file mode 100644
index 0000000000..af1d52de10
--- /dev/null
+++ b/t/helper/test-name-hash.c
@@ -0,0 +1,23 @@
+/*
+ * test-name-hash.c: Read a list of paths over stdin and report on their
+ * name-hash and full name-hash.
+ */
+
+#include "test-tool.h"
+#include "git-compat-util.h"
+#include "pack-objects.h"
+#include "strbuf.h"
+
+int cmd__name_hash(int argc UNUSED, const char **argv UNUSED)
+{
+ struct strbuf line = STRBUF_INIT;
+
+ while (!strbuf_getline(&line, stdin)) {
+ printf("%10u ", pack_name_hash(line.buf));
+ printf("%10u ", pack_name_hash_v2((unsigned const char *)line.buf));
+ printf("%s\n", line.buf);
+ }
+
+ strbuf_release(&line);
+ return 0;
+}
diff --git a/t/helper/test-path-walk.c b/t/helper/test-path-walk.c
index 7f2d409c5b..61e845e5ec 100644
--- a/t/helper/test-path-walk.c
+++ b/t/helper/test-path-walk.c
@@ -1,6 +1,7 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "test-tool.h"
+#include "dir.h"
#include "environment.h"
#include "hex.h"
#include "object-name.h"
@@ -9,6 +10,7 @@
#include "revision.h"
#include "setup.h"
#include "parse-options.h"
+#include "strbuf.h"
#include "path-walk.h"
#include "oid-array.h"
@@ -65,7 +67,7 @@ static int emit_block(const char *path, struct oid_array *oids,
int cmd__path_walk(int argc, const char **argv)
{
- int res;
+ int res, stdin_pl = 0;
struct rev_info revs = REV_INFO_INIT;
struct path_walk_info info = PATH_WALK_INFO_INIT;
struct path_walk_test_data data = { 0 };
@@ -80,6 +82,8 @@ int cmd__path_walk(int argc, const char **argv)
N_("toggle inclusion of tree objects")),
OPT_BOOL(0, "prune", &info.prune_all_uninteresting,
N_("toggle pruning of uninteresting paths")),
+ OPT_BOOL(0, "stdin-pl", &stdin_pl,
+ N_("read a pattern list over stdin")),
OPT_END(),
};
@@ -99,6 +103,17 @@ int cmd__path_walk(int argc, const char **argv)
info.path_fn = emit_block;
info.path_fn_data = &data;
+ if (stdin_pl) {
+ struct strbuf in = STRBUF_INIT;
+ CALLOC_ARRAY(info.pl, 1);
+
+ info.pl->use_cone_patterns = 1;
+
+ strbuf_fread(&in, 2048, stdin);
+ add_patterns_from_buffer(in.buf, in.len, "", 0, info.pl);
+ strbuf_release(&in);
+ }
+
res = walk_objects_by_path(&info);
printf("commits:%" PRIuMAX "\n"
@@ -107,6 +122,11 @@ int cmd__path_walk(int argc, const char **argv)
"tags:%" PRIuMAX "\n",
data.commit_nr, data.tree_nr, data.blob_nr, data.tag_nr);
+ if (info.pl) {
+ clear_pattern_list(info.pl);
+ free(info.pl);
+ }
+
release_revisions(&revs);
return res;
}
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index e8bc94862e..50dc4dac4e 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -44,6 +44,7 @@ static struct test_cmd cmds[] = {
{ "match-trees", cmd__match_trees },
{ "mergesort", cmd__mergesort },
{ "mktemp", cmd__mktemp },
+ { "name-hash", cmd__name_hash },
{ "online-cpus", cmd__online_cpus },
{ "pack-mtimes", cmd__pack_mtimes },
{ "parse-options", cmd__parse_options },
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index fb4c609254..6d62a5b53d 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -37,6 +37,7 @@ int cmd__lazy_init_name_hash(int argc, const char **argv);
int cmd__match_trees(int argc, const char **argv);
int cmd__mergesort(int argc, const char **argv);
int cmd__mktemp(int argc, const char **argv);
+int cmd__name_hash(int argc, const char **argv);
int cmd__online_cpus(int argc, const char **argv);
int cmd__pack_mtimes(int argc, const char **argv);
int cmd__parse_options(int argc, const char **argv);
diff --git a/t/meson.build b/t/meson.build
index 35f25ca4a1..780939d49f 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -1,9 +1,13 @@
clar_test_suites = [
'unit-tests/u-ctype.c',
+ 'unit-tests/u-example-decorate.c',
'unit-tests/u-hash.c',
+ 'unit-tests/u-hashmap.c',
'unit-tests/u-mem-pool.c',
'unit-tests/u-prio-queue.c',
'unit-tests/u-reftable-tree.c',
+ 'unit-tests/u-strbuf.c',
+ 'unit-tests/u-strcmp-offset.c',
'unit-tests/u-strvec.c',
]
@@ -44,8 +48,6 @@ clar_unit_tests = executable('unit-tests',
test('unit-tests', clar_unit_tests)
unit_test_programs = [
- 'unit-tests/t-example-decorate.c',
- 'unit-tests/t-hashmap.c',
'unit-tests/t-oid-array.c',
'unit-tests/t-oidmap.c',
'unit-tests/t-oidtree.c',
@@ -57,8 +59,6 @@ unit_test_programs = [
'unit-tests/t-reftable-readwrite.c',
'unit-tests/t-reftable-record.c',
'unit-tests/t-reftable-stack.c',
- 'unit-tests/t-strbuf.c',
- 'unit-tests/t-strcmp-offset.c',
'unit-tests/t-trailer.c',
'unit-tests/t-urlmatch-normalization.c',
]
@@ -721,6 +721,8 @@ integration_tests = [
't5617-clone-submodules-remote.sh',
't5618-alternate-refs.sh',
't5619-clone-local-ambiguous-transport.sh',
+ 't5620-backfill.sh',
+ 't5621-clone-revision.sh',
't5700-protocol-v1.sh',
't5701-git-serve.sh',
't5702-protocol-v2.sh',
diff --git a/t/perf/p5313-pack-objects.sh b/t/perf/p5313-pack-objects.sh
new file mode 100755
index 0000000000..be5229a0ec
--- /dev/null
+++ b/t/perf/p5313-pack-objects.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+test_description='Tests pack performance using bitmaps'
+. ./perf-lib.sh
+
+GIT_TEST_PASSING_SANITIZE_LEAK=0
+export GIT_TEST_PASSING_SANITIZE_LEAK
+
+test_perf_large_repo
+
+test_expect_success 'create rev input' '
+ cat >in-thin <<-EOF &&
+ $(git rev-parse HEAD)
+ ^$(git rev-parse HEAD~1)
+ EOF
+
+ cat >in-big <<-EOF &&
+ $(git rev-parse HEAD)
+ ^$(git rev-parse HEAD~1000)
+ EOF
+
+ cat >in-shallow <<-EOF
+ $(git rev-parse HEAD)
+ --shallow $(git rev-parse HEAD)
+ EOF
+'
+
+for version in 1 2
+do
+ export version
+
+ test_perf "thin pack with version $version" '
+ git pack-objects --thin --stdout --revs --sparse \
+ --name-hash-version=$version <in-thin >out
+ '
+
+ test_size "thin pack size with version $version" '
+ test_file_size out
+ '
+
+ test_perf "big pack with version $version" '
+ git pack-objects --stdout --revs --sparse \
+ --name-hash-version=$version <in-big >out
+ '
+
+ test_size "big pack size with version $version" '
+ test_file_size out
+ '
+
+ test_perf "shallow fetch pack with version $version" '
+ git pack-objects --stdout --revs --sparse --shallow \
+ --name-hash-version=$version <in-shallow >out
+ '
+
+ test_size "shallow pack size with version $version" '
+ test_file_size out
+ '
+
+ test_perf "repack with version $version" '
+ git repack -adf --name-hash-version=$version
+ '
+
+ test_size "repack size with version $version" '
+ gitdir=$(git rev-parse --git-dir) &&
+ pack=$(ls $gitdir/objects/pack/pack-*.pack) &&
+ test_file_size "$pack"
+ '
+done
+
+test_done
diff --git a/t/perf/p5314-name-hash.sh b/t/perf/p5314-name-hash.sh
new file mode 100755
index 0000000000..4ef0ba7711
--- /dev/null
+++ b/t/perf/p5314-name-hash.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+test_description='Tests pack performance using bitmaps'
+. ./perf-lib.sh
+
+GIT_TEST_PASSING_SANITIZE_LEAK=0
+export GIT_TEST_PASSING_SANITIZE_LEAK
+
+test_perf_large_repo
+
+test_size 'paths at head' '
+ git ls-tree -r --name-only HEAD >path-list &&
+ wc -l <path-list &&
+ test-tool name-hash <path-list >name-hashes
+'
+
+for version in 1 2
+do
+ test_size "distinct hash value: v$version" '
+ awk "{ print \$$version; }" <name-hashes | sort | \
+ uniq -c >name-hash-count &&
+ wc -l <name-hash-count
+ '
+
+ test_size "maximum multiplicity: v$version" '
+ sort -nr <name-hash-count | head -n 1 | \
+ awk "{ print \$1; }"
+ '
+done
+
+test_done
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 72a0c2e7d4..c49d9e0d38 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -586,6 +586,18 @@ test_expect_success 'GIT_DEFAULT_HASH overrides init.defaultObjectFormat' '
echo sha256 >expected
'
+for hash in sha1 sha256
+do
+ test_expect_success "reinit repository with GIT_DEFAULT_HASH=$hash does not change format" '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ git -C repo rev-parse --show-object-format >expect &&
+ GIT_DEFAULT_HASH=$hash git init repo &&
+ git -C repo rev-parse --show-object-format >actual &&
+ test_cmp expect actual
+ '
+done
+
test_expect_success 'extensions.objectFormat is not allowed with repo version 0' '
test_when_finished "rm -rf explicit-v0" &&
git init --object-format=sha256 explicit-v0 &&
@@ -697,6 +709,15 @@ do
git -C refformat rev-parse --show-ref-format >actual &&
test_cmp expect actual
'
+
+ test_expect_success "reinit repository with GIT_DEFAULT_REF_FORMAT=$format does not change format" '
+ test_when_finished "rm -rf refformat" &&
+ git init refformat &&
+ git -C refformat rev-parse --show-ref-format >expect &&
+ GIT_DEFAULT_REF_FORMAT=$format git init refformat &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+ '
done
test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" '
@@ -861,15 +882,6 @@ test_expect_success 're-init with includeIf.onbranch condition' '
test_cmp expect actual
'
-test_expect_success 're-init with includeIf.onbranch condition' '
- test_when_finished "rm -rf repo" &&
- git init repo &&
- git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo &&
- echo $GIT_DEFAULT_REF_FORMAT >expect &&
- git -C repo rev-parse --show-ref-format >actual &&
- test_cmp expect actual
-'
-
test_expect_success 're-init skips non-matching includeIf.onbranch' '
test_when_finished "rm -rf repo config" &&
cat >config <<-EOF &&
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index dbb2e73bcd..8545cdfab5 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -592,17 +592,19 @@ test_lazy_prereq CAN_EXEC_IN_PWD '
./git rev-parse
'
+test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'setup runtime prefix' '
+ mkdir -p pretend/bin &&
+ cp "$GIT_EXEC_PATH"/git$X pretend/bin/
+'
+
test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' '
- mkdir -p pretend/bin pretend/libexec/git-core &&
+ mkdir -p pretend/libexec/git-core &&
echo "echo HERE" | write_script pretend/libexec/git-core/git-here &&
- cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
GIT_EXEC_PATH= ./pretend/bin/git here >actual &&
echo HERE >expect &&
test_cmp expect actual'
test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' '
- mkdir -p pretend/bin &&
- cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
git config yes.path "%(prefix)/yes" &&
GIT_EXEC_PATH= ./pretend/bin/git config --path yes.path >actual &&
echo "$(pwd)/pretend/yes" >expect &&
diff --git a/t/t0450/txt-help-mismatches b/t/t0450/txt-help-mismatches
index 28003f18c9..c4a15fd0cb 100644
--- a/t/t0450/txt-help-mismatches
+++ b/t/t0450/txt-help-mismatches
@@ -45,7 +45,6 @@ rebase
remote
remote-ext
remote-fd
-repack
reset
restore
rev-parse
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index a3a21c54cf..f3e720dc10 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -410,6 +410,20 @@ test_expect_success 'bare main worktree has HEAD at branch deleted by secondary
git -C secondary branch -D main
'
+test_expect_success 'secondary worktrees recognize core.bare=true in main config.worktree' '
+ test_when_finished "rm -rf bare_repo non_bare_repo secondary_worktree" &&
+ git init -b main non_bare_repo &&
+ test_commit -C non_bare_repo x &&
+
+ git clone --bare non_bare_repo bare_repo &&
+ git -C bare_repo config extensions.worktreeConfig true &&
+ git -C bare_repo config unset core.bare &&
+ git -C bare_repo config --worktree core.bare true &&
+
+ git -C bare_repo worktree add ../secondary_worktree &&
+ git -C secondary_worktree checkout main
+'
+
test_expect_success 'git branch --list -v with --abbrev' '
test_when_finished "git branch -D t" &&
git branch t &&
diff --git a/t/t4100-apply-stat.sh b/t/t4100-apply-stat.sh
index 146e73d8f5..a5664f3eb3 100755
--- a/t/t4100-apply-stat.sh
+++ b/t/t4100-apply-stat.sh
@@ -38,4 +38,17 @@ incomplete (1)
incomplete (2)
EOF
+test_expect_success 'applying a hunk header which overflows fails' '
+ cat >patch <<-\EOF &&
+ diff -u a/file b/file
+ --- a/file
+ +++ b/file
+ @@ -98765432109876543210 +98765432109876543210 @@
+ -a
+ +b
+ EOF
+ test_must_fail git apply patch 2>err &&
+ echo "error: corrupt patch at line 4" >expect &&
+ test_cmp expect err
+'
test_done
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index d1d6248558..5ac8d39094 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -689,4 +689,38 @@ do
'
done
+test_expect_success 'valid and invalid --name-hash-versions' '
+ sane_unset GIT_TEST_NAME_HASH_VERSION &&
+
+ # Valid values are hard to verify other than "do not fail".
+ # Performance tests will be more valuable to validate these versions.
+ # Negative values are converted to version 1.
+ for value in -1 1 2
+ do
+ git pack-objects base --all --name-hash-version=$value || return 1
+ done &&
+
+ # Invalid values have clear post-conditions.
+ for value in 0 3
+ do
+ test_must_fail git pack-objects base --all --name-hash-version=$value 2>err &&
+ test_grep "invalid --name-hash-version option" err || return 1
+ done
+'
+
+# The following test is not necessarily a permanent choice, but since we do not
+# have a "name hash version" bit in the .bitmap file format, we cannot write the
+# hash values into the .bitmap file without risking breakage later.
+#
+# TODO: Make these compatible in the future and replace this test with the
+# expected behavior when both are specified.
+test_expect_success '--name-hash-version=2 and --write-bitmap-index are incompatible' '
+ git pack-objects base --all --name-hash-version=2 --write-bitmap-index 2>err &&
+ test_grep "currently, --write-bitmap-index requires --name-hash-version=1" err &&
+
+ # --stdout option silently removes --write-bitmap-index
+ git pack-objects --stdout --all --name-hash-version=2 --write-bitmap-index >out 2>err &&
+ ! test_grep "currently, --write-bitmap-index requires --name-hash-version=1" err
+'
+
test_done
diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh
index eabfcd7ff6..621bbbdd26 100755
--- a/t/t5310-pack-bitmaps.sh
+++ b/t/t5310-pack-bitmaps.sh
@@ -26,6 +26,36 @@ has_any () {
grep -Ff "$1" "$2"
}
+# Since name-hash values are stored in the .bitmap files, add a test
+# that checks that the name-hash calculations are stable across versions.
+# Not exhaustive, but these hashing algorithms would be hard to change
+# without causing deviations here.
+test_expect_success 'name-hash value stability' '
+ cat >names <<-\EOF &&
+ first
+ second
+ third
+ a/one-long-enough-for-collisions
+ b/two-long-enough-for-collisions
+ many/parts/to/this/path/enough/to/collide/in/v2
+ enough/parts/to/this/path/enough/to/collide/in/v2
+ EOF
+
+ test-tool name-hash <names >out &&
+
+ cat >expect <<-\EOF &&
+ 2582249472 1763573760 first
+ 2289942528 1188134912 second
+ 2300837888 1130758144 third
+ 2544516325 3963087891 a/one-long-enough-for-collisions
+ 2544516325 4013419539 b/two-long-enough-for-collisions
+ 1420111091 1709547268 many/parts/to/this/path/enough/to/collide/in/v2
+ 1420111091 1709547268 enough/parts/to/this/path/enough/to/collide/in/v2
+ EOF
+
+ test_cmp expect out
+'
+
test_bitmap_cases () {
writeLookupTable=false
for i in "$@"
@@ -419,7 +449,10 @@ test_bitmap_cases () {
cat >expect <<-\EOF &&
error: missing value for '\''pack.preferbitmaptips'\''
EOF
- git repack -adb 2>actual &&
+
+ # Disable name hash version adjustment due to stderr comparison.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git repack -adb 2>actual &&
test_cmp expect actual
)
'
diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh
index 1dd6284756..3905cb6e4f 100755
--- a/t/t5333-pseudo-merge-bitmaps.sh
+++ b/t/t5333-pseudo-merge-bitmaps.sh
@@ -208,7 +208,8 @@ test_expect_success 'bitmapPseudoMerge.stableThreshold creates stable groups' '
'
test_expect_success 'out of order thresholds are rejected' '
- test_must_fail git \
+ # Disable the test var to remove a stderr message.
+ test_must_fail env GIT_TEST_NAME_HASH_VERSION=1 git \
-c bitmapPseudoMerge.test.pattern="refs/*" \
-c bitmapPseudoMerge.test.threshold=1.month.ago \
-c bitmapPseudoMerge.test.stableThreshold=1.week.ago \
diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh
index 723d1e17ec..17a46fd3ba 100755
--- a/t/t5401-update-hooks.sh
+++ b/t/t5401-update-hooks.sh
@@ -64,14 +64,14 @@ test_expect_success 'updated as expected' '
'
test_expect_success 'hooks ran' '
- test -f victim.git/pre-receive.args &&
- test -f victim.git/pre-receive.stdin &&
- test -f victim.git/update.args &&
- test -f victim.git/update.stdin &&
- test -f victim.git/post-receive.args &&
- test -f victim.git/post-receive.stdin &&
- test -f victim.git/post-update.args &&
- test -f victim.git/post-update.stdin
+ test_path_is_file victim.git/pre-receive.args &&
+ test_path_is_file victim.git/pre-receive.stdin &&
+ test_path_is_file victim.git/update.args &&
+ test_path_is_file victim.git/update.stdin &&
+ test_path_is_file victim.git/post-receive.args &&
+ test_path_is_file victim.git/post-receive.stdin &&
+ test_path_is_file victim.git/post-update.args &&
+ test_path_is_file victim.git/post-update.stdin
'
test_expect_success 'pre-receive hook input' '
diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh
index e273ab29c7..58074506c5 100755
--- a/t/t5504-fetch-receive-strict.sh
+++ b/t/t5504-fetch-receive-strict.sh
@@ -64,12 +64,6 @@ test_expect_success 'fetch with transfer.fsckobjects' '
)
'
-cat >exp <<EOF
-To dst
-! refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
-Done
-EOF
-
test_expect_success 'push without strict' '
rm -rf dst &&
git init dst &&
@@ -78,6 +72,11 @@ test_expect_success 'push without strict' '
git config fetch.fsckobjects false &&
git config transfer.fsckobjects false
) &&
+ cat >exp <<-\EOF &&
+ To dst
+ ! refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
+ Done
+ EOF
test_must_fail git push --porcelain dst main:refs/heads/test >act &&
test_cmp exp act
'
@@ -94,11 +93,6 @@ test_expect_success 'push with !receive.fsckobjects' '
test_cmp exp act
'
-cat >exp <<EOF
-To dst
-! refs/heads/main:refs/heads/test [remote rejected] (unpacker error)
-EOF
-
test_expect_success 'push with receive.fsckobjects' '
rm -rf dst &&
git init dst &&
@@ -107,6 +101,10 @@ test_expect_success 'push with receive.fsckobjects' '
git config receive.fsckobjects true &&
git config transfer.fsckobjects false
) &&
+ cat >exp <<-\EOF &&
+ To dst
+ ! refs/heads/main:refs/heads/test [remote rejected] (unpacker error)
+ EOF
test_must_fail git push --porcelain dst main:refs/heads/test >act &&
test_cmp exp act
'
@@ -129,15 +127,14 @@ test_expect_success 'repair the "corrupt or missing" object' '
git fsck
'
-cat >bogus-commit <<EOF
-tree $EMPTY_TREE
-author Bugs Bunny 1234567890 +0000
-committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
-
-This commit object intentionally broken
-EOF
-
test_expect_success 'setup bogus commit' '
+ cat >bogus-commit <<-EOF &&
+ tree $EMPTY_TREE
+ author Bugs Bunny 1234567890 +0000
+ committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
+
+ This commit object intentionally broken
+ EOF
commit="$(git hash-object --literally -t commit -w --stdin <bogus-commit)"
'
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 93a6662df7..bb7e0c6879 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '
)
'
+test_expect_success 'non-mirror fetch does not interfere with mirror' '
+ test_when_finished rm -rf headnotmain &&
+ (
+ git init --bare -b notmain headnotmain &&
+ cd headnotmain &&
+ git remote add -f other ../two &&
+ test "$(git symbolic-ref HEAD)" = "refs/heads/notmain"
+ )
+'
+
test_expect_success 'add --mirror=fetch' '
mkdir mirror-fetch &&
git init -b main mirror-fetch/parent &&
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 0b89aca77e..5f350facf5 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -81,6 +81,23 @@ test_expect_success "fetch test remote HEAD" '
branch=$(git rev-parse refs/remotes/origin/main) &&
test "z$head" = "z$branch"'
+test_expect_success "fetch test remote HEAD in bare repository" '
+ test_when_finished rm -rf barerepo &&
+ (
+ cd "$D" &&
+ git init --bare barerepo &&
+ cd barerepo &&
+ git remote add upstream ../two &&
+ git fetch upstream &&
+ git rev-parse --verify refs/remotes/upstream/HEAD &&
+ git rev-parse --verify refs/remotes/upstream/main &&
+ head=$(git rev-parse refs/remotes/upstream/HEAD) &&
+ branch=$(git rev-parse refs/remotes/upstream/main) &&
+ test "z$head" = "z$branch"
+ )
+'
+
+
test_expect_success "fetch test remote HEAD change" '
cd "$D" &&
cd two &&
@@ -1237,7 +1254,12 @@ test_expect_success 'all boundary commits are excluded' '
test_tick &&
git merge otherside &&
ad=$(git log --no-walk --format=%ad HEAD) &&
- git bundle create twoside-boundary.bdl main --since="$ad" &&
+
+ # If the a different name hash function is used here, then no delta
+ # pair is found and the bundle does not expand to three objects
+ # when fixing the thin object.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git bundle create twoside-boundary.bdl main --since="$ad" &&
test_bundle_object_count --thin twoside-boundary.bdl 3
'
diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh
index 04b47ad84a..3a700b0676 100755
--- a/t/t5543-atomic-push.sh
+++ b/t/t5543-atomic-push.sh
@@ -280,4 +280,34 @@ test_expect_success 'atomic push reports (reject by non-ff)' '
test_cmp expect actual
'
+test_expect_success 'atomic push reports exit code failure' '
+ write_script receive-pack-wrapper <<-\EOF &&
+ git-receive-pack "$@"
+ exit 1
+ EOF
+ test_must_fail git -C workbench push --atomic \
+ --receive-pack="${SQ}$(pwd)${SQ}/receive-pack-wrapper" \
+ up HEAD:refs/heads/no-conflict 2>err &&
+ cat >expect <<-EOF &&
+ To ../upstream
+ * [new branch] HEAD -> no-conflict
+ error: failed to push some refs to ${SQ}../upstream${SQ}
+ EOF
+ test_cmp expect err
+'
+
+test_expect_success 'atomic push reports exit code failure with porcelain' '
+ write_script receive-pack-wrapper <<-\EOF &&
+ git-receive-pack "$@"
+ exit 1
+ EOF
+ test_must_fail git -C workbench push --atomic --porcelain \
+ --receive-pack="${SQ}$(pwd)${SQ}/receive-pack-wrapper" \
+ up HEAD:refs/heads/no-conflict-porcelain 2>err &&
+ cat >expect <<-EOF &&
+ error: failed to push some refs to ${SQ}../upstream${SQ}
+ EOF
+ test_cmp expect err
+'
+
test_done
diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh
index 6282728eaf..4c19404ebe 100755
--- a/t/t5548-push-porcelain.sh
+++ b/t/t5548-push-porcelain.sh
@@ -54,29 +54,67 @@ format_and_save_expect () {
sed -e 's/^> //' -e 's/Z$//' >expect
}
+create_upstream_template () {
+ git init --bare upstream-template.git &&
+ git clone upstream-template.git tmp_work_dir &&
+ create_commits_in tmp_work_dir A B &&
+ (
+ cd tmp_work_dir &&
+ git push origin \
+ $B:refs/heads/main \
+ $A:refs/heads/foo \
+ $A:refs/heads/bar \
+ $A:refs/heads/baz
+ ) &&
+ rm -rf tmp_work_dir
+}
+
+setup_upstream () {
+ if test $# -ne 1
+ then
+ BUG "location of upstream repository is not provided"
+ fi &&
+ rm -rf "$1" &&
+ if ! test -d upstream-template.git
+ then
+ create_upstream_template
+ fi &&
+ git clone --mirror upstream-template.git "$1" &&
+ # The upstream repository provides services using the HTTP protocol.
+ if ! test "$1" = "upstream.git"
+ then
+ git -C "$1" config http.receivepack true
+ fi
+}
+
setup_upstream_and_workbench () {
- # Upstream after setup : main(B) foo(A) bar(A) baz(A)
- # Workbench after setup : main(A)
+ if test $# -ne 1
+ then
+ BUG "location of upstream repository is not provided"
+ fi
+ upstream="$1"
+
+ # Upstream after setup: main(B) foo(A) bar(A) baz(A)
+ # Workbench after setup: main(A) baz(A) next(A)
test_expect_success "setup upstream repository and workbench" '
- rm -rf upstream.git workbench &&
- git init --bare upstream.git &&
- git init workbench &&
- create_commits_in workbench A B &&
+ setup_upstream "$upstream" &&
+ rm -rf workbench &&
+ git clone "$upstream" workbench &&
(
cd workbench &&
+ git update-ref refs/heads/main $A &&
+ git update-ref refs/heads/baz $A &&
+ git update-ref refs/heads/next $A &&
# Try to make a stable fixed width for abbreviated commit ID,
# this fixed-width oid will be replaced with "<OID>".
git config core.abbrev 7 &&
- git remote add origin ../upstream.git &&
- git update-ref refs/heads/main $A &&
- git push origin \
- $B:refs/heads/main \
- $A:refs/heads/foo \
- $A:refs/heads/bar \
- $A:refs/heads/baz
+ git config advice.pushUpdateRejected false
) &&
- git -C "workbench" config advice.pushUpdateRejected false &&
- upstream=upstream.git
+ # The upstream repository provides services using the HTTP protocol.
+ if ! test "$upstream" = "upstream.git"
+ then
+ git -C workbench remote set-url origin "$HTTPD_URL/smart/upstream.git"
+ fi
'
}
@@ -88,34 +126,29 @@ run_git_push_porcelain_output_test() {
;;
file)
PROTOCOL="builtin protocol"
- URL_PREFIX="\.\."
+ URL_PREFIX=".*"
;;
esac
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
# Refs of workbench: main(A) baz(A) next(A)
# git-push : main(A) NULL (B) baz(A) next(A)
- test_expect_success "porcelain output of successful git-push ($PROTOCOL)" '
- (
- cd workbench &&
- git update-ref refs/heads/main $A &&
- git update-ref refs/heads/baz $A &&
- git update-ref refs/heads/next $A &&
- git push --porcelain --force origin \
- main \
- :refs/heads/foo \
- $B:bar \
- baz \
- next
- ) >out &&
+ test_expect_success ".. git-push --porcelain ($PROTOCOL)" '
+ test_when_finished "setup_upstream \"$upstream\"" &&
+ test_must_fail git -C workbench push --porcelain origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
make_user_friendly_and_stable_output <out >actual &&
- format_and_save_expect <<-EOF &&
+ format_and_save_expect <<-\EOF &&
> To <URL/of/upstream.git>
> = refs/heads/baz:refs/heads/baz [up to date]
> <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
> - :refs/heads/foo [deleted]
- > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
> * refs/heads/next:refs/heads/next [new branch]
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
> Done
EOF
test_cmp expect actual &&
@@ -125,34 +158,32 @@ run_git_push_porcelain_output_test() {
cat >expect <<-EOF &&
<COMMIT-B> refs/heads/bar
<COMMIT-A> refs/heads/baz
- <COMMIT-A> refs/heads/main
+ <COMMIT-B> refs/heads/main
<COMMIT-A> refs/heads/next
EOF
test_cmp expect actual
'
- # Refs of upstream : main(A) bar(B) baz(A) next(A)
- # Refs of workbench: main(B) bar(A) baz(A) next(A)
- # git-push : main(B) bar(A) NULL next(A)
- test_expect_success "atomic push failed ($PROTOCOL)" '
- (
- cd workbench &&
- git update-ref refs/heads/main $B &&
- git update-ref refs/heads/bar $A &&
- test_must_fail git push --atomic --porcelain origin \
- main \
- bar \
- :baz \
- next
- ) >out &&
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --force ($PROTOCOL)" '
+ test_when_finished "setup_upstream \"$upstream\"" &&
+ git -C workbench push --porcelain --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
make_user_friendly_and_stable_output <out >actual &&
format_and_save_expect <<-EOF &&
- To <URL/of/upstream.git>
- > = refs/heads/next:refs/heads/next [up to date]
- > ! refs/heads/bar:refs/heads/bar [rejected] (non-fast-forward)
- > ! (delete):refs/heads/baz [rejected] (atomic push failed)
- > ! refs/heads/main:refs/heads/main [rejected] (atomic push failed)
- Done
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
+ > * refs/heads/next:refs/heads/next [new branch]
+ > Done
EOF
test_cmp expect actual &&
@@ -167,34 +198,129 @@ run_git_push_porcelain_output_test() {
test_cmp expect actual
'
- test_expect_success "prepare pre-receive hook ($PROTOCOL)" '
- test_hook --setup -C "$upstream" pre-receive <<-EOF
- exit 1
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git push --porcelain --atomic ($PROTOCOL)" '
+ test_when_finished "setup_upstream \"$upstream\"" &&
+ test_must_fail git -C workbench push --porcelain --atomic origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > ! <COMMIT-B>:refs/heads/bar [rejected] (atomic push failed)
+ > ! (delete):refs/heads/foo [rejected] (atomic push failed)
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
+ > ! refs/heads/next:refs/heads/next [rejected] (atomic push failed)
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ EOF
+ test_cmp expect actual
+ '
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. pre-receive hook declined ($PROTOCOL)" '
+ test_when_finished "rm -f \"$upstream/hooks/pre-receive\" &&
+ setup_upstream \"$upstream\"" &&
+ test_hook --setup -C "$upstream" pre-receive <<-EOF &&
+ exit 1
+ EOF
+ test_must_fail git -C workbench push --porcelain --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > ! <COMMIT-B>:refs/heads/bar [remote rejected] (pre-receive hook declined)
+ > ! :refs/heads/foo [remote rejected] (pre-receive hook declined)
+ > ! refs/heads/main:refs/heads/main [remote rejected] (pre-receive hook declined)
+ > ! refs/heads/next:refs/heads/next [remote rejected] (pre-receive hook declined)
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
EOF
+ test_cmp expect actual
'
- # Refs of upstream : main(A) bar(B) baz(A) next(A)
- # Refs of workbench: main(B) bar(A) baz(A) next(A)
- # git-push : main(B) bar(A) NULL next(A)
- test_expect_success "pre-receive hook declined ($PROTOCOL)" '
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) next(A)
+ test_expect_success ".. non-fastforward push ($PROTOCOL)" '
+ test_when_finished "setup_upstream \"$upstream\"" &&
(
cd workbench &&
- git update-ref refs/heads/main $B &&
- git update-ref refs/heads/bar $A &&
- test_must_fail git push --porcelain --force origin \
+ test_must_fail git push --porcelain origin \
main \
- bar \
- :baz \
next
) >out &&
make_user_friendly_and_stable_output <out >actual &&
format_and_save_expect <<-EOF &&
- To <URL/of/upstream.git>
- > = refs/heads/next:refs/heads/next [up to date]
- > ! refs/heads/bar:refs/heads/bar [remote rejected] (pre-receive hook declined)
- > ! :refs/heads/baz [remote rejected] (pre-receive hook declined)
- > ! refs/heads/main:refs/heads/main [remote rejected] (pre-receive hook declined)
- Done
+ > To <URL/of/upstream.git>
+ > * refs/heads/next:refs/heads/next [new branch]
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ <COMMIT-A> refs/heads/next
+ EOF
+ test_cmp expect actual
+ '
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git push --porcelain --atomic --force ($PROTOCOL)" '
+ git -C workbench push --porcelain --atomic --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-\EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
+ > * refs/heads/next:refs/heads/next [new branch]
+ > Done
EOF
test_cmp expect actual &&
@@ -208,71 +334,174 @@ run_git_push_porcelain_output_test() {
EOF
test_cmp expect actual
'
+}
- test_expect_success "remove pre-receive hook ($PROTOCOL)" '
- rm "$upstream/hooks/pre-receive"
+run_git_push_dry_run_porcelain_output_test() {
+ case $1 in
+ http)
+ PROTOCOL="HTTP protocol"
+ URL_PREFIX="http://.*"
+ ;;
+ file)
+ PROTOCOL="builtin protocol"
+ URL_PREFIX=".*"
+ ;;
+ esac
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --dry-run ($PROTOCOL)" '
+ test_must_fail git -C workbench push --porcelain --dry-run origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > * refs/heads/next:refs/heads/next [new branch]
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ EOF
+ test_cmp expect actual
'
- # Refs of upstream : main(A) bar(B) baz(A) next(A)
- # Refs of workbench: main(B) bar(A) baz(A) next(A)
- # git-push : main(B) bar(A) NULL next(A)
- test_expect_success "non-fastforward push ($PROTOCOL)" '
- (
- cd workbench &&
- test_must_fail git push --porcelain origin \
- main \
- bar \
- :baz \
- next
- ) >out &&
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --dry-run --force ($PROTOCOL)" '
+ git -C workbench push --porcelain --dry-run --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
+ > * refs/heads/next:refs/heads/next [new branch]
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ EOF
+ test_cmp expect actual
+ '
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --dry-run --atomic ($PROTOCOL)" '
+ test_must_fail git -C workbench push --porcelain --dry-run --atomic origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
make_user_friendly_and_stable_output <out >actual &&
format_and_save_expect <<-EOF &&
- To <URL/of/upstream.git>
- > = refs/heads/next:refs/heads/next [up to date]
- > - :refs/heads/baz [deleted]
- > refs/heads/main:refs/heads/main <COMMIT-A>..<COMMIT-B>
- > ! refs/heads/bar:refs/heads/bar [rejected] (non-fast-forward)
- Done
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > ! <COMMIT-B>:refs/heads/bar [rejected] (atomic push failed)
+ > ! (delete):refs/heads/foo [rejected] (atomic push failed)
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
+ > ! refs/heads/next:refs/heads/next [rejected] (atomic push failed)
+ > Done
EOF
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
make_user_friendly_and_stable_output <out >actual &&
cat >expect <<-EOF &&
- <COMMIT-B> refs/heads/bar
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ EOF
+ test_cmp expect actual
+ '
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --dry-run --atomic --force ($PROTOCOL)" '
+ git -C workbench push --porcelain --dry-run --atomic --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
+ > * refs/heads/next:refs/heads/next [new branch]
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
<COMMIT-B> refs/heads/main
- <COMMIT-A> refs/heads/next
EOF
test_cmp expect actual
'
}
-# Initialize the upstream repository and local workbench.
-setup_upstream_and_workbench
+setup_upstream_and_workbench upstream.git
-# Run git-push porcelain test on builtin protocol
run_git_push_porcelain_output_test file
+setup_upstream_and_workbench upstream.git
+
+run_git_push_dry_run_porcelain_output_test file
+
ROOT_PATH="$PWD"
. "$TEST_DIRECTORY"/lib-gpg.sh
. "$TEST_DIRECTORY"/lib-httpd.sh
. "$TEST_DIRECTORY"/lib-terminal.sh
start_httpd
+setup_askpass_helper
-# Re-initialize the upstream repository and local workbench.
-setup_upstream_and_workbench
-
-test_expect_success "setup for http" '
- git -C upstream.git config http.receivepack true &&
- upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
- mv upstream.git "$upstream" &&
+setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
- git -C workbench remote set-url origin $HTTPD_URL/smart/upstream.git
-'
+run_git_push_porcelain_output_test http
-setup_askpass_helper
+setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
-# Run git-push porcelain test on HTTP protocol
-run_git_push_porcelain_output_test http
+run_git_push_dry_run_porcelain_output_test http
test_done
diff --git a/t/t5620-backfill.sh b/t/t5620-backfill.sh
new file mode 100755
index 0000000000..58c81556e7
--- /dev/null
+++ b/t/t5620-backfill.sh
@@ -0,0 +1,211 @@
+#!/bin/sh
+
+test_description='git backfill on partial clones'
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+. ./test-lib.sh
+
+# We create objects in the 'src' repo.
+test_expect_success 'setup repo for object creation' '
+ echo "{print \$1}" >print_1.awk &&
+ echo "{print \$2}" >print_2.awk &&
+
+ git init src &&
+
+ mkdir -p src/a/b/c &&
+ mkdir -p src/d/e &&
+
+ for i in 1 2
+ do
+ for n in 1 2 3 4
+ do
+ echo "Version $i of file $n" > src/file.$n.txt &&
+ echo "Version $i of file a/$n" > src/a/file.$n.txt &&
+ echo "Version $i of file a/b/$n" > src/a/b/file.$n.txt &&
+ echo "Version $i of file a/b/c/$n" > src/a/b/c/file.$n.txt &&
+ echo "Version $i of file d/$n" > src/d/file.$n.txt &&
+ echo "Version $i of file d/e/$n" > src/d/e/file.$n.txt &&
+ git -C src add . &&
+ git -C src commit -m "Iteration $n" || return 1
+ done
+ done
+'
+
+# Clone 'src' into 'srv.bare' so we have a bare repo to be our origin
+# server for the partial clone.
+test_expect_success 'setup bare clone for server' '
+ git clone --bare "file://$(pwd)/src" srv.bare &&
+ git -C srv.bare config --local uploadpack.allowfilter 1 &&
+ git -C srv.bare config --local uploadpack.allowanysha1inwant 1
+'
+
+# do basic partial clone from "srv.bare"
+test_expect_success 'do partial clone 1, backfill gets all objects' '
+ git clone --no-checkout --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill1 &&
+
+ # Backfill with no options gets everything reachable from HEAD.
+ GIT_TRACE2_EVENT="$(pwd)/backfill-file-trace" git \
+ -C backfill1 backfill &&
+
+ # We should have engaged the partial clone machinery
+ test_trace2_data promisor fetch_count 48 <backfill-file-trace &&
+
+ # No more missing objects!
+ git -C backfill1 rev-list --quiet --objects --missing=print HEAD >revs2 &&
+ test_line_count = 0 revs2
+'
+
+test_expect_success 'do partial clone 2, backfill min batch size' '
+ git clone --no-checkout --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill2 &&
+
+ GIT_TRACE2_EVENT="$(pwd)/batch-trace" git \
+ -C backfill2 backfill --min-batch-size=20 &&
+
+ # Batches were used
+ test_trace2_data promisor fetch_count 20 <batch-trace >matches &&
+ test_line_count = 2 matches &&
+ test_trace2_data promisor fetch_count 8 <batch-trace &&
+
+ # No more missing objects!
+ git -C backfill2 rev-list --quiet --objects --missing=print HEAD >revs2 &&
+ test_line_count = 0 revs2
+'
+
+test_expect_success 'backfill --sparse without sparse-checkout fails' '
+ git init not-sparse &&
+ test_must_fail git -C not-sparse backfill --sparse 2>err &&
+ grep "problem loading sparse-checkout" err
+'
+
+test_expect_success 'backfill --sparse' '
+ git clone --sparse --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill3 &&
+
+ # Initial checkout includes four files at root.
+ git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 44 missing &&
+
+ # Initial sparse-checkout is just the files at root, so we get the
+ # older versions of the four files at tip.
+ GIT_TRACE2_EVENT="$(pwd)/sparse-trace1" git \
+ -C backfill3 backfill --sparse &&
+ test_trace2_data promisor fetch_count 4 <sparse-trace1 &&
+ test_trace2_data path-walk paths 5 <sparse-trace1 &&
+ git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 40 missing &&
+
+ # Expand the sparse-checkout to include 'd' recursively. This
+ # engages the algorithm to skip the trees for 'a'. Note that
+ # the "sparse-checkout set" command downloads the objects at tip
+ # to satisfy the current checkout.
+ git -C backfill3 sparse-checkout set d &&
+ GIT_TRACE2_EVENT="$(pwd)/sparse-trace2" git \
+ -C backfill3 backfill --sparse &&
+ test_trace2_data promisor fetch_count 8 <sparse-trace2 &&
+ test_trace2_data path-walk paths 15 <sparse-trace2 &&
+ git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 24 missing &&
+
+ # Disabling the --sparse option (on by default) will download everything
+ git -C backfill3 backfill --no-sparse &&
+ git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 0 missing
+'
+
+test_expect_success 'backfill --sparse without cone mode (positive)' '
+ git clone --no-checkout --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill4 &&
+
+ # No blobs yet
+ git -C backfill4 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 48 missing &&
+
+ # Define sparse-checkout by filename regardless of parent directory.
+ # This downloads 6 blobs to satisfy the checkout.
+ git -C backfill4 sparse-checkout set --no-cone "**/file.1.txt" &&
+ git -C backfill4 checkout main &&
+
+ # Track new blob count
+ git -C backfill4 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 42 missing &&
+
+ GIT_TRACE2_EVENT="$(pwd)/no-cone-trace1" git \
+ -C backfill4 backfill --sparse &&
+ test_trace2_data promisor fetch_count 6 <no-cone-trace1 &&
+
+ # This walk needed to visit all directories to search for these paths.
+ test_trace2_data path-walk paths 12 <no-cone-trace1 &&
+ git -C backfill4 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 36 missing
+'
+
+test_expect_success 'backfill --sparse without cone mode (negative)' '
+ git clone --no-checkout --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill5 &&
+
+ # No blobs yet
+ git -C backfill5 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 48 missing &&
+
+ # Define sparse-checkout by filename regardless of parent directory.
+ # This downloads 18 blobs to satisfy the checkout
+ git -C backfill5 sparse-checkout set --no-cone "**/file*" "!**/file.1.txt" &&
+ git -C backfill5 checkout main &&
+
+ # Track new blob count
+ git -C backfill5 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 30 missing &&
+
+ GIT_TRACE2_EVENT="$(pwd)/no-cone-trace2" git \
+ -C backfill5 backfill --sparse &&
+ test_trace2_data promisor fetch_count 18 <no-cone-trace2 &&
+
+ # This walk needed to visit all directories to search for these paths, plus
+ # 12 extra "file.?.txt" paths than the previous test.
+ test_trace2_data path-walk paths 24 <no-cone-trace2 &&
+ git -C backfill5 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 12 missing
+'
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+test_expect_success 'create a partial clone over HTTP' '
+ SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
+ rm -rf "$SERVER" repo &&
+ git clone --bare "file://$(pwd)/src" "$SERVER" &&
+ test_config -C "$SERVER" uploadpack.allowfilter 1 &&
+ test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
+
+ git clone --no-checkout --filter=blob:none \
+ "$HTTPD_URL/smart/server" backfill-http
+'
+
+test_expect_success 'backfilling over HTTP succeeds' '
+ GIT_TRACE2_EVENT="$(pwd)/backfill-http-trace" git \
+ -C backfill-http backfill &&
+
+ # We should have engaged the partial clone machinery
+ test_trace2_data promisor fetch_count 48 <backfill-http-trace &&
+
+ # Confirm all objects are present, none missing.
+ git -C backfill-http rev-list --objects --all >rev-list-out &&
+ awk "{print \$1;}" <rev-list-out >oids &&
+ GIT_TRACE2_EVENT="$(pwd)/walk-trace" git -C backfill-http \
+ cat-file --batch-check <oids >batch-out &&
+ ! grep missing batch-out
+'
+
+# DO NOT add non-httpd-specific tests here, because the last part of this
+# test script is only executed when httpd is available and enabled.
+
+test_done
diff --git a/t/t5621-clone-revision.sh b/t/t5621-clone-revision.sh
new file mode 100755
index 0000000000..db3b8cff55
--- /dev/null
+++ b/t/t5621-clone-revision.sh
@@ -0,0 +1,122 @@
+#!/bin/sh
+
+test_description='tests for git clone --revision'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ test_commit --no-tag "initial commit" README "Hello" &&
+ test_commit --annotate "second commit" README "Hello world" v1.0 &&
+ test_commit --no-tag "third commit" README "Hello world!" &&
+ git switch -c feature v1.0 &&
+ test_commit --no-tag "feature commit" README "Hello world!" &&
+ git switch main
+'
+
+test_expect_success 'clone with --revision being a branch' '
+ test_when_finished "rm -rf dst" &&
+ git clone --revision=refs/heads/feature . dst &&
+ git rev-parse refs/heads/feature >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --depth and --revision being a branch' '
+ test_when_finished "rm -rf dst" &&
+ git clone --no-local --depth=1 --revision=refs/heads/feature . dst &&
+ git rev-parse refs/heads/feature >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch &&
+ git -C dst rev-list HEAD >actual &&
+ test_line_count = 1 actual
+'
+
+test_expect_success 'clone with --revision being a tag' '
+ test_when_finished "rm -rf dst" &&
+ git clone --revision=refs/tags/v1.0 . dst &&
+ git rev-parse refs/tags/v1.0^{} >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --revision being HEAD' '
+ test_when_finished "rm -rf dst" &&
+ git clone --revision=HEAD . dst &&
+ git rev-parse HEAD >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --revision being a raw commit hash' '
+ test_when_finished "rm -rf dst" &&
+ oid=$(git rev-parse refs/heads/feature) &&
+ git clone --revision=$oid . dst &&
+ echo $oid >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --revision and --bare' '
+ test_when_finished "rm -rf dst" &&
+ git clone --revision=refs/heads/main --bare . dst &&
+ oid=$(git rev-parse refs/heads/main) &&
+ git -C dst cat-file -t $oid >actual &&
+ echo "commit" >expect &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --revision being a short raw commit hash' '
+ test_when_finished "rm -rf dst" &&
+ oid=$(git rev-parse --short refs/heads/feature) &&
+ test_must_fail git clone --revision=$oid . dst 2>err &&
+ test_grep "fatal: Remote revision $oid not found in upstream origin" err
+'
+
+test_expect_success 'clone with --revision being a tree hash' '
+ test_when_finished "rm -rf dst" &&
+ oid=$(git rev-parse refs/heads/feature^{tree}) &&
+ test_must_fail git clone --revision=$oid . dst 2>err &&
+ test_grep "error: object $oid is a tree, not a commit" err
+'
+
+test_expect_success 'clone with --revision being the parent of a ref fails' '
+ test_when_finished "rm -rf dst" &&
+ test_must_fail git clone --revision=refs/heads/main^ . dst
+'
+
+test_expect_success 'clone with --revision and --branch fails' '
+ test_when_finished "rm -rf dst" &&
+ test_must_fail git clone --revision=refs/heads/main --branch=main . dst
+'
+
+test_expect_success 'clone with --revision and --mirror fails' '
+ test_when_finished "rm -rf dst" &&
+ test_must_fail git clone --revision=refs/heads/main --mirror . dst
+'
+
+test_done
diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh
index 4ce62feaa2..b3807e8f35 100755
--- a/t/t6020-bundle-misc.sh
+++ b/t/t6020-bundle-misc.sh
@@ -246,7 +246,11 @@ test_expect_success 'create bundle with --since option' '
EOF
test_cmp expect actual &&
- git bundle create since.bdl \
+ # If a different name hash function is used, then one fewer
+ # delta base is found and this counts a different number
+ # of objects after performing --fix-thin.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git bundle create since.bdl \
--since "Thu Apr 7 15:27:00 2005 -0700" \
--all &&
diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh
index 88d1cf2cde..94080c65d1 100755
--- a/t/t6423-merge-rename-directories.sh
+++ b/t/t6423-merge-rename-directories.sh
@@ -5071,7 +5071,8 @@ test_expect_success '12i: Directory rename causes rename-to-self' '
test_path_is_file source/bar &&
test_path_is_file source/baz &&
- git ls-files | uniq >tracked &&
+ git ls-files >actual &&
+ uniq <actual >tracked &&
test_line_count = 3 tracked &&
git status --porcelain -uno >actual &&
@@ -5129,7 +5130,8 @@ test_expect_success '12j: Directory rename to root causes rename-to-self' '
test_path_is_file bar &&
test_path_is_file baz &&
- git ls-files | uniq >tracked &&
+ git ls-files >actual &&
+ uniq <actual >tracked &&
test_line_count = 3 tracked &&
git status --porcelain -uno >actual &&
@@ -5187,7 +5189,8 @@ test_expect_success '12k: Directory rename with sibling causes rename-to-self' '
test_path_is_file dirA/bar &&
test_path_is_file dirA/baz &&
- git ls-files | uniq >tracked &&
+ git ls-files >actual &&
+ uniq <actual >tracked &&
test_line_count = 3 tracked &&
git status --porcelain -uno >actual &&
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index 5378455968..bef472cb8d 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -338,6 +338,39 @@ test_expect_success 'gc.maxCruftSize sets appropriate repack options' '
test_subcommand $cruft_max_size_opts --max-cruft-size=3145728 <trace2.txt
'
+test_expect_success '--expire-to sets repack --expire-to' '
+ rm -rf expired &&
+ mkdir expired &&
+ expire_to="$(pwd)/expired/pack" &&
+ GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --cruft --expire-to="$expire_to" &&
+ test_subcommand $cruft_max_size_opts --expire-to="$expire_to" <trace2.txt
+'
+
+test_expect_success '--expire-to with --prune=now sets repack --expire-to' '
+ rm -rf expired &&
+ mkdir expired &&
+ expire_to="$(pwd)/expired/pack" &&
+ GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --cruft --prune=now --expire-to="$expire_to" &&
+ test_subcommand git repack -d -l --cruft --cruft-expiration=now --expire-to="$expire_to" <trace2.txt
+'
+
+
+test_expect_success '--expire-to with --no-cruft sets repack -A' '
+ rm -rf expired &&
+ mkdir expired &&
+ expire_to="$(pwd)/expired/pack" &&
+ GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --no-cruft --expire-to="$expire_to" &&
+ test_subcommand git repack -d -l -A --unpack-unreachable=2.weeks.ago <trace2.txt
+'
+
+test_expect_success '--expire-to with --no-cruft sets repack -a' '
+ rm -rf expired &&
+ mkdir expired &&
+ expire_to="$(pwd)/expired/pack" &&
+ GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --no-cruft --prune=now --expire-to="$expire_to" &&
+ test_subcommand git repack -d -l -a <trace2.txt
+'
+
run_and_wait_for_gc () {
# We read stdout from gc for the side effect of waiting until the
# background gc process exits, closing its fd 9. Furthermore, the
diff --git a/t/t6601-path-walk.sh b/t/t6601-path-walk.sh
index 5f04acb8a2..c89b0f1e19 100755
--- a/t/t6601-path-walk.sh
+++ b/t/t6601-path-walk.sh
@@ -176,6 +176,38 @@ test_expect_success 'branches and indexed objects mix well' '
test_cmp_sorted expect out
'
+test_expect_success 'base & topic, sparse' '
+ cat >patterns <<-EOF &&
+ /*
+ !/*/
+ /left/
+ EOF
+
+ test-tool path-walk --stdin-pl -- base topic <patterns >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base)
+ 0:commit::$(git rev-parse base~1)
+ 0:commit::$(git rev-parse base~2)
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base^{tree})
+ 1:tree::$(git rev-parse base~1^{tree})
+ 1:tree::$(git rev-parse base~2^{tree})
+ 2:blob:a:$(git rev-parse base~2:a)
+ 3:tree:left/:$(git rev-parse base:left)
+ 3:tree:left/:$(git rev-parse base~2:left)
+ 4:blob:left/b:$(git rev-parse base~2:left/b)
+ 4:blob:left/b:$(git rev-parse base:left/b)
+ blobs:3
+ commits:4
+ tags:0
+ trees:6
+ EOF
+
+ test_cmp_sorted expect out
+'
+
test_expect_success 'topic only' '
test-tool path-walk -- topic >out &&
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 297c6c3b5c..c562bad042 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1093,7 +1093,9 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
) &&
git clone super4 super5 &&
(cd super5 &&
- git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
+ # This test var can mess with the stderr output checked in this test.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
test_must_be_empty out &&
test_must_be_empty err
) &&
diff --git a/t/t7422-submodule-output.sh b/t/t7422-submodule-output.sh
index f21e920367..023a5cbdc4 100755
--- a/t/t7422-submodule-output.sh
+++ b/t/t7422-submodule-output.sh
@@ -167,10 +167,45 @@ do
done
test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE' '
- { git submodule status --recursive 2>err; echo $?>status; } |
- grep -q X/S &&
- test_must_be_empty err &&
- test_match_signal 13 "$(cat status)"
+ # The test setup is somewhat involved because triggering a SIGPIPE is
+ # racy with buffered pipes. To avoid the raciness we thus need to make
+ # sure that the subprocess in question fills the buffers completely,
+ # which requires a couple thousand submodules in total.
+ test_when_finished "rm -rf submodule repo" &&
+ git init submodule &&
+ (
+ cd submodule &&
+ test_commit initial &&
+
+ COMMIT=$(git rev-parse HEAD) &&
+ for i in $(test_seq 2000)
+ do
+ printf "[submodule \"sm-$i\"]\npath = recursive-submodule-path-$i\n" "$i" ||
+ return 1
+ done >gitmodules &&
+ BLOB=$(git hash-object -w --stdin <gitmodules) &&
+
+ printf "100644 blob $BLOB\t.gitmodules\n" >tree &&
+ for i in $(test_seq 2000)
+ do
+ printf "160000 commit $COMMIT\trecursive-submodule-path-%d\n" "$i" ||
+ return 1
+ done >>tree &&
+ TREE=$(git mktree <tree) &&
+
+ COMMIT=$(git commit-tree "$TREE") &&
+ git reset --hard "$COMMIT"
+ ) &&
+
+ git init repo &&
+ (
+ cd repo &&
+ GIT_ALLOW_PROTOCOL=file git submodule add "$(pwd)"/../submodule &&
+ { git submodule status --recursive 2>err; echo $?>status; } |
+ grep -q recursive-submodule-path-1 &&
+ test_must_be_empty err &&
+ test_match_signal 13 "$(cat status)"
+ )
'
test_done
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index be1188e736..611755cc13 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -308,7 +308,10 @@ test_expect_success 'no bitmaps created if .keep files present' '
keep=${pack%.pack}.keep &&
test_when_finished "rm -f \"\$keep\"" &&
>"$keep" &&
- git -C bare.git repack -ad 2>stderr &&
+
+ # Disable --name-hash-version test due to stderr comparison.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git -C bare.git repack -ad 2>stderr &&
test_must_be_empty stderr &&
find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
test_must_be_empty actual
@@ -319,7 +322,10 @@ test_expect_success 'auto-bitmaps do not complain if unavailable' '
blob=$(test-tool genrandom big $((1024*1024)) |
git -C bare.git hash-object -w --stdin) &&
git -C bare.git update-ref refs/tags/big $blob &&
- git -C bare.git repack -ad 2>stderr &&
+
+ # Disable --name-hash-version test due to stderr comparison.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git -C bare.git repack -ad 2>stderr &&
test_must_be_empty stderr &&
find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
test_must_be_empty actual
@@ -776,6 +782,12 @@ test_expect_success 'repack -ad cleans up old .tmp-* packs' '
test_must_be_empty tmpfiles
'
+test_expect_success '--name-hash-version option passes through to pack-objects' '
+ GIT_TRACE2_EVENT="$(pwd)/hash-trace.txt" \
+ git repack -a --name-hash-version=2 &&
+ test_subcommand_flex git pack-objects --name-hash-version=2 <hash-trace.txt
+'
+
test_expect_success 'setup for update-server-info' '
git init update-server-info &&
test_commit -C update-server-info message
diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh
index 5715f4d69a..5559d4ccb4 100755
--- a/t/t7701-repack-unpack-unreachable.sh
+++ b/t/t7701-repack-unpack-unreachable.sh
@@ -195,4 +195,20 @@ test_expect_success 'repack -k packs unreachable loose objects' '
git cat-file -p $sha1
'
+test_expect_success 'repack -k packs unreachable loose objects without existing packfiles' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+
+ oid=$(echo would-be-deleted-loose | git hash-object -w --stdin) &&
+ objpath=.git/objects/$(echo $sha1 | sed "s,..,&/,") &&
+ test_path_is_file $objpath &&
+
+ git repack -ad --keep-unreachable &&
+ test_path_is_missing $objpath &&
+ git cat-file -p $oid
+ )
+'
+
test_done
diff --git a/t/t9003-help-autocorrect.sh b/t/t9003-help-autocorrect.sh
index 85a5074b5e..8da318d2b5 100755
--- a/t/t9003-help-autocorrect.sh
+++ b/t/t9003-help-autocorrect.sh
@@ -28,15 +28,18 @@ test_expect_success 'setup' '
test_cmp expect actual
'
-test_expect_success 'autocorrect showing candidates' '
- git config help.autocorrect 0 &&
+for show in false no off 0 show
+do
+ test_expect_success 'autocorrect showing candidates' '
+ git config help.autocorrect $show &&
- test_must_fail git lfg 2>actual &&
- grep "^ lgf" actual &&
+ test_must_fail git lfg 2>actual &&
+ grep "^ lgf" actual &&
- test_must_fail git distimdist 2>actual &&
- grep "^ distimdistim" actual
-'
+ test_must_fail git distimdist 2>actual &&
+ grep "^ distimdistim" actual
+ '
+done
for immediate in -1 immediate
do
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 14d511f509..b93736e0d5 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1896,6 +1896,32 @@ test_subcommand () {
fi
}
+# Check that the given subcommand was run with the given set of
+# arguments in order (but with possible extra arguments).
+#
+# test_subcommand_flex [!] <command> <args>... < <trace>
+#
+# If the first parameter passed is !, this instead checks that
+# the given command was not called.
+#
+test_subcommand_flex () {
+ local negate=
+ if test "$1" = "!"
+ then
+ negate=t
+ shift
+ fi
+
+ local expr="$(printf '"%s".*' "$@")"
+
+ if test -n "$negate"
+ then
+ ! grep "\[$expr\]"
+ else
+ grep "\[$expr\]"
+ fi
+}
+
# Check that the given command was invoked as part of the
# trace2-format trace on stdin.
#
diff --git a/t/unit-tests/t-example-decorate.c b/t/unit-tests/t-example-decorate.c
deleted file mode 100644
index bfc776e223..0000000000
--- a/t/unit-tests/t-example-decorate.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
-#include "test-lib.h"
-#include "object.h"
-#include "decorate.h"
-#include "repository.h"
-
-struct test_vars {
- struct object *one, *two, *three;
- struct decoration n;
- int decoration_a, decoration_b;
-};
-
-static void t_add(struct test_vars *vars)
-{
- void *ret = add_decoration(&vars->n, vars->one, &vars->decoration_a);
-
- check(ret == NULL);
- ret = add_decoration(&vars->n, vars->two, NULL);
- check(ret == NULL);
-}
-
-static void t_readd(struct test_vars *vars)
-{
- void *ret = add_decoration(&vars->n, vars->one, NULL);
-
- check(ret == &vars->decoration_a);
- ret = add_decoration(&vars->n, vars->two, &vars->decoration_b);
- check(ret == NULL);
-}
-
-static void t_lookup(struct test_vars *vars)
-{
- void *ret = lookup_decoration(&vars->n, vars->one);
-
- check(ret == NULL);
- ret = lookup_decoration(&vars->n, vars->two);
- check(ret == &vars->decoration_b);
- ret = lookup_decoration(&vars->n, vars->three);
- check(ret == NULL);
-}
-
-static void t_loop(struct test_vars *vars)
-{
- int objects_noticed = 0;
-
- for (size_t i = 0; i < vars->n.size; i++) {
- if (vars->n.entries[i].base)
- objects_noticed++;
- }
- check_int(objects_noticed, ==, 2);
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- struct object_id one_oid = { { 1 } }, two_oid = { { 2 } }, three_oid = { { 3 } };
- struct test_vars vars = { 0 };
-
- vars.one = lookup_unknown_object(the_repository, &one_oid);
- vars.two = lookup_unknown_object(the_repository, &two_oid);
- vars.three = lookup_unknown_object(the_repository, &three_oid);
-
- TEST(t_add(&vars),
- "Add 2 objects, one with a non-NULL decoration and one with a NULL decoration.");
- TEST(t_readd(&vars),
- "When re-adding an already existing object, the old decoration is returned.");
- TEST(t_lookup(&vars),
- "Lookup returns the added declarations, or NULL if the object was never added.");
- TEST(t_loop(&vars), "The user can also loop through all entries.");
-
- clear_decoration(&vars.n, NULL);
-
- return test_done();
-}
diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c
index aeec195b2b..c3f0059c34 100644
--- a/t/unit-tests/t-reftable-stack.c
+++ b/t/unit-tests/t-reftable-stack.c
@@ -103,7 +103,8 @@ static void t_read_file(void)
static int write_test_ref(struct reftable_writer *wr, void *arg)
{
struct reftable_ref_record *ref = arg;
- reftable_writer_set_limits(wr, ref->update_index, ref->update_index);
+ check(!reftable_writer_set_limits(wr, ref->update_index,
+ ref->update_index));
return reftable_writer_add_ref(wr, ref);
}
@@ -143,7 +144,8 @@ static int write_test_log(struct reftable_writer *wr, void *arg)
{
struct write_log_arg *wla = arg;
- reftable_writer_set_limits(wr, wla->update_index, wla->update_index);
+ check(!reftable_writer_set_limits(wr, wla->update_index,
+ wla->update_index));
return reftable_writer_add_log(wr, wla->log);
}
@@ -961,7 +963,7 @@ static void t_reflog_expire(void)
static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
{
- reftable_writer_set_limits(wr, 1, 1);
+ check(!reftable_writer_set_limits(wr, 1, 1));
return 0;
}
@@ -1369,11 +1371,57 @@ static void t_reftable_stack_reload_with_missing_table(void)
clear_dir(dir);
}
+static int write_limits_after_ref(struct reftable_writer *wr, void *arg)
+{
+ struct reftable_ref_record *ref = arg;
+ check(!reftable_writer_set_limits(wr, ref->update_index, ref->update_index));
+ check(!reftable_writer_add_ref(wr, ref));
+ return reftable_writer_set_limits(wr, ref->update_index, ref->update_index);
+}
+
+static void t_reftable_invalid_limit_updates(void)
+{
+ struct reftable_ref_record ref = {
+ .refname = (char *) "HEAD",
+ .update_index = 1,
+ .value_type = REFTABLE_REF_SYMREF,
+ .value.symref = (char *) "master",
+ };
+ struct reftable_write_options opts = {
+ .default_permissions = 0660,
+ };
+ struct reftable_addition *add = NULL;
+ char *dir = get_tmp_dir(__LINE__);
+ struct reftable_stack *st = NULL;
+ int err;
+
+ err = reftable_new_stack(&st, dir, &opts);
+ check(!err);
+
+ reftable_addition_destroy(add);
+
+ err = reftable_stack_new_addition(&add, st, 0);
+ check(!err);
+
+ /*
+ * write_limits_after_ref also updates the update indexes after adding
+ * the record. This should cause an err to be returned, since the limits
+ * must be set at the start.
+ */
+ err = reftable_addition_add(add, write_limits_after_ref, &ref);
+ check_int(err, ==, REFTABLE_API_ERROR);
+
+ reftable_addition_destroy(add);
+ reftable_stack_destroy(st);
+ clear_dir(dir);
+}
+
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
{
TEST(t_empty_add(), "empty addition to stack");
TEST(t_read_file(), "read_lines works");
TEST(t_reflog_expire(), "expire reflog entries");
+ TEST(t_reftable_invalid_limit_updates(), "prevent limit updates after adding records");
TEST(t_reftable_stack_add(), "add multiple refs and logs to stack");
TEST(t_reftable_stack_add_one(), "add a single ref record to stack");
TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction");
diff --git a/t/unit-tests/t-strbuf.c b/t/unit-tests/t-strbuf.c
deleted file mode 100644
index 3f4044d697..0000000000
--- a/t/unit-tests/t-strbuf.c
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "test-lib.h"
-#include "strbuf.h"
-
-/* wrapper that supplies tests with an empty, initialized strbuf */
-static void setup(void (*f)(struct strbuf*, const void*),
- const void *data)
-{
- struct strbuf buf = STRBUF_INIT;
-
- f(&buf, data);
- strbuf_release(&buf);
- check_uint(buf.len, ==, 0);
- check_uint(buf.alloc, ==, 0);
-}
-
-/* wrapper that supplies tests with a populated, initialized strbuf */
-static void setup_populated(void (*f)(struct strbuf*, const void*),
- const char *init_str, const void *data)
-{
- struct strbuf buf = STRBUF_INIT;
-
- strbuf_addstr(&buf, init_str);
- check_uint(buf.len, ==, strlen(init_str));
- f(&buf, data);
- strbuf_release(&buf);
- check_uint(buf.len, ==, 0);
- check_uint(buf.alloc, ==, 0);
-}
-
-static int assert_sane_strbuf(struct strbuf *buf)
-{
- /* Initialized strbufs should always have a non-NULL buffer */
- if (!check(!!buf->buf))
- return 0;
- /* Buffers should always be NUL-terminated */
- if (!check_char(buf->buf[buf->len], ==, '\0'))
- return 0;
- /*
- * Freshly-initialized strbufs may not have a dynamically allocated
- * buffer
- */
- if (buf->len == 0 && buf->alloc == 0)
- return 1;
- /* alloc must be at least one byte larger than len */
- return check_uint(buf->len, <, buf->alloc);
-}
-
-static void t_static_init(void)
-{
- struct strbuf buf = STRBUF_INIT;
-
- check_uint(buf.len, ==, 0);
- check_uint(buf.alloc, ==, 0);
- check_char(buf.buf[0], ==, '\0');
-}
-
-static void t_dynamic_init(void)
-{
- struct strbuf buf;
-
- strbuf_init(&buf, 1024);
- check(assert_sane_strbuf(&buf));
- check_uint(buf.len, ==, 0);
- check_uint(buf.alloc, >=, 1024);
- check_char(buf.buf[0], ==, '\0');
- strbuf_release(&buf);
-}
-
-static void t_addch(struct strbuf *buf, const void *data)
-{
- const char *p_ch = data;
- const char ch = *p_ch;
- size_t orig_alloc = buf->alloc;
- size_t orig_len = buf->len;
-
- if (!check(assert_sane_strbuf(buf)))
- return;
- strbuf_addch(buf, ch);
- if (!check(assert_sane_strbuf(buf)))
- return;
- if (!(check_uint(buf->len, ==, orig_len + 1) &&
- check_uint(buf->alloc, >=, orig_alloc)))
- return; /* avoid de-referencing buf->buf */
- check_char(buf->buf[buf->len - 1], ==, ch);
- check_char(buf->buf[buf->len], ==, '\0');
-}
-
-static void t_addstr(struct strbuf *buf, const void *data)
-{
- const char *text = data;
- size_t len = strlen(text);
- size_t orig_alloc = buf->alloc;
- size_t orig_len = buf->len;
-
- if (!check(assert_sane_strbuf(buf)))
- return;
- strbuf_addstr(buf, text);
- if (!check(assert_sane_strbuf(buf)))
- return;
- if (!(check_uint(buf->len, ==, orig_len + len) &&
- check_uint(buf->alloc, >=, orig_alloc) &&
- check_uint(buf->alloc, >, orig_len + len) &&
- check_char(buf->buf[orig_len + len], ==, '\0')))
- return;
- check_str(buf->buf + orig_len, text);
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- if (!TEST(t_static_init(), "static initialization works"))
- test_skip_all("STRBUF_INIT is broken");
- TEST(t_dynamic_init(), "dynamic initialization works");
- TEST(setup(t_addch, "a"), "strbuf_addch adds char");
- TEST(setup(t_addch, ""), "strbuf_addch adds NUL char");
- TEST(setup_populated(t_addch, "initial value", "a"),
- "strbuf_addch appends to initial value");
- TEST(setup(t_addstr, "hello there"), "strbuf_addstr adds string");
- TEST(setup_populated(t_addstr, "initial value", "hello there"),
- "strbuf_addstr appends string to initial value");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-strcmp-offset.c b/t/unit-tests/t-strcmp-offset.c
deleted file mode 100644
index 6880f21161..0000000000
--- a/t/unit-tests/t-strcmp-offset.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "test-lib.h"
-#include "read-cache-ll.h"
-
-static void check_strcmp_offset(const char *string1, const char *string2,
- int expect_result, uintmax_t expect_offset)
-{
- size_t offset;
- int result = strcmp_offset(string1, string2, &offset);
-
- /*
- * Because different CRTs behave differently, only rely on signs of the
- * result values.
- */
- result = (result < 0 ? -1 :
- result > 0 ? 1 :
- 0);
-
- check_int(result, ==, expect_result);
- check_uint((uintmax_t)offset, ==, expect_offset);
-}
-
-#define TEST_STRCMP_OFFSET(string1, string2, expect_result, expect_offset) \
- TEST(check_strcmp_offset(string1, string2, expect_result, \
- expect_offset), \
- "strcmp_offset(%s, %s) works", #string1, #string2)
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- TEST_STRCMP_OFFSET("abc", "abc", 0, 3);
- TEST_STRCMP_OFFSET("abc", "def", -1, 0);
- TEST_STRCMP_OFFSET("abc", "abz", -1, 2);
- TEST_STRCMP_OFFSET("abc", "abcdef", -1, 3);
-
- return test_done();
-}
diff --git a/t/unit-tests/u-example-decorate.c b/t/unit-tests/u-example-decorate.c
new file mode 100644
index 0000000000..9b1d1ce753
--- /dev/null
+++ b/t/unit-tests/u-example-decorate.c
@@ -0,0 +1,64 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
+#include "unit-test.h"
+#include "object.h"
+#include "decorate.h"
+#include "repository.h"
+
+struct test_vars {
+ struct object *one, *two, *three;
+ struct decoration n;
+ int decoration_a, decoration_b;
+};
+
+static struct test_vars vars;
+
+void test_example_decorate__initialize(void)
+{
+ struct object_id one_oid = { { 1 } }, two_oid = { { 2 } }, three_oid = { { 3 } };
+
+ vars.one = lookup_unknown_object(the_repository, &one_oid);
+ vars.two = lookup_unknown_object(the_repository, &two_oid);
+ vars.three = lookup_unknown_object(the_repository, &three_oid);
+}
+
+void test_example_decorate__cleanup(void)
+{
+ clear_decoration(&vars.n, NULL);
+}
+
+void test_example_decorate__add(void)
+{
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, NULL), NULL);
+}
+
+void test_example_decorate__readd(void)
+{
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, NULL), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, NULL), &vars.decoration_a);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
+}
+
+void test_example_decorate__lookup(void)
+{
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, NULL), NULL);
+ cl_assert_equal_p(lookup_decoration(&vars.n, vars.two), &vars.decoration_b);
+ cl_assert_equal_p(lookup_decoration(&vars.n, vars.one), NULL);
+}
+
+void test_example_decorate__loop(void)
+{
+ int objects_noticed = 0;
+
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
+
+ for (size_t i = 0; i < vars.n.size; i++)
+ if (vars.n.entries[i].base)
+ objects_noticed++;
+
+ cl_assert_equal_i(objects_noticed, 2);
+}
diff --git a/t/unit-tests/u-hash.c b/t/unit-tests/u-hash.c
index a0320efe4b..bd4ac6a6e1 100644
--- a/t/unit-tests/u-hash.c
+++ b/t/unit-tests/u-hash.c
@@ -8,13 +8,13 @@ static void check_hash_data(const void *data, size_t data_length,
cl_assert(data != NULL);
for (size_t i = 1; i < ARRAY_SIZE(hash_algos); i++) {
- git_hash_ctx ctx;
+ struct git_hash_ctx ctx;
unsigned char hash[GIT_MAX_HEXSZ];
const struct git_hash_algo *algop = &hash_algos[i];
algop->init_fn(&ctx);
- algop->update_fn(&ctx, data, data_length);
- algop->final_fn(hash, &ctx);
+ git_hash_update(&ctx, data, data_length);
+ git_hash_final(hash, &ctx);
cl_assert_equal_s(hash_to_hex_algop(hash,algop), expected_hashes[i - 1]);
}
diff --git a/t/unit-tests/t-hashmap.c b/t/unit-tests/u-hashmap.c
index 83b79dff39..eb80aa1348 100644
--- a/t/unit-tests/t-hashmap.c
+++ b/t/unit-tests/u-hashmap.c
@@ -1,4 +1,4 @@
-#include "test-lib.h"
+#include "unit-test.h"
#include "hashmap.h"
#include "strbuf.h"
@@ -83,23 +83,23 @@ static void t_replace(struct hashmap *map, unsigned int ignore_case)
struct test_entry *entry;
entry = alloc_test_entry("key1", "value1", ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
entry = alloc_test_entry(ignore_case ? "Key1" : "key1", "value2",
ignore_case);
entry = hashmap_put_entry(map, entry, ent);
- if (check(entry != NULL))
- check_str(get_value(entry), "value1");
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(get_value(entry), "value1");
free(entry);
entry = alloc_test_entry("fooBarFrotz", "value3", ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
entry = alloc_test_entry(ignore_case ? "FOObarFrotz" : "fooBarFrotz",
"value4", ignore_case);
entry = hashmap_put_entry(map, entry, ent);
- if (check(entry != NULL))
- check_str(get_value(entry), "value3");
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(get_value(entry), "value3");
free(entry);
}
@@ -122,20 +122,18 @@ static void t_get(struct hashmap *map, unsigned int ignore_case)
for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
entry = alloc_test_entry(key_val[i][0], key_val[i][1],
ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
}
for (size_t i = 0; i < ARRAY_SIZE(query); i++) {
entry = get_test_entry(map, query[i][0], ignore_case);
- if (check(entry != NULL))
- check_str(get_value(entry), query[i][1]);
- else
- test_msg("query key: %s", query[i][0]);
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(get_value(entry), query[i][1]);
}
- check_pointer_eq(get_test_entry(map, "notInMap", ignore_case), NULL);
- check_int(map->tablesize, ==, 64);
- check_int(hashmap_get_size(map), ==, ARRAY_SIZE(key_val));
+ cl_assert_equal_p(get_test_entry(map, "notInMap", ignore_case), NULL);
+ cl_assert_equal_i(map->tablesize, 64);
+ cl_assert_equal_i(hashmap_get_size(map), ARRAY_SIZE(key_val));
}
static void t_add(struct hashmap *map, unsigned int ignore_case)
@@ -165,39 +163,19 @@ static void t_add(struct hashmap *map, unsigned int ignore_case)
hashmap_for_each_entry_from(map, entry, ent)
{
- int ret;
- if (!check_int((ret = key_val_contains(
- key_val, seen,
- ARRAY_SIZE(key_val), entry)),
- ==, 0)) {
- switch (ret) {
- case 1:
- test_msg("found entry was not given in the input\n"
- " key: %s\n value: %s",
- entry->key, get_value(entry));
- break;
- case 2:
- test_msg("duplicate entry detected\n"
- " key: %s\n value: %s",
- entry->key, get_value(entry));
- break;
- }
- } else {
- count++;
- }
+ int ret = key_val_contains(key_val, seen,
+ ARRAY_SIZE(key_val), entry);
+ cl_assert_equal_i(ret, 0);
+ count++;
}
- check_int(count, ==, 2);
+ cl_assert_equal_i(count, 2);
}
- for (size_t i = 0; i < ARRAY_SIZE(seen); i++) {
- if (!check_int(seen[i], ==, 1))
- test_msg("following key-val pair was not iterated over:\n"
- " key: %s\n value: %s",
- key_val[i][0], key_val[i][1]);
- }
+ for (size_t i = 0; i < ARRAY_SIZE(seen); i++)
+ cl_assert_equal_i(seen[i], 1);
- check_int(hashmap_get_size(map), ==, ARRAY_SIZE(key_val));
- check_pointer_eq(get_test_entry(map, "notInMap", ignore_case), NULL);
+ cl_assert_equal_i(hashmap_get_size(map), ARRAY_SIZE(key_val));
+ cl_assert_equal_p(get_test_entry(map, "notInMap", ignore_case), NULL);
}
static void t_remove(struct hashmap *map, unsigned int ignore_case)
@@ -211,24 +189,25 @@ static void t_remove(struct hashmap *map, unsigned int ignore_case)
for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
entry = alloc_test_entry(key_val[i][0], key_val[i][1], ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
}
for (size_t i = 0; i < ARRAY_SIZE(remove); i++) {
entry = alloc_test_entry(remove[i][0], "", ignore_case);
removed = hashmap_remove_entry(map, entry, ent, remove[i][0]);
- if (check(removed != NULL))
- check_str(get_value(removed), remove[i][1]);
+ cl_assert(removed != NULL);
+ cl_assert_equal_s(get_value(removed), remove[i][1]);
free(entry);
free(removed);
}
entry = alloc_test_entry("notInMap", "", ignore_case);
- check_pointer_eq(hashmap_remove_entry(map, entry, ent, "notInMap"), NULL);
+ cl_assert_equal_p(hashmap_remove_entry(map, entry, ent, "notInMap"), NULL);
free(entry);
- check_int(map->tablesize, ==, 64);
- check_int(hashmap_get_size(map), ==, ARRAY_SIZE(key_val) - ARRAY_SIZE(remove));
+ cl_assert_equal_i(map->tablesize, 64);
+ cl_assert_equal_i(hashmap_get_size(map),
+ ARRAY_SIZE(key_val) - ARRAY_SIZE(remove));
}
static void t_iterate(struct hashmap *map, unsigned int ignore_case)
@@ -242,38 +221,21 @@ static void t_iterate(struct hashmap *map, unsigned int ignore_case)
for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
entry = alloc_test_entry(key_val[i][0], key_val[i][1], ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
}
hashmap_for_each_entry(map, &iter, entry, ent /* member name */)
{
- int ret;
- if (!check_int((ret = key_val_contains(key_val, seen,
- ARRAY_SIZE(key_val),
- entry)), ==, 0)) {
- switch (ret) {
- case 1:
- test_msg("found entry was not given in the input\n"
- " key: %s\n value: %s",
- entry->key, get_value(entry));
- break;
- case 2:
- test_msg("duplicate entry detected\n"
- " key: %s\n value: %s",
- entry->key, get_value(entry));
- break;
- }
- }
+ int ret = key_val_contains(key_val, seen,
+ ARRAY_SIZE(key_val),
+ entry);
+ cl_assert(ret == 0);
}
- for (size_t i = 0; i < ARRAY_SIZE(seen); i++) {
- if (!check_int(seen[i], ==, 1))
- test_msg("following key-val pair was not iterated over:\n"
- " key: %s\n value: %s",
- key_val[i][0], key_val[i][1]);
- }
+ for (size_t i = 0; i < ARRAY_SIZE(seen); i++)
+ cl_assert_equal_i(seen[i], 1);
- check_int(hashmap_get_size(map), ==, ARRAY_SIZE(key_val));
+ cl_assert_equal_i(hashmap_get_size(map), ARRAY_SIZE(key_val));
}
static void t_alloc(struct hashmap *map, unsigned int ignore_case)
@@ -284,17 +246,17 @@ static void t_alloc(struct hashmap *map, unsigned int ignore_case)
char *key = xstrfmt("key%d", i);
char *value = xstrfmt("value%d", i);
entry = alloc_test_entry(key, value, ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
free(key);
free(value);
}
- check_int(map->tablesize, ==, 64);
- check_int(hashmap_get_size(map), ==, 51);
+ cl_assert_equal_i(map->tablesize, 64);
+ cl_assert_equal_i(hashmap_get_size(map), 51);
entry = alloc_test_entry("key52", "value52", ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
- check_int(map->tablesize, ==, 256);
- check_int(hashmap_get_size(map), ==, 52);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_i(map->tablesize, 256);
+ cl_assert_equal_i(hashmap_get_size(map), 52);
for (int i = 1; i <= 12; i++) {
char *key = xstrfmt("key%d", i);
@@ -302,27 +264,27 @@ static void t_alloc(struct hashmap *map, unsigned int ignore_case)
entry = alloc_test_entry(key, "", ignore_case);
removed = hashmap_remove_entry(map, entry, ent, key);
- if (check(removed != NULL))
- check_str(value, get_value(removed));
+ cl_assert(removed != NULL);
+ cl_assert_equal_s(value, get_value(removed));
free(key);
free(value);
free(entry);
free(removed);
}
- check_int(map->tablesize, ==, 256);
- check_int(hashmap_get_size(map), ==, 40);
+ cl_assert_equal_i(map->tablesize, 256);
+ cl_assert_equal_i(hashmap_get_size(map), 40);
entry = alloc_test_entry("key40", "", ignore_case);
removed = hashmap_remove_entry(map, entry, ent, "key40");
- if (check(removed != NULL))
- check_str("value40", get_value(removed));
- check_int(map->tablesize, ==, 64);
- check_int(hashmap_get_size(map), ==, 39);
+ cl_assert(removed != NULL);
+ cl_assert_equal_s("value40", get_value(removed));
+ cl_assert_equal_i(map->tablesize, 64);
+ cl_assert_equal_i(hashmap_get_size(map), 39);
free(entry);
free(removed);
}
-static void t_intern(void)
+void test_hashmap__intern(void)
{
const char *values[] = { "value1", "Value1", "value2", "value2" };
@@ -330,32 +292,68 @@ static void t_intern(void)
const char *i1 = strintern(values[i]);
const char *i2 = strintern(values[i]);
- if (!check(!strcmp(i1, values[i])))
- test_msg("strintern(%s) returns %s\n", values[i], i1);
- else if (!check(i1 != values[i]))
- test_msg("strintern(%s) returns input pointer\n",
- values[i]);
- else if (!check_pointer_eq(i1, i2))
- test_msg("address('%s') != address('%s'), so strintern('%s') != strintern('%s')",
- i1, i2, values[i], values[i]);
- else
- check_str(i1, values[i]);
+ cl_assert_equal_s(i1, values[i]);
+ cl_assert(i1 != values[i]);
+ cl_assert_equal_p(i1, i2);
}
}
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
+void test_hashmap__replace_case_sensitive(void)
+{
+ setup(t_replace, 0);
+}
+
+void test_hashmap__replace_case_insensitive(void)
+{
+ setup(t_replace, 1);
+}
+
+void test_hashmap__get_case_sensitive(void)
+{
+ setup(t_get, 0);
+}
+
+void test_hashmap__get_case_insensitive(void)
+{
+ setup(t_get, 1);
+}
+
+void test_hashmap__add_case_sensitive(void)
+{
+ setup(t_add, 0);
+}
+
+void test_hashmap__add_case_insensitive(void)
+{
+ setup(t_add, 1);
+}
+
+void test_hashmap__remove_case_sensitive(void)
+{
+ setup(t_remove, 0);
+}
+
+void test_hashmap__remove_case_insensitive(void)
+{
+ setup(t_remove, 1);
+}
+
+void test_hashmap__iterate_case_sensitive(void)
+{
+ setup(t_iterate, 0);
+}
+
+void test_hashmap__iterate_case_insensitive(void)
+{
+ setup(t_iterate, 1);
+}
+
+void test_hashmap__alloc_case_sensitive(void)
+{
+ setup(t_alloc, 0);
+}
+
+void test_hashmap__alloc_case_insensitive(void)
{
- TEST(setup(t_replace, 0), "replace works");
- TEST(setup(t_replace, 1), "replace (case insensitive) works");
- TEST(setup(t_get, 0), "get works");
- TEST(setup(t_get, 1), "get (case insensitive) works");
- TEST(setup(t_add, 0), "add works");
- TEST(setup(t_add, 1), "add (case insensitive) works");
- TEST(setup(t_remove, 0), "remove works");
- TEST(setup(t_remove, 1), "remove (case insensitive) works");
- TEST(setup(t_iterate, 0), "iterate works");
- TEST(setup(t_iterate, 1), "iterate (case insensitive) works");
- TEST(setup(t_alloc, 0), "grow / shrink works");
- TEST(t_intern(), "string interning works");
- return test_done();
+ setup(t_alloc, 1);
}
diff --git a/t/unit-tests/u-strbuf.c b/t/unit-tests/u-strbuf.c
new file mode 100644
index 0000000000..caa5d78aa3
--- /dev/null
+++ b/t/unit-tests/u-strbuf.c
@@ -0,0 +1,119 @@
+#include "unit-test.h"
+#include "strbuf.h"
+
+/* wrapper that supplies tests with an empty, initialized strbuf */
+static void setup(void (*f)(struct strbuf*, const void*),
+ const void *data)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ f(&buf, data);
+ strbuf_release(&buf);
+ cl_assert_equal_i(buf.len, 0);
+ cl_assert_equal_i(buf.alloc, 0);
+}
+
+/* wrapper that supplies tests with a populated, initialized strbuf */
+static void setup_populated(void (*f)(struct strbuf*, const void*),
+ const char *init_str, const void *data)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ strbuf_addstr(&buf, init_str);
+ cl_assert_equal_i(buf.len, strlen(init_str));
+ f(&buf, data);
+ strbuf_release(&buf);
+ cl_assert_equal_i(buf.len, 0);
+ cl_assert_equal_i(buf.alloc, 0);
+}
+
+static void assert_sane_strbuf(struct strbuf *buf)
+{
+ /* Initialized strbufs should always have a non-NULL buffer */
+ cl_assert(buf->buf != NULL);
+ /* Buffers should always be NUL-terminated */
+ cl_assert(buf->buf[buf->len] == '\0');
+ /*
+ * In case the buffer contains anything, `alloc` must alloc must
+ * be at least one byte larger than `len`.
+ */
+ if (buf->len)
+ cl_assert(buf->len < buf->alloc);
+}
+
+void test_strbuf__static_init(void)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ cl_assert_equal_i(buf.len, 0);
+ cl_assert_equal_i(buf.alloc, 0);
+ cl_assert(buf.buf[0] == '\0');
+}
+
+void test_strbuf__dynamic_init(void)
+{
+ struct strbuf buf;
+
+ strbuf_init(&buf, 1024);
+ assert_sane_strbuf(&buf);
+ cl_assert_equal_i(buf.len, 0);
+ cl_assert(buf.alloc >= 1024);
+ cl_assert(buf.buf[0] == '\0');
+ strbuf_release(&buf);
+}
+
+static void t_addch(struct strbuf *buf, const void *data)
+{
+ const char *p_ch = data;
+ const char ch = *p_ch;
+ size_t orig_alloc = buf->alloc;
+ size_t orig_len = buf->len;
+
+ assert_sane_strbuf(buf);
+ strbuf_addch(buf, ch);
+ assert_sane_strbuf(buf);
+ cl_assert_equal_i(buf->len, orig_len + 1);
+ cl_assert(buf->alloc >= orig_alloc);
+ cl_assert(buf->buf[buf->len] == '\0');
+}
+
+static void t_addstr(struct strbuf *buf, const void *data)
+{
+ const char *text = data;
+ size_t len = strlen(text);
+ size_t orig_alloc = buf->alloc;
+ size_t orig_len = buf->len;
+
+ assert_sane_strbuf(buf);
+ strbuf_addstr(buf, text);
+ assert_sane_strbuf(buf);
+ cl_assert_equal_i(buf->len, orig_len + len);
+ cl_assert(buf->alloc >= orig_alloc);
+ cl_assert(buf->buf[buf->len] == '\0');
+ cl_assert_equal_s(buf->buf + orig_len, text);
+}
+
+void test_strbuf__add_single_char(void)
+{
+ setup(t_addch, "a");
+}
+
+void test_strbuf__add_empty_char(void)
+{
+ setup(t_addch, "");
+}
+
+void test_strbuf__add_append_char(void)
+{
+ setup_populated(t_addch, "initial value", "a");
+}
+
+void test_strbuf__add_single_str(void)
+{
+ setup(t_addstr, "hello there");
+}
+
+void test_strbuf__add_append_str(void)
+{
+ setup_populated(t_addstr, "initial value", "hello there");
+}
diff --git a/t/unit-tests/u-strcmp-offset.c b/t/unit-tests/u-strcmp-offset.c
new file mode 100644
index 0000000000..7e8e9acf3c
--- /dev/null
+++ b/t/unit-tests/u-strcmp-offset.c
@@ -0,0 +1,45 @@
+#include "unit-test.h"
+#include "read-cache-ll.h"
+
+static void check_strcmp_offset(const char *string1, const char *string2,
+ int expect_result, uintmax_t expect_offset)
+{
+ size_t offset;
+ int result = strcmp_offset(string1, string2, &offset);
+
+ /*
+ * Because different CRTs behave differently, only rely on signs of the
+ * result values.
+ */
+ result = (result < 0 ? -1 :
+ result > 0 ? 1 :
+ 0);
+
+ cl_assert_equal_i(result, expect_result);
+ cl_assert_equal_i((uintmax_t)offset, expect_offset);
+}
+
+void test_strcmp_offset__empty(void)
+{
+ check_strcmp_offset("", "", 0, 0);
+}
+
+void test_strcmp_offset__equal(void)
+{
+ check_strcmp_offset("abc", "abc", 0, 3);
+}
+
+void test_strcmp_offset__different(void)
+{
+ check_strcmp_offset("abc", "def", -1, 0);
+}
+
+void test_strcmp_offset__mismatch(void)
+{
+ check_strcmp_offset("abc", "abz", -1, 2);
+}
+
+void test_strcmp_offset__different_length(void)
+{
+ check_strcmp_offset("abc", "abcdef", -1, 3);
+}