diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-08-11 18:04:11 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-08-11 18:04:11 -0700 |
commit | e0ad9574ddf5bb14d9ed6808112485ce0da99fea (patch) | |
tree | 633eb1867a929588ec5b3d8af351a93ba62aac5a | |
parent | Fifth batch (diff) | |
parent | t: remove test_oid_init in tests (diff) | |
download | tgif-e0ad9574ddf5bb14d9ed6808112485ce0da99fea.tar.xz |
Merge branch 'bc/sha-256-part-3'
The final leg of SHA-256 transition.
* bc/sha-256-part-3: (39 commits)
t: remove test_oid_init in tests
docs: add documentation for extensions.objectFormat
ci: run tests with SHA-256
t: make SHA1 prerequisite depend on default hash
t: allow testing different hash algorithms via environment
t: add test_oid option to select hash algorithm
repository: enable SHA-256 support by default
setup: add support for reading extensions.objectformat
bundle: add new version for use with SHA-256
builtin/verify-pack: implement an --object-format option
http-fetch: set up git directory before parsing pack hashes
t0410: mark test with SHA1 prerequisite
t5308: make test work with SHA-256
t9700: make hash size independent
t9500: ensure that algorithm info is preserved in config
t9350: make hash size independent
t9301: make hash size independent
t9300: use $ZERO_OID instead of hard-coded object ID
t9300: abstract away SHA-1-specific constants
t8011: make hash size independent
...
74 files changed, 633 insertions, 351 deletions
diff --git a/Documentation/config.txt b/Documentation/config.txt index ef0768b91a..3042d80978 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -348,6 +348,8 @@ include::config/diff.txt[] include::config/difftool.txt[] +include::config/extensions.txt[] + include::config/fastimport.txt[] include::config/feature.txt[] diff --git a/Documentation/config/extensions.txt b/Documentation/config/extensions.txt new file mode 100644 index 0000000000..4e23d73cdc --- /dev/null +++ b/Documentation/config/extensions.txt @@ -0,0 +1,8 @@ +extensions.objectFormat:: + Specify the hash algorithm to use. The acceptable values are `sha1` and + `sha256`. If not specified, `sha1` is assumed. It is an error to specify + this key unless `core.repositoryFormatVersion` is 1. ++ +Note that this setting should only be set by linkgit:git-init[1] or +linkgit:git-clone[1]. Trying to change it after initialization will not +work and will produce hard-to-diagnose issues. diff --git a/Documentation/git-bundle.txt b/Documentation/git-bundle.txt index d34b0964be..53804cad4b 100644 --- a/Documentation/git-bundle.txt +++ b/Documentation/git-bundle.txt @@ -9,7 +9,8 @@ git-bundle - Move objects and refs by archive SYNOPSIS -------- [verse] -'git bundle' create [-q | --quiet | --progress | --all-progress] [--all-progress-implied] <file> <git-rev-list-args> +'git bundle' create [-q | --quiet | --progress | --all-progress] [--all-progress-implied] + [--version=<version>] <file> <git-rev-list-args> 'git bundle' verify [-q | --quiet] <file> 'git bundle' list-heads <file> [<refname>...] 'git bundle' unbundle <file> [<refname>...] @@ -102,6 +103,12 @@ unbundle <file>:: is activated. Unlike --all-progress this flag doesn't actually force any progress display by itself. +--version=<version>:: + Specify the bundle version. Version 2 is the older format and can only be + used with SHA-1 repositories; the newer version 3 contains capabilities that + permit extensions. The default is the oldest supported format, based on the + hash algorithm in use. + -q:: --quiet:: This flag makes the command not to report its progress diff --git a/Documentation/technical/bundle-format.txt b/Documentation/technical/bundle-format.txt index 0e828151a5..bac558d049 100644 --- a/Documentation/technical/bundle-format.txt +++ b/Documentation/technical/bundle-format.txt @@ -7,6 +7,8 @@ The Git bundle format is a format that represents both refs and Git objects. We will use ABNF notation to define the Git bundle format. See protocol-common.txt for the details. +A v2 bundle looks like this: + ---- bundle = signature *prerequisite *reference LF pack signature = "# v2 git bundle" LF @@ -18,9 +20,28 @@ reference = obj-id SP refname LF pack = ... ; packfile ---- +A v3 bundle looks like this: + +---- +bundle = signature *capability *prerequisite *reference LF pack +signature = "# v3 git bundle" LF + +capability = "@" key ["=" value] LF +prerequisite = "-" obj-id SP comment LF +comment = *CHAR +reference = obj-id SP refname LF +key = 1*(ALPHA / DIGIT / "-") +value = *(%01-09 / %0b-FF) + +pack = ... ; packfile +---- + == Semantics -A Git bundle consists of three parts. +A Git bundle consists of several parts. + +* "Capabilities", which are only in the v3 format, indicate functionality that + the bundle requires to be read properly. * "Prerequisites" lists the objects that are NOT included in the bundle and the reader of the bundle MUST already have, in order to use the data in the @@ -46,3 +67,10 @@ put any string here. The reader of the bundle MUST ignore the comment. Note that the prerequisites does not represent a shallow-clone boundary. The semantics of the prerequisites and the shallow-clone boundaries are different, and the Git bundle v2 format cannot represent a shallow clone repository. + +== Capabilities + +Because there is no opportunity for negotiation, unknown capabilities cause 'git +bundle' to abort. The only known capability is `object-format`, which specifies +the hash algorithm in use, and can take the same values as the +`extensions.objectFormat` configuration value. diff --git a/builtin/bundle.c b/builtin/bundle.c index 750630bdd9..ea6948110b 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -60,6 +60,7 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { int all_progress_implied = 0; int progress = isatty(STDERR_FILENO); struct strvec pack_opts; + int version = -1; struct option options[] = { OPT_SET_INT('q', "quiet", &progress, @@ -71,6 +72,8 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { OPT_BOOL(0, "all-progress-implied", &all_progress_implied, N_("similar to --all-progress when progress meter is shown")), + OPT_INTEGER(0, "version", &version, + N_("specify bundle format version")), OPT_END() }; const char* bundle_file; @@ -91,7 +94,7 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { if (!startup_info->have_repository) die(_("Need a repository to create a bundle.")); - return !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts); + return !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts, version); } static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) { diff --git a/builtin/init-db.c b/builtin/init-db.c index cee64823cb..f70076d38e 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -183,11 +183,6 @@ void initialize_repository_version(int hash_algo) char repo_version_string[10]; int repo_version = GIT_REPO_VERSION; -#ifndef ENABLE_SHA256 - if (hash_algo != GIT_HASH_SHA1) - die(_("The hash algorithm %s is not supported in this build."), hash_algos[hash_algo].name); -#endif - if (hash_algo != GIT_HASH_SHA1) repo_version = GIT_REPO_VERSION_READ; diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c index c2a1a5c504..05c5213594 100644 --- a/builtin/verify-pack.c +++ b/builtin/verify-pack.c @@ -7,21 +7,26 @@ #define VERIFY_PACK_VERBOSE 01 #define VERIFY_PACK_STAT_ONLY 02 -static int verify_one_pack(const char *path, unsigned int flags) +static int verify_one_pack(const char *path, unsigned int flags, const char *hash_algo) { struct child_process index_pack = CHILD_PROCESS_INIT; - const char *argv[] = {"index-pack", NULL, NULL, NULL }; + struct strvec *argv = &index_pack.args; struct strbuf arg = STRBUF_INIT; int verbose = flags & VERIFY_PACK_VERBOSE; int stat_only = flags & VERIFY_PACK_STAT_ONLY; int err; + strvec_push(argv, "index-pack"); + if (stat_only) - argv[1] = "--verify-stat-only"; + strvec_push(argv, "--verify-stat-only"); else if (verbose) - argv[1] = "--verify-stat"; + strvec_push(argv, "--verify-stat"); else - argv[1] = "--verify"; + strvec_push(argv, "--verify"); + + if (hash_algo) + strvec_pushf(argv, "--object-format=%s", hash_algo); /* * In addition to "foo.pack" we accept "foo.idx" and "foo"; @@ -31,9 +36,8 @@ static int verify_one_pack(const char *path, unsigned int flags) if (strbuf_strip_suffix(&arg, ".idx") || !ends_with(arg.buf, ".pack")) strbuf_addstr(&arg, ".pack"); - argv[2] = arg.buf; + strvec_push(argv, arg.buf); - index_pack.argv = argv; index_pack.git_cmd = 1; err = run_command(&index_pack); @@ -60,12 +64,15 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix) { int err = 0; unsigned int flags = 0; + const char *object_format = NULL; int i; const struct option verify_pack_options[] = { OPT_BIT('v', "verbose", &flags, N_("verbose"), VERIFY_PACK_VERBOSE), OPT_BIT('s', "stat-only", &flags, N_("show statistics only"), VERIFY_PACK_STAT_ONLY), + OPT_STRING(0, "object-format", &object_format, N_("hash"), + N_("specify the hash algorithm to use")), OPT_END() }; @@ -75,7 +82,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix) if (argc < 1) usage_with_options(verify_pack_usage, verify_pack_options); for (i = 0; i < argc; i++) { - if (verify_one_pack(argv[i], flags)) + if (verify_one_pack(argv[i], flags, object_format)) err = 1; } @@ -12,7 +12,16 @@ #include "refs.h" #include "strvec.h" -static const char bundle_signature[] = "# v2 git bundle\n"; + +static const char v2_bundle_signature[] = "# v2 git bundle\n"; +static const char v3_bundle_signature[] = "# v3 git bundle\n"; +static struct { + int version; + const char *signature; +} bundle_sigs[] = { + { 2, v2_bundle_signature }, + { 3, v3_bundle_signature }, +}; static void add_to_ref_list(const struct object_id *oid, const char *name, struct ref_list *list) @@ -23,15 +32,30 @@ static void add_to_ref_list(const struct object_id *oid, const char *name, list->nr++; } -static const struct git_hash_algo *detect_hash_algo(struct strbuf *buf) +static int parse_capability(struct bundle_header *header, const char *capability) +{ + const char *arg; + if (skip_prefix(capability, "object-format=", &arg)) { + int algo = hash_algo_by_name(arg); + if (algo == GIT_HASH_UNKNOWN) + return error(_("unrecognized bundle hash algorithm: %s"), arg); + header->hash_algo = &hash_algos[algo]; + return 0; + } + return error(_("unknown capability '%s'"), capability); +} + +static int parse_bundle_signature(struct bundle_header *header, const char *line) { - size_t len = strcspn(buf->buf, " \n"); - int algo; + int i; - algo = hash_algo_by_length(len / 2); - if (algo == GIT_HASH_UNKNOWN) - return NULL; - return &hash_algos[algo]; + for (i = 0; i < ARRAY_SIZE(bundle_sigs); i++) { + if (!strcmp(line, bundle_sigs[i].signature)) { + header->version = bundle_sigs[i].version; + return 0; + } + } + return -1; } static int parse_bundle_header(int fd, struct bundle_header *header, @@ -42,14 +66,16 @@ static int parse_bundle_header(int fd, struct bundle_header *header, /* The bundle header begins with the signature */ if (strbuf_getwholeline_fd(&buf, fd, '\n') || - strcmp(buf.buf, bundle_signature)) { + parse_bundle_signature(header, buf.buf)) { if (report_path) - error(_("'%s' does not look like a v2 bundle file"), + error(_("'%s' does not look like a v2 or v3 bundle file"), report_path); status = -1; goto abort; } + header->hash_algo = the_hash_algo; + /* The bundle header ends with an empty line */ while (!strbuf_getwholeline_fd(&buf, fd, '\n') && buf.len && buf.buf[0] != '\n') { @@ -57,19 +83,19 @@ static int parse_bundle_header(int fd, struct bundle_header *header, int is_prereq = 0; const char *p; - if (*buf.buf == '-') { - is_prereq = 1; - strbuf_remove(&buf, 0, 1); - } strbuf_rtrim(&buf); - if (!header->hash_algo) { - header->hash_algo = detect_hash_algo(&buf); - if (!header->hash_algo) { - error(_("unknown hash algorithm length")); + if (header->version == 3 && *buf.buf == '@') { + if (parse_capability(header, buf.buf + 1)) { status = -1; break; } + continue; + } + + if (*buf.buf == '-') { + is_prereq = 1; + strbuf_remove(&buf, 0, 1); } /* @@ -449,13 +475,14 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) } int create_bundle(struct repository *r, const char *path, - int argc, const char **argv, struct strvec *pack_options) + int argc, const char **argv, struct strvec *pack_options, int version) { struct lock_file lock = LOCK_INIT; int bundle_fd = -1; int bundle_to_stdout; int ref_count = 0; struct rev_info revs; + int min_version = the_hash_algo == &hash_algos[GIT_HASH_SHA1] ? 2 : 3; bundle_to_stdout = !strcmp(path, "-"); if (bundle_to_stdout) @@ -464,8 +491,22 @@ int create_bundle(struct repository *r, const char *path, bundle_fd = hold_lock_file_for_update(&lock, path, LOCK_DIE_ON_ERROR); - /* write signature */ - write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature)); + if (version == -1) + version = min_version; + + if (version < 2 || version > 3) { + die(_("unsupported bundle version %d"), version); + } else if (version < min_version) { + die(_("cannot write bundle version %d with algorithm %s"), version, the_hash_algo->name); + } else if (version == 2) { + write_or_die(bundle_fd, v2_bundle_signature, strlen(v2_bundle_signature)); + } else { + const char *capability = "@object-format="; + write_or_die(bundle_fd, v3_bundle_signature, strlen(v3_bundle_signature)); + write_or_die(bundle_fd, capability, strlen(capability)); + write_or_die(bundle_fd, the_hash_algo->name, strlen(the_hash_algo->name)); + write_or_die(bundle_fd, "\n", 1); + } /* init revs to list objects for pack-objects later */ save_commit_buffer = 0; @@ -13,6 +13,7 @@ struct ref_list { }; struct bundle_header { + unsigned version; struct ref_list prerequisites; struct ref_list references; const struct git_hash_algo *hash_algo; @@ -21,7 +22,8 @@ struct bundle_header { int is_bundle(const char *path, int quiet); int read_bundle_header(const char *path, struct bundle_header *header); int create_bundle(struct repository *r, const char *path, - int argc, const char **argv, struct strvec *pack_options); + int argc, const char **argv, struct strvec *pack_options, + int version); int verify_bundle(struct repository *r, struct bundle_header *header, int verbose); #define BUNDLE_VERBOSE 1 int unbundle(struct repository *r, struct bundle_header *header, diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh index 17e25aade9..6c27b886b8 100755 --- a/ci/run-build-and-tests.sh +++ b/ci/run-build-and-tests.sh @@ -24,6 +24,12 @@ linux-gcc) export GIT_TEST_ADD_I_USE_BUILTIN=1 make test ;; +linux-clang) + export GIT_TEST_DEFAULT_HASH=sha1 + make test + export GIT_TEST_DEFAULT_HASH=sha256 + make test + ;; linux-gcc-4.8) # Don't run the tests; we only care about whether Git can be # built with GCC 4.8, as it errors out on some undesired (C99) diff --git a/config.mak.dev b/config.mak.dev index cd4a82a9eb..89b218d11a 100644 --- a/config.mak.dev +++ b/config.mak.dev @@ -16,8 +16,6 @@ DEVELOPER_CFLAGS += -Wstrict-prototypes DEVELOPER_CFLAGS += -Wunused DEVELOPER_CFLAGS += -Wvla -DEVELOPER_CFLAGS += -DENABLE_SHA256 - ifndef COMPILER_FEATURES COMPILER_FEATURES := $(shell ./detect-compiler $(CC)) endif diff --git a/http-fetch.c b/http-fetch.c index 1df376e745..c4ccc5fea9 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -84,8 +84,11 @@ int cmd_main(int argc, const char **argv) int get_verbosely = 0; int get_recover = 0; int packfile = 0; + int nongit; struct object_id packfile_hash; + setup_git_directory_gently(&nongit); + while (arg < argc && argv[arg][0] == '-') { const char *p; @@ -115,7 +118,8 @@ int cmd_main(int argc, const char **argv) if (argc != arg + 2 - (commits_on_stdin || packfile)) usage(http_fetch_usage); - setup_git_directory(); + if (nongit) + die(_("not a git repository")); git_config(git_default_config, NULL); diff --git a/repository.c b/repository.c index 6f7f6f002b..a4174ddb06 100644 --- a/repository.c +++ b/repository.c @@ -89,10 +89,6 @@ void repo_set_gitdir(struct repository *repo, void repo_set_hash_algo(struct repository *repo, int hash_algo) { repo->hash_algo = &hash_algos[hash_algo]; -#ifndef ENABLE_SHA256 - if (hash_algo != GIT_HASH_SHA1) - die(_("The hash algorithm %s is not supported in this build."), repo->hash_algo->name); -#endif } /* @@ -490,8 +490,17 @@ static enum extension_result handle_extension(const char *var, { if (!strcmp(ext, "noop-v1")) { return EXTENSION_OK; - } + } else if (!strcmp(ext, "objectformat")) { + int format; + if (!value) + return config_error_nonbool(var); + format = hash_algo_by_name(value); + if (format == GIT_HASH_UNKNOWN) + return error("invalid value for 'extensions.objectformat'"); + data->hash_algo = format; + return EXTENSION_OK; + } return EXTENSION_UNKNOWN; } diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index f0aa80b98e..5e77d56f59 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -50,6 +50,8 @@ static const char *bloom_usage = "\n" int cmd__bloom(int argc, const char **argv) { + setup_git_directory(); + if (argc < 2) usage(bloom_usage); diff --git a/t/lib-pack.sh b/t/lib-pack.sh index f3463170b3..bb8938ccbe 100644 --- a/t/lib-pack.sh +++ b/t/lib-pack.sh @@ -35,8 +35,6 @@ pack_header () { # have hardcoded some well-known objects. See the case statements below for the # complete list. pack_obj () { - test_oid_init - case "$1" in # empty blob $EMPTY_BLOB) @@ -93,6 +91,14 @@ pack_obj () { ;; esac ;; + # blob containing "\3\326" + 471819e8c52bf11513f100b2810a8aa0622d5cd3d1c913758a071dd4b3bad8fe) + case "$2" in + '') + printf '\062\170\234\143\276\006\000\000\336\000\332' + return + ;; + esac esac # If it's not a delta, we can convince pack-objects to generate a pack @@ -113,7 +119,6 @@ pack_obj () { # Compute and append pack trailer to "$1" pack_trailer () { - test_oid_init && test-tool $(test_oid algo) -b <"$1" >trailer.tmp && cat trailer.tmp >>"$1" && rm -f trailer.tmp diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index 07c822c8ff..87a759149f 100644 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -196,7 +196,6 @@ test_git_directory_exists () { # the submodule repo if it doesn't exist and configures the most problematic # settings for diff.ignoreSubmodules. prolog () { - test_oid_init && (test -d submodule_update_repo || create_lib_submodule_repo) && test_config_global diff.ignoreSubmodules all && test_config diff.ignoreSubmodules all diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 90bf1dbc8d..923281af93 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -891,10 +891,6 @@ test_expect_success 'test_atexit is run' " test_path_is_missing also-clean-atexit " -test_expect_success 'test_oid setup' ' - test_oid_init -' - test_expect_success 'test_oid provides sane info by default' ' test_oid zero >actual && grep "^00*\$" actual && @@ -928,6 +924,17 @@ test_expect_success 'test_oid can look up data for SHA-256' ' test "$hexsz" -eq 64 ' +test_expect_success 'test_oid can look up data for a specified algorithm' ' + rawsz="$(test_oid --hash=sha1 rawsz)" && + hexsz="$(test_oid --hash=sha1 hexsz)" && + test "$rawsz" -eq 20 && + test "$hexsz" -eq 40 && + rawsz="$(test_oid --hash=sha256 rawsz)" && + hexsz="$(test_oid --hash=sha256 hexsz)" && + test "$rawsz" -eq 32 && + test "$hexsz" -eq 64 +' + test_expect_success 'test_bool_env' ' ( sane_unset envvar && diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 6d2467995e..d71d4c7238 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -441,6 +441,39 @@ test_expect_success 're-init from a linked worktree' ' ) ' +test_expect_success 'init honors GIT_DEFAULT_HASH' ' + GIT_DEFAULT_HASH=sha1 git init sha1 && + git -C sha1 rev-parse --show-object-format >actual && + echo sha1 >expected && + test_cmp expected actual && + GIT_DEFAULT_HASH=sha256 git init sha256 && + git -C sha256 rev-parse --show-object-format >actual && + echo sha256 >expected && + test_cmp expected actual +' + +test_expect_success 'init honors --object-format' ' + git init --object-format=sha1 explicit-sha1 && + git -C explicit-sha1 rev-parse --show-object-format >actual && + echo sha1 >expected && + test_cmp expected actual && + git init --object-format=sha256 explicit-sha256 && + git -C explicit-sha256 rev-parse --show-object-format >actual && + echo sha256 >expected && + test_cmp expected actual +' + +test_expect_success 'extensions.objectFormat is not allowed with repo version 0' ' + git init --object-format=sha256 explicit-v0 && + git -C explicit-v0 config core.repositoryformatversion 0 && + test_must_fail git -C explicit-v0 rev-parse --show-object-format +' + +test_expect_success 'init rejects attempts to initialize with different hash' ' + test_must_fail git -C sha1 init --object-format=sha256 && + test_must_fail git -C sha256 init --object-format=sha1 +' + test_expect_success MINGW 'core.hidedotfiles = false' ' git config --global core.hidedotfiles false && rm -rf newdir && diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh index 6aa0f313bd..a5ebdf9ff3 100755 --- a/t/t0410-partial-clone.sh +++ b/t/t0410-partial-clone.sh @@ -42,7 +42,7 @@ test_expect_success 'convert shallow clone to partial clone' ' test_cmp_config -C client 1 core.repositoryformatversion ' -test_expect_success 'convert to partial clone with noop extension' ' +test_expect_success SHA1 'convert to partial clone with noop extension' ' rm -fr server client && test_create_repo server && test_commit -C server my_commit 1 && @@ -53,7 +53,7 @@ test_expect_success 'convert to partial clone with noop extension' ' git -C client fetch --unshallow --filter="blob:none" ' -test_expect_success 'converting to partial clone fails with unrecognized extension' ' +test_expect_success SHA1 'converting to partial clone fails with unrecognized extension' ' rm -fr server client && test_create_repo server && test_commit -C server my_commit 1 && diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 43c4be1e5e..2f501d2dc9 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -140,8 +140,6 @@ test_expect_success '--batch-check without %(rest) considers whole line' ' test_cmp expect actual ' -test_oid_init - tree_sha1=$(git write-tree) tree_size=$(($(test_oid rawsz) + 13)) tree_pretty_content="100644 blob $hello_sha1 hello" diff --git a/t/t1050-large.sh b/t/t1050-large.sh index 6a56d1ca24..61e89a8071 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -12,7 +12,6 @@ file_size () { } test_expect_success setup ' - test_oid_init && # clone does not allow us to pass core.bigfilethreshold to # new repos, so set core.bigfilethreshold globally git config --global core.bigfilethreshold 200k && diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 7cd45fc139..84acfc48b6 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -369,7 +369,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat git clone repo unmerged && cat >input <<-EOF && - 0 0000000000000000000000000000000000000000 folder1/a + 0 $ZERO_OID folder1/a 100644 $(git -C unmerged rev-parse HEAD:folder1/a) 1 folder1/a EOF git -C unmerged update-index --index-info <input && @@ -396,7 +396,7 @@ test_expect_success 'sparse-checkout reapply' ' echo dirty >tweak/deep/deeper2/a && cat >input <<-EOF && - 0 0000000000000000000000000000000000000000 folder1/a + 0 $ZERO_OID folder1/a 100644 $(git -C tweak rev-parse HEAD:folder1/a) 1 folder1/a EOF git -C tweak update-index --index-info <input && diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 76d9b744a6..730a43d9dd 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -54,7 +54,6 @@ check_dont_have () { } test_expect_success setup ' - test_oid_init && mkdir -p A/B && echo rat >C && echo ox >A/D && diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index af2a2c4682..b17f5c21fb 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -9,7 +9,6 @@ test_description='git fsck random collection of tests . ./test-lib.sh test_expect_success setup ' - test_oid_init && git config gc.auto 0 && git config i18n.commitencoding ISO-8859-1 && test_commit A fileA one && diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh index 603019b541..408b97d5af 100755 --- a/t/t1500-rev-parse.sh +++ b/t/t1500-rev-parse.sh @@ -59,7 +59,6 @@ test_rev_parse () { ROOT=$(pwd) test_expect_success 'setup' ' - test_oid_init && mkdir -p sub/dir work && cp -R .git repo.git ' diff --git a/t/t3305-notes-fanout.sh b/t/t3305-notes-fanout.sh index 3b4753e1b4..94c1b02251 100755 --- a/t/t3305-notes-fanout.sh +++ b/t/t3305-notes-fanout.sh @@ -7,7 +7,7 @@ test_description='Test that adding/removing many notes triggers automatic fanout path_has_fanout() { path=$1 && fanout=$2 && - after_last_slash=$((40 - $fanout * 2)) && + after_last_slash=$(($(test_oid hexsz) - $fanout * 2)) && echo $path | grep -q "^\([0-9a-f]\{2\}/\)\{$fanout\}[0-9a-f]\{$after_last_slash\}$" } diff --git a/t/t3308-notes-merge.sh b/t/t3308-notes-merge.sh index 790e292966..d69c84c640 100755 --- a/t/t3308-notes-merge.sh +++ b/t/t3308-notes-merge.sh @@ -22,7 +22,6 @@ test_expect_success setup ' # Copy notes to remote-notes git fetch . refs/notes/*:refs/remote-notes/origin/* && - test_oid_init && test_oid_cache <<-EOF hash4a sha1:5e93d24084d32e1cb61f7070505b9d2530cca987 hash3a sha1:8366731eeee53787d2bdf8fc1eff7d94757e8da0 diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 4a7d21f898..9744e88760 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1250,7 +1250,7 @@ test_expect_success 'rebase -i error on commits with \ in message' ' test_expect_code 1 grep " emp" error ' -test_expect_success SHA1 'short SHA-1 setup' ' +test_expect_success 'short commit ID setup' ' test_when_finished "git checkout master" && git checkout --orphan collide && git rm -rf . && @@ -1262,23 +1262,54 @@ test_expect_success SHA1 'short SHA-1 setup' ' ) ' -test_expect_success SHA1 'short SHA-1 collide' ' +if test -n "$GIT_TEST_FIND_COLLIDER" +then + author="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)" + committer="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)" + blob="$(git rev-parse collide2:collide)" + from="$(git rev-parse collide1^0)" + repl="commit refs/heads/collider-&\\n" + repl="${repl}author $author\\ncommitter $committer\\n" + repl="${repl}data <<EOF\\ncollide2 &\\nEOF\\n" + repl="${repl}from $from\\nM 100644 $blob collide\\n" + test_seq 1 32768 | sed "s|.*|$repl|" >script && + git fast-import <script && + git pack-refs && + git for-each-ref >refs && + grep "^$(test_oid t3404_collision)" <refs >matches && + cat matches && + test_line_count -gt 2 matches || { + echo "Could not find a collider" >&2 + exit 1 + } +fi + +test_expect_success 'short commit ID collide' ' + test_oid_cache <<-EOF && + # collision-related constants + t3404_collision sha1:6bcd + t3404_collision sha256:0161 + t3404_collider sha1:ac4f2ee + t3404_collider sha256:16697 + EOF test_when_finished "reset_rebase && git checkout master" && git checkout collide && - colliding_sha1=6bcda37 && - test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" && + colliding_id=$(test_oid t3404_collision) && + hexsz=$(test_oid hexsz) && + test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" && + test_config core.abbrev 4 && ( unset test_tick && test_tick && set_fake_editor && - FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \ + FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \ FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 && - test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" && - grep "^pick $colliding_sha1 " \ + test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" && + grep "^pick $colliding_id " \ .git/rebase-merge/git-rebase-todo.tmp && - grep "^pick [0-9a-f]\{40\}" \ + grep "^pick [0-9a-f]\{$hexsz\}" \ .git/rebase-merge/git-rebase-todo && - grep "^pick [0-9a-f]\{40\}" \ + grep "^pick [0-9a-f]\{$hexsz\}" \ .git/rebase-merge/git-rebase-todo.backup && git rebase --continue ) && diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index f2c0168941..efec8d13b6 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -241,7 +241,6 @@ test_expect_success 'refresh index before checking if it is up-to-date' ' ' test_expect_success 'choking "git rm" should not let it die with cruft' ' - test_oid_init && git reset -q --hard && test_when_finished "rm -f .git/index.lock && git reset -q --hard" && i=0 && diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index 64dcc5ec28..d696aa4e52 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -23,7 +23,6 @@ check_verify_failure () { # first create a commit, so we have a valid object/type # for the tag. test_expect_success 'setup' ' - test_oid_init && echo Hello >A && git update-index --add A && git commit -m "Initial commit" && diff --git a/t/t4002-diff-basic.sh b/t/t4002-diff-basic.sh index cbcdd10464..6a9f010197 100755 --- a/t/t4002-diff-basic.sh +++ b/t/t4002-diff-basic.sh @@ -10,8 +10,6 @@ test_description='Test diff raw-output. . "$TEST_DIRECTORY"/lib-read-tree-m-3way.sh -test_oid_init - test_oid_cache <<\EOF aa_1 sha1:ccba72ad3888a3520b39efcf780b9ee64167535d aa_1 sha256:9febfbf18197819b2735c45291f138525d2476d59470f98239647544586ba403 diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh index e29deaf4a5..d7145ccca4 100755 --- a/t/t4027-diff-submodule.sh +++ b/t/t4027-diff-submodule.sh @@ -6,7 +6,6 @@ test_description='difference in submodules' . "$TEST_DIRECTORY"/diff-lib.sh test_expect_success setup ' - test_oid_init && test_tick && test_create_repo sub && ( diff --git a/t/t4134-apply-submodule.sh b/t/t4134-apply-submodule.sh index 99ed4cc546..d1c16ba33c 100755 --- a/t/t4134-apply-submodule.sh +++ b/t/t4134-apply-submodule.sh @@ -8,7 +8,6 @@ test_description='git apply submodule tests' . ./test-lib.sh test_expect_success setup ' - test_oid_init && cat > create-sm.patch <<EOF && diff --git a/dir/sm b/dir/sm new file mode 160000 diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh index 831d424c47..d94d25e4f0 100755 --- a/t/t4200-rerere.sh +++ b/t/t4200-rerere.sh @@ -25,7 +25,6 @@ test_description='git rerere . ./test-lib.sh test_expect_success 'setup' ' - test_oid_init && cat >a1 <<-\EOF && Some title ========== diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index e186c83250..2d1d7b5d19 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -4,7 +4,6 @@ test_description='test log -L' . ./test-lib.sh test_expect_success 'setup (import history)' ' - test_oid_init && git fast-import < "$TEST_DIRECTORY"/t4211/history.export && git reset --hard ' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index d553d0ca46..3d6a93343a 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -12,8 +12,7 @@ TRASH=$(pwd) test_expect_success \ 'setup' \ - 'test_oid_init && - rm -f .git/index* && + 'rm -f .git/index* && perl -e "print \"a\" x 4096;" > a && perl -e "print \"b\" x 4096;" > b && perl -e "print \"c\" x 4096;" > c && diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index 8981c9b90e..119494bd64 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -7,7 +7,6 @@ test_description='pack index with 64-bit offsets and object CRC' . ./test-lib.sh test_expect_success 'setup' ' - test_oid_init && rawsz=$(test_oid rawsz) && rm -rf .git && git init && diff --git a/t/t5308-pack-detect-duplicates.sh b/t/t5308-pack-detect-duplicates.sh index 6845c1f3c3..693b2411c8 100755 --- a/t/t5308-pack-detect-duplicates.sh +++ b/t/t5308-pack-detect-duplicates.sh @@ -4,23 +4,27 @@ test_description='handling of duplicate objects in incoming packfiles' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-pack.sh -if ! test_have_prereq SHA1 -then - skip_all='not using SHA-1 for objects' - test_done -fi +test_expect_success 'setup' ' + test_oid_cache <<-EOF + lo_oid sha1:e68fe8129b546b101aee9510c5328e7f21ca1d18 + lo_oid sha256:471819e8c52bf11513f100b2810a8aa0622d5cd3d1c913758a071dd4b3bad8fe + + missing_oid sha1:e69d000000000000000000000000000000000000 + missing_oid sha256:4720000000000000000000000000000000000000000000000000000000000000 + EOF +' # The sha1s we have in our pack. It's important that these have the same # starting byte, so that they end up in the same fanout section of the index. # That lets us make sure we are exercising the binary search with both sets. -LO_SHA1=e68fe8129b546b101aee9510c5328e7f21ca1d18 -HI_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 +LO_SHA1=$(test_oid lo_oid) +HI_SHA1=$EMPTY_BLOB # And here's a "missing sha1" which will produce failed lookups. It must also # be in the same fanout section, and should be between the two (so that during # our binary search, we are sure to end up looking at one or the other of the # duplicate runs). -MISSING_SHA1='e69d000000000000000000000000000000000000' +MISSING_SHA1=$(test_oid missing_oid) # git will never intentionally create packfiles with # duplicate objects, so we have to construct them by hand. diff --git a/t/t5313-pack-bounds-checks.sh b/t/t5313-pack-bounds-checks.sh index 2a4557efc2..535313e4dc 100755 --- a/t/t5313-pack-bounds-checks.sh +++ b/t/t5313-pack-bounds-checks.sh @@ -45,7 +45,6 @@ extended_table () { } test_expect_success 'setup' ' - test_oid_init && test_oid_cache <<-EOF oid000 sha1:1485 oid000 sha256:4222 diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 2804b0dd45..044cf8a3de 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -10,8 +10,7 @@ test_expect_success 'setup full repo' ' cd "$TRASH_DIRECTORY/full" && git init && git config core.commitGraph true && - objdir=".git/objects" && - test_oid_init + objdir=".git/objects" ' test_expect_success POSIXPERM 'tweak umask for modebit tests' ' diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index 7214cab36c..7dfff0f8f4 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -29,7 +29,6 @@ midx_read_expect () { } test_expect_success 'setup' ' - test_oid_init && test_oid_cache <<-EOF idxoff sha1:2999 idxoff sha256:3739 diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh index 9b850ea907..ea28d522b8 100755 --- a/t/t5324-split-commit-graph.sh +++ b/t/t5324-split-commit-graph.sh @@ -12,7 +12,6 @@ test_expect_success 'setup repo' ' git config gc.writeCommitGraph false && infodir=".git/objects/info" && graphdir="$infodir/commit-graphs" && - test_oid_init && test_oid_cache <<-EOM shallow sha1:1760 shallow sha256:2064 diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh index a32efe2b6c..1a16ac4c0d 100755 --- a/t/t5504-fetch-receive-strict.sh +++ b/t/t5504-fetch-receive-strict.sh @@ -4,7 +4,6 @@ test_description='fetch/receive strict mode' . ./test-lib.sh test_expect_success 'setup and inject "corrupt or missing" object' ' - test_oid_init && echo hello >greetings && git add greetings && git commit -m greetings && diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 7456c567cd..e567cba38d 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -281,15 +281,19 @@ test_expect_success 'create bundle 1' ' cd "$D" && echo >file updated again by origin && git commit -a -m "tip" && - git bundle create bundle1 master^..master + git bundle create --version=3 bundle1 master^..master ' test_expect_success 'header of bundle looks right' ' - head -n 4 "$D"/bundle1 && - head -n 1 "$D"/bundle1 | grep "^#" && - head -n 2 "$D"/bundle1 | grep "^-$OID_REGEX " && - head -n 3 "$D"/bundle1 | grep "^$OID_REGEX " && - head -n 4 "$D"/bundle1 | grep "^$" + cat >expect <<-EOF && + # v3 git bundle + @object-format=$(test_oid algo) + -OID updated by origin + OID refs/heads/master + + EOF + sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual && + test_cmp expect actual ' test_expect_success 'create bundle 2' ' diff --git a/t/t5530-upload-pack-error.sh b/t/t5530-upload-pack-error.sh index 4ce9a9f704..205a2631e7 100755 --- a/t/t5530-upload-pack-error.sh +++ b/t/t5530-upload-pack-error.sh @@ -14,7 +14,6 @@ corrupt_repo () { } test_expect_success 'setup and corrupt repository' ' - test_oid_init && echo file >file && git add file && git rev-parse :file && diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh index c6ec625497..e5d3d15ba8 100755 --- a/t/t5562-http-backend-content-length.sh +++ b/t/t5562-http-backend-content-length.sh @@ -46,7 +46,6 @@ ssize_b100dots() { } test_expect_success 'setup' ' - test_oid_init && HTTP_CONTENT_ENCODING="identity" && export HTTP_CONTENT_ENCODING && git config http.receivepack true && diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh index 6d5a977fcb..26985f4b44 100755 --- a/t/t5607-clone-bundle.sh +++ b/t/t5607-clone-bundle.sh @@ -4,6 +4,10 @@ test_description='some bundle related tests' . ./test-lib.sh test_expect_success 'setup' ' + test_oid_cache <<-EOF && + version sha1:2 + version sha256:3 + EOF test_commit initial && test_tick && git tag -m tag tag && @@ -94,4 +98,31 @@ test_expect_success 'fetch SHA-1 from bundle' ' git fetch --no-tags foo/tip.bundle "$(cat hash)" ' +test_expect_success 'git bundle uses expected default format' ' + git bundle create bundle HEAD^.. && + head -n1 bundle | grep "^# v$(test_oid version) git bundle$" +' + +test_expect_success 'git bundle v3 has expected contents' ' + git branch side HEAD && + git bundle create --version=3 bundle HEAD^..side && + head -n2 bundle >actual && + cat >expect <<-EOF && + # v3 git bundle + @object-format=$(test_oid algo) + EOF + test_cmp expect actual && + git bundle verify bundle +' + +test_expect_success 'git bundle v3 rejects unknown capabilities' ' + cat >new <<-EOF && + # v3 git bundle + @object-format=$(test_oid algo) + @unknown=silly + EOF + test_must_fail git bundle verify new 2>output && + test_i18ngrep "unknown capability .unknown=silly." output +' + test_done diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index 1b54c35b01..5a60fbe3ed 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -13,7 +13,6 @@ start_git_daemon --export-all --enable=receive-pack daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent test_expect_success 'create repo to be served by git-daemon' ' - test_oid_init && git init "$daemon_parent" && test_commit -C "$daemon_parent" one ' @@ -829,7 +828,7 @@ test_expect_success 'part of packfile response provided as URI' ' # Ensure that my-blob and other-blob are in separate packfiles. for idx in http_child/.git/objects/pack/*.idx do - git verify-pack --verbose $idx >out && + git verify-pack --object-format=$(test_oid algo) --verbose $idx >out && { grep "^[0-9a-f]\{16,\} " out || : } >out.objectlist && diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 748282f058..d9ecf0f4a9 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -43,7 +43,6 @@ write_command () { # \ | / # a test_expect_success 'setup repository' ' - test_oid_init && test_commit a && git checkout -b o/foo && test_commit b && diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 7e82e43a63..bc95da8a5f 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -32,7 +32,6 @@ changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) truncate_count=20 test_expect_success 'setup' ' - test_oid_init && : >foo && git add foo && git config i18n.commitEncoding $test_encoding && diff --git a/t/t6100-rev-list-in-order.sh b/t/t6100-rev-list-in-order.sh index b2bb0a7f61..e934bc239c 100755 --- a/t/t6100-rev-list-in-order.sh +++ b/t/t6100-rev-list-in-order.sh @@ -22,7 +22,7 @@ test_expect_success 'setup a commit history with trees, blobs' ' test_expect_success 'rev-list --in-commit-order' ' git rev-list --in-commit-order --objects HEAD >actual.raw && - cut -c 1-40 >actual <actual.raw && + cut -d" " -f1 >actual <actual.raw && git cat-file --batch-check="%(objectname)" >expect.raw <<-\EOF && HEAD^{commit} @@ -49,7 +49,7 @@ test_expect_success 'rev-list --in-commit-order' ' test_expect_success 'rev-list lists blobs and trees after commits' ' git rev-list --objects HEAD >actual.raw && - cut -c 1-40 >actual <actual.raw && + cut -d" " -f1 >actual <actual.raw && git cat-file --batch-check="%(objectname)" >expect.raw <<-\EOF && HEAD^{commit} diff --git a/t/t6101-rev-parse-parents.sh b/t/t6101-rev-parse-parents.sh index 7683e4a114..7531262a5e 100755 --- a/t/t6101-rev-parse-parents.sh +++ b/t/t6101-rev-parse-parents.sh @@ -34,7 +34,7 @@ test_expect_success 'setup' ' ' test_expect_success 'start is valid' ' - git rev-parse start | grep "^[0-9a-f]\{40\}$" + git rev-parse start | grep "^$OID_REGEX$" ' test_expect_success 'start^0' ' diff --git a/t/t6301-for-each-ref-errors.sh b/t/t6301-for-each-ref-errors.sh index 49cc65bb58..809854fc0c 100755 --- a/t/t6301-for-each-ref-errors.sh +++ b/t/t6301-for-each-ref-errors.sh @@ -5,9 +5,9 @@ test_description='for-each-ref errors for broken refs' . ./test-lib.sh ZEROS=$ZERO_OID -MISSING=abababababababababababababababababababab test_expect_success setup ' + MISSING=$(test_oid deadbeef) && git commit --allow-empty -m "Initial" && git tag testtag && git for-each-ref >full-list && diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index 0a69a67117..4a3b8f48ac 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -10,7 +10,24 @@ test_expect_success 'setup' ' # do not let the amount of physical memory affects gc # behavior, make sure we always pack everything to one pack by # default - git config gc.bigPackThreshold 2g + git config gc.bigPackThreshold 2g && + + # These are simply values which, when hashed as a blob with a newline, + # produce a hash where the first byte is 0x17 in their respective + # algorithms. + test_oid_cache <<-EOF + obj1 sha1:263 + obj1 sha256:34 + + obj2 sha1:410 + obj2 sha256:174 + + obj3 sha1:523 + obj3 sha256:313 + + obj4 sha1:790 + obj4 sha256:481 + EOF ' test_expect_success 'gc empty repository' ' @@ -85,13 +102,13 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre # We need to create two object whose sha1s start with 17 # since this is what git gc counts. As it happens, these # two blobs will do so. - test_commit 263 && - test_commit 410 && + test_commit "$(test_oid obj1)" && + test_commit "$(test_oid obj2)" && # Our first gc will create a pack; our second will create a second pack git gc --auto && ls .git/objects/pack | sort >existing_packs && - test_commit 523 && - test_commit 790 && + test_commit "$(test_oid obj3)" && + test_commit "$(test_oid obj4)" && git gc --auto 2>err && test_i18ngrep ! "^warning:" err && diff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh index f30b4849b6..8a3bb4105b 100755 --- a/t/t6501-freshen-objects.sh +++ b/t/t6501-freshen-objects.sh @@ -128,9 +128,9 @@ for repack in '' true; do done test_expect_success 'do not complain about existing broken links (commit)' ' - cat >broken-commit <<-\EOF && - tree 0000000000000000000000000000000000000001 - parent 0000000000000000000000000000000000000002 + cat >broken-commit <<-EOF && + tree $(test_oid 001) + parent $(test_oid 002) author whatever <whatever@example.com> 1234 -0000 committer whatever <whatever@example.com> 1234 -0000 @@ -143,8 +143,8 @@ test_expect_success 'do not complain about existing broken links (commit)' ' ' test_expect_success 'do not complain about existing broken links (tree)' ' - cat >broken-tree <<-\EOF && - 100644 blob 0000000000000000000000000000000000000003 foo + cat >broken-tree <<-EOF && + 100644 blob $(test_oid 003) foo EOF tree=$(git mktree --missing <broken-tree) && git gc -q 2>stderr && @@ -153,8 +153,8 @@ test_expect_success 'do not complain about existing broken links (tree)' ' ' test_expect_success 'do not complain about existing broken links (tag)' ' - cat >broken-tag <<-\EOF && - object 0000000000000000000000000000000000000004 + cat >broken-tag <<-EOF && + object $(test_oid 004) type commit tag broken tagger whatever <whatever@example.com> 1234 -0000 diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index e23de7d0b5..36477cb1f4 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -463,10 +463,11 @@ test_expect_success 'rewrite submodule with another content' ' ' test_expect_success 'replace submodule revision' ' + invalid=$(test_oid numeric) && git reset --hard original && git filter-branch -f --tree-filter \ "if git ls-files --error-unmatch -- submod > /dev/null 2>&1 - then git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 submod + then git update-index --cacheinfo 160000 $invalid submod fi" HEAD && test $orig_head != $(git show-ref --hash --head HEAD) ' diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh index 428cff9cf3..a682a3d826 100755 --- a/t/t7063-status-untracked-cache.sh +++ b/t/t7063-status-untracked-cache.sh @@ -75,14 +75,24 @@ test_expect_success 'setup' ' touch one two three done/one dtwo/two dthree/three && git add one two done/one && : >.git/info/exclude && - git update-index --untracked-cache + git update-index --untracked-cache && + test_oid_cache <<-EOF + root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e + root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974 + + exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0 + exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c + + done sha1:1946f0437f90c5005533cbe1736a6451ca301714 + done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc + EOF ' test_expect_success 'untracked cache is empty' ' test-tool dump-untracked-cache >../actual && cat >../expect-empty <<EOF && -info/exclude 0000000000000000000000000000000000000000 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $ZERO_OID +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 EOF @@ -100,17 +110,17 @@ EOF cat >../dump.expect <<EOF && info/exclude $EMPTY_BLOB -core.excludesfile 0000000000000000000000000000000000000000 +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ 0000000000000000000000000000000000000000 recurse valid +/ $ZERO_OID recurse valid dthree/ dtwo/ three -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid three -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF @@ -190,18 +200,18 @@ test_expect_success 'verify untracked cache dump' ' test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && info/exclude $EMPTY_BLOB -core.excludesfile 0000000000000000000000000000000000000000 +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ 0000000000000000000000000000000000000000 recurse valid +/ $ZERO_OID recurse valid dthree/ dtwo/ four three -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid three -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -239,18 +249,18 @@ test_expect_success 'verify untracked cache dump' ' test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && info/exclude $EMPTY_BLOB -core.excludesfile 0000000000000000000000000000000000000000 +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid +/ $(test_oid root) recurse valid .gitignore dthree/ dtwo/ three -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid three -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -284,16 +294,16 @@ EOF test_expect_success 'verify untracked cache dump' ' test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && -info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $(test_oid exclude) +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid +/ $(test_oid root) recurse valid .gitignore dtwo/ -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -303,14 +313,14 @@ test_expect_success 'move two from tracked to untracked' ' git rm --cached two && test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && -info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $(test_oid exclude) +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/ $(test_oid root) recurse +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -342,17 +352,17 @@ EOF test_expect_success 'verify untracked cache dump' ' test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && -info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $(test_oid exclude) +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid +/ $(test_oid root) recurse valid .gitignore dtwo/ two -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -362,14 +372,14 @@ test_expect_success 'move two from untracked to tracked' ' git add two && test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && -info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $(test_oid exclude) +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/ $(test_oid root) recurse +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -401,16 +411,16 @@ EOF test_expect_success 'verify untracked cache dump' ' test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && -info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $(test_oid exclude) +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid +/ $(test_oid root) recurse valid .gitignore dtwo/ -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -447,16 +457,16 @@ EOF test_expect_success 'untracked cache correct after commit' ' test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && -info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $(test_oid exclude) +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid +/ $(test_oid root) recurse valid .gitignore dtwo/ -/done/ 0000000000000000000000000000000000000000 recurse valid -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/ $ZERO_OID recurse valid +/dthree/ $ZERO_OID recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -508,17 +518,17 @@ EOF test_expect_success 'untracked cache correct after status' ' test-tool dump-untracked-cache >../actual && cat >../expect <<EOF && -info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $(test_oid exclude) +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid +/ $(test_oid root) recurse valid .gitignore dtwo/ -/done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid +/done/ $(test_oid done) recurse valid five -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/dthree/ $ZERO_OID recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect ../actual @@ -580,22 +590,22 @@ EOF test_expect_success 'verify untracked cache dump (sparse/subdirs)' ' test-tool dump-untracked-cache >../actual && cat >../expect-from-test-dump <<EOF && -info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 -core.excludesfile 0000000000000000000000000000000000000000 +info/exclude $(test_oid exclude) +core.excludesfile $ZERO_OID exclude_per_dir .gitignore flags 00000006 -/ e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid +/ $(test_oid root) recurse valid .gitignore dtwo/ -/done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid +/done/ $(test_oid done) recurse valid five sub/ -/done/sub/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/sub/ $ZERO_OID recurse check_only valid sub/ -/done/sub/sub/ 0000000000000000000000000000000000000000 recurse check_only valid +/done/sub/sub/ $ZERO_OID recurse check_only valid file -/dthree/ 0000000000000000000000000000000000000000 recurse check_only valid -/dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid +/dthree/ $ZERO_OID recurse check_only valid +/dtwo/ $ZERO_OID recurse check_only valid two EOF test_cmp ../expect-from-test-dump ../actual @@ -806,8 +816,8 @@ test_expect_success '"status" after file replacement should be clean with UC=tru test-tool dump-untracked-cache >../actual && grep -F "recurse valid" ../actual >../actual.grep && cat >../expect.grep <<EOF && -/ 0000000000000000000000000000000000000000 recurse valid -/two/ 0000000000000000000000000000000000000000 recurse valid +/ $ZERO_OID recurse valid +/two/ $ZERO_OID recurse valid EOF status_is_clean && test_cmp ../expect.grep ../actual.grep diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 97be0d968d..22161b3b2d 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -37,17 +37,23 @@ test_expect_success 'creating initial files and commits' ' echo "2nd line 1st file" >>first && git commit -a -m "modify 1st file" && + head5p2=$(git rev-parse --verify HEAD) && + head5p2f=$(git rev-parse --short HEAD:first) && git rm first && git mv second secondfile && git commit -a -m "remove 1st and rename 2nd" && + head5p1=$(git rev-parse --verify HEAD) && + head5p1s=$(git rev-parse --short HEAD:secondfile) && echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && # "git commit -m" would break MinGW, as Windows refuse to pass # $test_encoding encoded parameter to git. commit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - && - head5=$(git rev-parse --verify HEAD) + head5=$(git rev-parse --verify HEAD) && + head5s=$(git rev-parse --short HEAD:secondfile) && + head5sl=$(git rev-parse HEAD:secondfile) ' # git log --pretty=oneline # to see those SHA1 involved @@ -94,7 +100,7 @@ test_expect_success 'giving a non existing revision should fail' ' test_expect_success 'reset --soft with unmerged index should fail' ' touch .git/MERGE_HEAD && - echo "100644 44c5b5884550c17758737edcced463447b91d42b 1 un" | + echo "100644 $head5sl 1 un" | git update-index --index-info && test_must_fail git reset --soft HEAD && rm .git/MERGE_HEAD && @@ -192,7 +198,7 @@ test_expect_success \ >.diff_expect cat >.cached_expect <<EOF diff --git a/secondfile b/secondfile -index 1bbba79..44c5b58 100644 +index $head5p1s..$head5s 100644 --- a/secondfile +++ b/secondfile @@ -1 +1,2 @@ @@ -207,7 +213,7 @@ secondfile: EOF test_expect_success '--soft reset only should show changes in diff --cached' ' git reset --soft HEAD^ && - check_changes d1a4bc3abce4829628ae2dcb0d60ef3d1a78b1c4 && + check_changes $head5p1 && test "$(git rev-parse ORIG_HEAD)" = \ $head5 ' @@ -242,7 +248,7 @@ EOF test_expect_success \ '--hard reset should change the files and undo commits permanently' ' git reset --hard HEAD~2 && - check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && + check_changes $head5p2 && test "$(git rev-parse ORIG_HEAD)" = \ $head4 ' @@ -251,7 +257,7 @@ test_expect_success \ cat >.cached_expect <<EOF diff --git a/first b/first deleted file mode 100644 -index 8206c22..0000000 +index $head5p2f..0000000 --- a/first +++ /dev/null @@ -1,2 +0,0 @@ @@ -259,14 +265,14 @@ index 8206c22..0000000 -2nd line 1st file diff --git a/second b/second deleted file mode 100644 -index 1bbba79..0000000 +index $head5p1s..0000000 --- a/second +++ /dev/null @@ -1 +0,0 @@ -2nd file diff --git a/secondfile b/secondfile new file mode 100644 -index 0000000..44c5b58 +index 0000000..$head5s --- /dev/null +++ b/secondfile @@ -0,0 +1,2 @@ @@ -286,13 +292,13 @@ test_expect_success \ echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && git add secondfile && - check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e + check_changes $head5p2 ' cat >.diff_expect <<EOF diff --git a/first b/first deleted file mode 100644 -index 8206c22..0000000 +index $head5p2f..0000000 --- a/first +++ /dev/null @@ -1,2 +0,0 @@ @@ -300,7 +306,7 @@ index 8206c22..0000000 -2nd line 1st file diff --git a/second b/second deleted file mode 100644 -index 1bbba79..0000000 +index $head5p1s..0000000 --- a/second +++ /dev/null @@ -1 +0,0 @@ @@ -314,9 +320,8 @@ secondfile: EOF test_expect_success '--mixed reset to HEAD should unadd the files' ' git reset && - check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && - test "$(git rev-parse ORIG_HEAD)" = \ - ddaefe00f1da16864591c61fdc7adb5d7cd6b74e + check_changes $head5p2 && + test "$(git rev-parse ORIG_HEAD)" = $head5p2 ' >.diff_expect @@ -328,7 +333,7 @@ secondfile: EOF test_expect_success 'redoing the last two commits should succeed' ' git add secondfile && - git reset --hard ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && + git reset --hard $head5p2 && git rm first && git mv second secondfile && @@ -389,47 +394,55 @@ test_expect_success \ check_changes $head5 ' -cat > expect << EOF -diff --git a/file1 b/file1 -index d00491f..7ed6ff8 100644 ---- a/file1 -+++ b/file1 -@@ -1 +1 @@ --1 -+5 -diff --git a/file2 b/file2 -deleted file mode 100644 -index 0cfbf08..0000000 ---- a/file2 -+++ /dev/null -@@ -1 +0,0 @@ --2 -EOF -cat > cached_expect << EOF -diff --git a/file4 b/file4 -new file mode 100644 -index 0000000..b8626c4 ---- /dev/null -+++ b/file4 -@@ -0,0 +1 @@ -+4 -EOF test_expect_success 'test --mixed <paths>' ' echo 1 > file1 && echo 2 > file2 && git add file1 file2 && test_tick && git commit -m files && + before1=$(git rev-parse --short HEAD:file1) && + before2=$(git rev-parse --short HEAD:file2) && git rm file2 && echo 3 > file3 && echo 4 > file4 && echo 5 > file1 && + after1=$(git rev-parse --short $(git hash-object file1)) && + after4=$(git rev-parse --short $(git hash-object file4)) && git add file1 file3 file4 && git reset HEAD -- file1 file2 file3 && test_must_fail git diff --quiet && git diff > output && + + cat > expect <<-EOF && + diff --git a/file1 b/file1 + index $before1..$after1 100644 + --- a/file1 + +++ b/file1 + @@ -1 +1 @@ + -1 + +5 + diff --git a/file2 b/file2 + deleted file mode 100644 + index $before2..0000000 + --- a/file2 + +++ /dev/null + @@ -1 +0,0 @@ + -2 + EOF + test_cmp expect output && git diff --cached > output && + + cat > cached_expect <<-EOF && + diff --git a/file4 b/file4 + new file mode 100644 + index 0000000..$after4 + --- /dev/null + +++ b/file4 + @@ -0,0 +1 @@ + +4 + EOF + test_cmp cached_expect output ' diff --git a/t/t7201-co.sh b/t/t7201-co.sh index b696bae5f5..4d62b9b00f 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -230,9 +230,10 @@ test_expect_success 'switch to another branch while carrying a deletion' ' test_expect_success 'checkout to detach HEAD (with advice declined)' ' git config advice.detachedHead false && + rev=$(git rev-parse --short renamer^) && git checkout -f renamer && git clean -f && git checkout renamer^ 2>messages && - test_i18ngrep "HEAD is now at 7329388" messages && + test_i18ngrep "HEAD is now at $rev" messages && test_line_count = 1 messages && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && @@ -248,9 +249,10 @@ test_expect_success 'checkout to detach HEAD (with advice declined)' ' test_expect_success 'checkout to detach HEAD' ' git config advice.detachedHead true && + rev=$(git rev-parse --short renamer^) && git checkout -f renamer && git clean -f && GIT_TEST_GETTEXT_POISON=false git checkout renamer^ 2>messages && - grep "HEAD is now at 7329388" messages && + grep "HEAD is now at $rev" messages && test_line_count -gt 1 messages && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 956e17abb3..fec7e0299d 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -1231,7 +1231,7 @@ test_expect_success 'submodule helper list is not confused by common prefixes' ' git submodule add /dir1/b dir1/b && git submodule add /dir2/b dir2/b && git commit -m "first submodule commit" && - git submodule--helper list dir1/b |cut -c51- >actual && + git submodule--helper list dir1/b | cut -f 2 >actual && echo "dir1/b" >expect && test_cmp expect actual ' @@ -1260,7 +1260,7 @@ test_expect_success 'submodule update --init with a specification' ' pwd=$(pwd) && git clone file://"$pwd"/multisuper multisuper_clone && git -C multisuper_clone submodule update --init . ":(exclude)sub0" && - git -C multisuper_clone submodule status |cut -c 1,43- >actual && + git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && test_cmp expect actual ' @@ -1271,7 +1271,7 @@ test_expect_success 'submodule update --init with submodule.active set' ' git -C multisuper_clone config submodule.active "." && git -C multisuper_clone config --add submodule.active ":(exclude)sub0" && git -C multisuper_clone submodule update --init && - git -C multisuper_clone submodule status |cut -c 1,43- >actual && + git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && test_cmp expect actual ' @@ -1290,7 +1290,7 @@ test_expect_success 'submodule update and setting submodule.<name>.active' ' -sub3 EOF git -C multisuper_clone submodule update && - git -C multisuper_clone submodule status |cut -c 1,43- >actual && + git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && test_cmp expect actual ' @@ -1307,12 +1307,12 @@ test_expect_success 'clone active submodule without submodule url set' ' git submodule update && git submodule status >actual_raw && - cut -c 1,43- actual_raw >actual && + cut -d" " -f3- actual_raw >actual && cat >expect <<-\EOF && - sub0 (test2) - sub1 (test2) - sub2 (test2) - sub3 (test2) + sub0 (test2) + sub1 (test2) + sub2 (test2) + sub3 (test2) EOF test_cmp expect actual ) @@ -1328,7 +1328,7 @@ test_expect_success 'clone --recurse-submodules with a pathspec works' ' EOF git clone --recurse-submodules="sub0" multisuper multisuper_clone && - git -C multisuper_clone submodule status |cut -c1,43- >actual && + git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && test_cmp expected actual ' @@ -1345,7 +1345,7 @@ test_expect_success 'clone with multiple --recurse-submodules options' ' --recurse-submodules=":(exclude)sub0" \ --recurse-submodules=":(exclude)sub2" \ multisuper multisuper_clone && - git -C multisuper_clone submodule status |cut -c1,43- >actual && + git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && test_cmp expect actual ' @@ -1373,7 +1373,7 @@ test_expect_success 'clone and subsequent updates correctly auto-initialize subm --recurse-submodules=":(exclude)sub4" \ multisuper multisuper_clone && - git -C multisuper_clone submodule status |cut -c1,43- >actual && + git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && test_cmp expect actual && git -C multisuper submodule add ../sub1 sub4 && @@ -1382,7 +1382,7 @@ test_expect_success 'clone and subsequent updates correctly auto-initialize subm # obtain the new superproject git -C multisuper_clone pull && git -C multisuper_clone submodule update --init && - git -C multisuper_clone submodule status |cut -c1,43- >actual && + git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && test_cmp expect2 actual ' diff --git a/t/t7405-submodule-merge.sh b/t/t7405-submodule-merge.sh index aa33978ed2..6a1e5f8232 100755 --- a/t/t7405-submodule-merge.sh +++ b/t/t7405-submodule-merge.sh @@ -195,7 +195,7 @@ test_expect_success 'git submodule status should display the merge conflict prop url = $TRASH_DIRECTORY/sub EOF cat >expect <<EOF && -U0000000000000000000000000000000000000000 sub +U$ZERO_OID sub EOF git submodule status > actual && test_cmp expect actual && @@ -214,7 +214,7 @@ test_expect_success 'git submodule status should display the merge conflict prop url = $TRASH_DIRECTORY/sub EOF cat >expect <<EOF && -U0000000000000000000000000000000000000000 sub +U$ZERO_OID sub EOF git submodule status > actual && test_cmp expect actual && diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh index 08629a6e70..3fcb44767f 100755 --- a/t/t7506-status-submodule.sh +++ b/t/t7506-status-submodule.sh @@ -22,6 +22,10 @@ sanitize_output () { mv output2 output } +sanitize_diff () { + sed -e "/^index [0-9a-f,]*\.\.[0-9a-f]*/d" "$1" +} + test_expect_success 'setup' ' test_create_repo_with_commit sub && @@ -269,7 +273,6 @@ short_sha1_merge_sub1=$(cd sub1 && git rev-parse --short HEAD) short_sha1_merge_sub2=$(cd sub2 && git rev-parse --short HEAD) cat >diff_expect <<\EOF diff --cc .gitmodules -index badaa4c,44f999a..0000000 --- a/.gitmodules +++ b/.gitmodules @@@ -1,3 -1,3 +1,9 @@@ @@ -286,7 +289,6 @@ EOF cat >diff_submodule_expect <<\EOF diff --cc .gitmodules -index badaa4c,44f999a..0000000 --- a/.gitmodules +++ b/.gitmodules @@@ -1,3 -1,3 +1,9 @@@ @@ -306,7 +308,8 @@ test_expect_success 'diff with merge conflict in .gitmodules' ' cd super && git diff >../diff_actual 2>&1 ) && - test_cmp diff_expect diff_actual + sanitize_diff diff_actual >diff_sanitized && + test_cmp diff_expect diff_sanitized ' test_expect_success 'diff --submodule with merge conflict in .gitmodules' ' @@ -314,7 +317,8 @@ test_expect_success 'diff --submodule with merge conflict in .gitmodules' ' cd super && git diff --submodule >../diff_submodule_actual 2>&1 ) && - test_cmp diff_submodule_expect diff_submodule_actual + sanitize_diff diff_submodule_actual >diff_sanitized && + test_cmp diff_submodule_expect diff_sanitized ' # We'll setup different cases for further testing: diff --git a/t/t7508-status.sh b/t/t7508-status.sh index 8e969f3e36..e81759319f 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -837,7 +837,7 @@ EOF ' cat >expect <<EOF -:100644 100644 $EMPTY_BLOB 0000000000000000000000000000000000000000 M dir1/modified +:100644 100644 $EMPTY_BLOB $ZERO_OID M dir1/modified EOF test_expect_success 'status refreshes the index' ' touch dir2/added && diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh index 2ed6aaae35..015973e8fe 100755 --- a/t/t8002-blame.sh +++ b/t/t8002-blame.sh @@ -6,6 +6,10 @@ test_description='git blame' PROG='git blame -c' . "$TEST_DIRECTORY"/annotate-tests.sh +test_expect_success 'setup' ' + hexsz=$(test_oid hexsz) +' + test_expect_success 'blame untracked file in empty repo' ' >untracked && test_must_fail git blame untracked @@ -105,17 +109,17 @@ test_expect_success 'blame --abbrev=<n> works' ' ' test_expect_success 'blame -l aligns regular and boundary commits' ' - check_abbrev 40 -l HEAD && - check_abbrev 39 -l ^HEAD + check_abbrev $hexsz -l HEAD && + check_abbrev $((hexsz - 1)) -l ^HEAD ' -test_expect_success 'blame --abbrev=40 behaves like -l' ' - check_abbrev 40 --abbrev=40 HEAD && - check_abbrev 39 --abbrev=40 ^HEAD +test_expect_success 'blame --abbrev with full length behaves like -l' ' + check_abbrev $hexsz --abbrev=$hexsz HEAD && + check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD ' -test_expect_success '--no-abbrev works like --abbrev=40' ' - check_abbrev 40 --no-abbrev +test_expect_success '--no-abbrev works like --abbrev with full length' ' + check_abbrev $hexsz --no-abbrev ' test_expect_success '--exclude-promisor-objects does not BUG-crash' ' diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh index 9130b887d2..b871dd4f86 100755 --- a/t/t8003-blame-corner-cases.sh +++ b/t/t8003-blame-corner-cases.sh @@ -6,7 +6,6 @@ test_description='git blame corner cases' pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/' test_expect_success setup ' - echo A A A A A >one && echo B B B B B >two && echo C C C C C >tres && @@ -306,7 +305,7 @@ test_expect_success 'blame coalesce' ' $oid 1) ABC $oid 2) DEF EOF - git -c core.abbrev=40 blame -s giraffe >actual && + git -c core.abbrev=$(test_oid hexsz) blame -s giraffe >actual && test_cmp expect actual ' diff --git a/t/t8011-blame-split-file.sh b/t/t8011-blame-split-file.sh index 831125047b..bdda0c03fe 100755 --- a/t/t8011-blame-split-file.sh +++ b/t/t8011-blame-split-file.sh @@ -54,7 +54,7 @@ test_expect_success 'setup simulated porcelain' ' cat >read-porcelain.pl <<-\EOF my $field = shift; while (<>) { - if (/^[0-9a-f]{40} /) { + if (/^[0-9a-f]{40,} /) { flush(); $hash = $&; } elsif (/^$field (.*)/) { diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index e151df81c0..308c1ef42c 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -92,7 +92,7 @@ test_expect_success 'A: create pack from stdin' ' EOF reset refs/tags/to-be-deleted - from 0000000000000000000000000000000000000000 + from $ZERO_OID tag nested mark :6 @@ -102,7 +102,7 @@ test_expect_success 'A: create pack from stdin' ' EOF reset refs/tags/nested - from 0000000000000000000000000000000000000000 + from $ZERO_OID tag nested mark :7 @@ -284,8 +284,9 @@ test_expect_success 'A: verify pack' ' ' test_expect_success 'A: verify diff' ' + copy=$(git rev-parse --verify master:file2) && cat >expect <<-EOF && - :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2 + :000000 100755 $ZERO_OID $copy A copy-of-file2 EOF git diff-tree -M -r master verify--import-marks >actual && compare_diff_raw expect actual && @@ -364,7 +365,7 @@ test_expect_success 'B: fail on invalid blob sha1' ' COMMIT from refs/heads/master - M 755 0000000000000000000000000000000000000001 zero1 + M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1 INPUT_END @@ -528,6 +529,7 @@ test_expect_success 'B: fail on invalid committer (5)' ' test_expect_success 'C: incremental import create pack from stdin' ' newf=$(echo hi newf | git hash-object -w --stdin) && oldf=$(git rev-parse --verify master:file2) && + thrf=$(git rev-parse --verify master:file3) && test_tick && cat >input <<-INPUT_END && commit refs/heads/branch @@ -570,10 +572,11 @@ test_expect_success 'C: verify commit' ' ' test_expect_success 'C: validate rename result' ' + zero=$ZERO_OID && cat >expect <<-EOF && - :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf - :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf - :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3 + :000000 100755 $zero $newf A file2/newf + :100644 100644 $oldf $oldf R100 file2 file2/oldf + :100644 000000 $thrf $zero D file3 EOF git diff-tree -M -r master branch >actual && compare_diff_raw expect actual @@ -614,9 +617,11 @@ test_expect_success 'D: verify pack' ' ' test_expect_success 'D: validate new files added' ' + f5id=$(echo "$file5_data" | git hash-object --stdin) && + f6id=$(echo "$file6_data" | git hash-object --stdin) && cat >expect <<-EOF && - :000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A newdir/exec.sh - :000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A newdir/interesting + :000000 100755 $ZERO_OID $f6id A newdir/exec.sh + :000000 100644 $ZERO_OID $f5id A newdir/interesting EOF git diff-tree -M -r branch^ branch >actual && compare_diff_raw expect actual @@ -779,12 +784,13 @@ test_expect_success 'H: verify pack' ' ' test_expect_success 'H: validate old files removed, new files added' ' + f4id=$(git rev-parse HEAD:file4) && cat >expect <<-EOF && - :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf - :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf - :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4 - :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo - :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh + :100755 000000 $newf $zero D file2/newf + :100644 000000 $oldf $zero D file2/oldf + :100755 000000 $f4id $zero D file4 + :100644 100644 $f5id $f5id R100 newdir/interesting h/e/l/lo + :100755 000000 $f6id $zero D newdir/exec.sh EOF git diff-tree -M -r H^ H >actual && compare_diff_raw expect actual @@ -935,14 +941,15 @@ test_expect_success 'L: verify internal tree sorting' ' INPUT_END cat >expect <<-EXPECT_END && - :100644 100644 4268632... 55d3a52... M b. - :040000 040000 0ae5cac... 443c768... M b - :100644 100644 4268632... 55d3a52... M ba + :100644 100644 M b. + :040000 040000 M b + :100644 100644 M ba EXPECT_END git fast-import <input && GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output && - test_cmp expect output + cut -d" " -f1,2,5 output >actual && + test_cmp expect actual ' test_expect_success 'L: nested tree copy does not corrupt deltas' ' @@ -1004,7 +1011,7 @@ test_expect_success 'M: rename file in same subdirectory' ' INPUT_END cat >expect <<-EOF && - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f + :100755 100755 $newf $newf R100 file2/newf file2/n.e.w.f EOF git fast-import <input && git diff-tree -M -r M1^ M1 >actual && @@ -1025,7 +1032,7 @@ test_expect_success 'M: rename file to new subdirectory' ' INPUT_END cat >expect <<-EOF && - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you + :100755 100755 $newf $newf R100 file2/newf i/am/new/to/you EOF git fast-import <input && git diff-tree -M -r M2^ M2 >actual && @@ -1046,7 +1053,7 @@ test_expect_success 'M: rename subdirectory to new subdirectory' ' INPUT_END cat >expect <<-EOF && - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you + :100755 100755 $newf $newf R100 i/am/new/to/you other/sub/am/new/to/you EOF git fast-import <input && git diff-tree -M -r M3^ M3 >actual && @@ -1067,11 +1074,11 @@ test_expect_success 'M: rename root to subdirectory' ' INPUT_END cat >expect <<-EOF && - :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf - :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4 - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you - :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh - :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting + :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf + :100755 100755 $f4id $f4id R100 file4 sub/file4 + :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you + :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh + :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting EOF git fast-import <input && git diff-tree -M -r M4^ M4 >actual && @@ -1097,7 +1104,7 @@ test_expect_success 'N: copy file in same subdirectory' ' INPUT_END cat >expect <<-EOF && - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f + :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f EOF git fast-import <input && git diff-tree -C --find-copies-harder -r N1^ N1 >actual && @@ -1129,9 +1136,9 @@ test_expect_success 'N: copy then modify subdirectory' ' INPUT_END cat >expect <<-EOF && - :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5 - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf - :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf + :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5 + :100755 100755 $newf $newf C100 file2/newf file3/newf + :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf EOF git fast-import <input && git diff-tree -C --find-copies-harder -r N2^^ N2 >actual && @@ -1162,9 +1169,9 @@ test_expect_success 'N: copy dirty subdirectory' ' ' test_expect_success 'N: copy directory by id' ' - cat >expect <<-\EOF && - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf - :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf + cat >expect <<-EOF && + :100755 100755 $newf $newf C100 file2/newf file3/newf + :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf EOF subdir=$(git rev-parse refs/heads/branch^0:file2) && cat >input <<-INPUT_END && @@ -1183,9 +1190,9 @@ test_expect_success 'N: copy directory by id' ' ' test_expect_success PIPE 'N: read and copy directory' ' - cat >expect <<-\EOF && - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf - :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf + cat >expect <<-EOF && + :100755 100755 $newf $newf C100 file2/newf file3/newf + :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf EOF git update-ref -d refs/heads/N4 && rm -f backflow && @@ -1254,9 +1261,9 @@ test_expect_success PIPE 'N: empty directory reads as missing' ' ' test_expect_success 'N: copy root directory by tree hash' ' - cat >expect <<-\EOF && - :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf - :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf + cat >expect <<-EOF && + :100755 000000 $newf $zero D file3/newf + :100644 000000 $oldf $zero D file3/oldf EOF root=$(git rev-parse refs/heads/branch^0^{tree}) && cat >input <<-INPUT_END && @@ -1275,12 +1282,12 @@ test_expect_success 'N: copy root directory by tree hash' ' ' test_expect_success 'N: copy root by path' ' - cat >expect <<-\EOF && - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf - :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf - :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4 - :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh - :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting + cat >expect <<-EOF && + :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf + :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf + :100755 100755 $f4id $f4id C100 file4 oldroot/file4 + :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh + :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting EOF cat >input <<-INPUT_END && commit refs/heads/N-copy-root-path @@ -1340,10 +1347,10 @@ test_expect_success 'N: delete directory by copying' ' ' test_expect_success 'N: modify copied tree' ' - cat >expect <<-\EOF && - :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5 - :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf - :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf + cat >expect <<-EOF && + :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5 + :100755 100755 $newf $newf C100 file2/newf file3/newf + :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf EOF subdir=$(git rev-parse refs/heads/branch^0:file2) && cat >input <<-INPUT_END && @@ -2726,7 +2733,7 @@ test_expect_success 'R: corrupt lines do not mess marks file' ' rm -f io.marks && blob=$(echo hi | git hash-object --stdin) && cat >expect <<-EOF && - :3 0000000000000000000000000000000000000000 + :3 $ZERO_OID :1 $blob :2 $blob EOF @@ -3077,7 +3084,7 @@ test_expect_success 'T: delete branch' ' git branch to-delete && git fast-import <<-EOF && reset refs/heads/to-delete - from 0000000000000000000000000000000000000000 + from $ZERO_OID EOF test_must_fail git rev-parse --verify refs/heads/to-delete ' @@ -3117,6 +3124,9 @@ test_expect_success 'U: initialize for U tests' ' INPUT_END + f7id=$(echo "blob 1" | git hash-object --stdin) && + f8id=$(echo "sleep well" | git hash-object --stdin) && + f9id=$(echo "au revoir" | git hash-object --stdin) && git fast-import <input ' @@ -3137,7 +3147,7 @@ test_expect_success 'U: filedelete file succeeds' ' test_expect_success 'U: validate file delete result' ' cat >expect <<-EOF && - :100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt + :100644 000000 $f8id $ZERO_OID D good/night.txt EOF git diff-tree -M -r U^1 U >actual && @@ -3162,7 +3172,7 @@ test_expect_success 'U: filedelete directory succeeds' ' test_expect_success 'U: validate directory delete result' ' cat >expect <<-EOF && - :100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt + :100644 000000 $f9id $ZERO_OID D good/bye.txt EOF git diff-tree -M -r U^1 U >actual && @@ -3187,7 +3197,7 @@ test_expect_success 'U: filedelete root succeeds' ' test_expect_success 'U: validate root delete result' ' cat >expect <<-EOF && - :100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c + :100644 000000 $f7id $ZERO_OID D hello.c EOF git diff-tree -M -r U^1 U >actual && diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh index ca223dca98..14c1baa739 100755 --- a/t/t9301-fast-import-notes.sh +++ b/t/t9301-fast-import-notes.sh @@ -470,12 +470,13 @@ test_expect_success 'add lots of commits and notes' ' ' test_expect_success 'verify that lots of notes trigger a fanout scheme' ' + hexsz=$(test_oid hexsz) && # None of the entries in the top-level notes tree should be a full SHA1 git ls-tree --name-only refs/notes/many_notes | while read path do - if test $(expr length "$path") -ge 40 + if test $(expr length "$path") -ge $hexsz then return 1 fi @@ -518,7 +519,7 @@ test_expect_success 'verify that importing a notes tree respects the fanout sche git ls-tree --name-only refs/notes/other_notes | while read path do - if test $(expr length "$path") -ge 40 + if test $(expr length "$path") -ge $hexsz then return 1 fi @@ -593,7 +594,7 @@ test_expect_success 'verify that changing notes respect existing fanout' ' git ls-tree --name-only refs/notes/many_notes | while read path do - if test $(expr length "$path") -ge 40 + if test $(expr length "$path") -ge $hexsz then return 1 fi @@ -616,7 +617,7 @@ i=$(($num_commits - $remaining_notes)) for sha1 in $(git rev-list -n $i refs/heads/many_commits) do cat >>input <<INPUT_END -N 0000000000000000000000000000000000000000 $sha1 +N $ZERO_OID $sha1 INPUT_END done @@ -646,7 +647,6 @@ test_expect_success 'remove lots of notes' ' ' test_expect_success 'verify that removing notes trigger fanout consolidation' ' - # All entries in the top-level notes tree should be a full SHA1 git ls-tree --name-only -r refs/notes/many_notes | while read path @@ -656,7 +656,7 @@ test_expect_success 'verify that removing notes trigger fanout consolidation' ' test "$path" = "deadbeef" && continue test "$path" = "de/adbeef" && continue - if test $(expr length "$path") -ne 40 + if test $(expr length "$path") -ne $hexsz then return 1 fi diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 690c90fb82..1372842559 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -132,12 +132,12 @@ test_expect_success 'reencoding iso-8859-7' ' sed "s/wer/i18n/" iso-8859-7.fi | (cd new && git fast-import && - # The commit object, if not re-encoded, would be 240 bytes. + # The commit object, if not re-encoded, would be 200 bytes plus hash. # Removing the "encoding iso-8859-7\n" header drops 20 bytes. # Re-encoding the Pi character from \xF0 (\360) in iso-8859-7 # to \xCF\x80 (\317\200) in UTF-8 adds a byte. Check for # the expected size. - test 221 -eq "$(git cat-file -s i18n)" && + test $(($(test_oid hexsz) + 181)) -eq "$(git cat-file -s i18n)" && # ...and for the expected translation of bytes. git cat-file commit i18n >actual && grep $(printf "\317\200") actual && @@ -164,12 +164,12 @@ test_expect_success 'preserving iso-8859-7' ' sed "s/wer/i18n-no-recoding/" iso-8859-7.fi | (cd new && git fast-import && - # The commit object, if not re-encoded, is 240 bytes. + # The commit object, if not re-encoded, is 200 bytes plus hash. # Removing the "encoding iso-8859-7\n" header would drops 20 # bytes. Re-encoding the Pi character from \xF0 (\360) in # iso-8859-7 to \xCF\x80 (\317\200) in UTF-8 adds a byte. # Check for the expected size... - test 240 -eq "$(git cat-file -s i18n-no-recoding)" && + test $(($(test_oid hexsz) + 200)) -eq "$(git cat-file -s i18n-no-recoding)" && # ...as well as the expected byte. git cat-file commit i18n-no-recoding >actual && grep $(printf "\360") actual && @@ -192,7 +192,7 @@ test_expect_success 'encoding preserved if reencoding fails' ' grep ^encoding actual && # Verify that the commit has the expected size; i.e. # that no bytes were re-encoded to a different encoding. - test 252 -eq "$(git cat-file -s i18n-invalid)" && + test $(($(test_oid hexsz) + 212)) -eq "$(git cat-file -s i18n-invalid)" && # ...and check for the original special bytes grep $(printf "\360") actual && grep $(printf "\377") actual) @@ -694,7 +694,7 @@ test_expect_success 'delete ref because entire history excluded' ' git fast-export to-delete ^to-delete >actual && cat >expected <<-EOF && reset refs/heads/to-delete - from 0000000000000000000000000000000000000000 + from $ZERO_OID EOF test_cmp expected actual @@ -704,7 +704,7 @@ test_expect_success 'delete refspec' ' git fast-export --refspec :refs/heads/to-delete >actual && cat >expected <<-EOF && reset refs/heads/to-delete - from 0000000000000000000000000000000000000000 + from $ZERO_OID EOF test_cmp expected actual diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh index 267ddc997d..b484e3e250 100755 --- a/t/t9500-gitweb-standalone-no-errors.sh +++ b/t/t9500-gitweb-standalone-no-errors.sh @@ -621,12 +621,22 @@ test_expect_success \ git config gitweb.snapshot "zip,tgz, tbz2" && gitweb_run "p=.git;a=tree"' -cat >.git/config <<\EOF -# testing noval and alternate separator -[gitweb] - blame - snapshot = zip tgz -EOF +test_expect_success 'setup' ' + version=$(git config core.repositoryformatversion) && + algo=$(test_might_fail git config extensions.objectformat) && + cat >.git/config <<-\EOF && + # testing noval and alternate separator + [gitweb] + blame + snapshot = zip tgz + EOF + git config core.repositoryformatversion "$version" && + if test -n "$algo" + then + git config extensions.objectformat "$algo" + fi +' + test_expect_success \ 'config override: tree view, features enabled in repo config (2)' \ 'gitweb_run "p=.git;a=tree"' diff --git a/t/t9700/test.pl b/t/t9700/test.pl index c59a015f89..e046f7db76 100755 --- a/t/t9700/test.pl +++ b/t/t9700/test.pl @@ -23,6 +23,8 @@ sub adjust_dirsep { return $path; } +my $oid_re = qr/^[0-9a-fA-F]{40}(?:[0-9a-fA-F]{24})?$/; + BEGIN { use_ok('Git') } # set up @@ -93,7 +95,7 @@ is(Git::hash_object("blob", $tmpfile), $file1hash, "hash_object: roundtrip"); open TEMPFILE, ">$tmpfile" or die "Can't open $tmpfile: $!"; print TEMPFILE my $test_text = "test blob, to be inserted\n"; close TEMPFILE or die "Failed writing to $tmpfile: $!"; -like(our $newhash = $r->hash_and_insert_object($tmpfile), qr/[0-9a-fA-F]{40}/, +like(our $newhash = $r->hash_and_insert_object($tmpfile), $oid_re, "hash_and_insert_object: returns hash"); open TEMPFILE, "+>$tmpfile" or die "Can't open $tmpfile: $!"; is($r->cat_blob($newhash, \*TEMPFILE), length $test_text, "cat_blob: roundtrip size"); @@ -119,7 +121,7 @@ is($r2->wc_subdir, "directory2/", "wc_subdir initial (2)"); # commands in sub directory my $last_commit = $r2->command_oneline(qw(rev-parse --verify HEAD)); -like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash'); +like($last_commit, $oid_re, 'rev-parse returned hash'); my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.'); isnt($last_commit, $dir_commit, 'log . does not show last commit'); diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index b791933ffd..596c549cdd 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1464,9 +1464,7 @@ test_set_hash () { # Detect the hash algorithm in use. test_detect_hash () { - # Currently we only support SHA-1, but in the future this function will - # actually detect the algorithm in use. - test_hash_algo='sha1' + test_hash_algo="${GIT_TEST_DEFAULT_HASH:-sha1}" } # Load common hash metadata and common placeholder object IDs for use with @@ -1515,7 +1513,17 @@ test_oid_cache () { # Look up a per-hash value based on a key ($1). The value must have been loaded # by test_oid_init or test_oid_cache. test_oid () { - local var="test_oid_${test_hash_algo}_$1" && + local algo="${test_hash_algo}" && + + case "$1" in + --hash=*) + algo="${1#--hash=}" && + shift;; + *) + ;; + esac && + + local var="test_oid_${algo}_$1" && # If the variable is unset, we must be missing an entry for this # key-hash pair, so exit with an error. diff --git a/t/test-lib.sh b/t/test-lib.sh index ba224c86f5..ef31f40037 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -455,6 +455,9 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export GIT_COMMITTER_DATE GIT_AUTHOR_DATE export EDITOR +GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-sha1}" +export GIT_DEFAULT_HASH + # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output GIT_TRACE_BARE=1 export GIT_TRACE_BARE @@ -1689,7 +1692,11 @@ test_lazy_prereq CURL ' # which will not work with other hash algorithms and tests that work but don't # test anything meaningful (e.g. special values which cause short collisions). test_lazy_prereq SHA1 ' - test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 + case "$GIT_DEFAULT_HASH" in + sha1) true ;; + "") test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 ;; + *) false ;; + esac ' test_lazy_prereq REBASE_P ' |