summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Makefile26
-rw-r--r--t/README33
-rwxr-xr-xt/aggregate-results.sh2
-rw-r--r--t/for-each-ref-tests.sh2141
-rw-r--r--t/helper/meson.build8
-rw-r--r--t/helper/test-advise.c3
-rw-r--r--t/helper/test-bitmap.c8
-rw-r--r--t/helper/test-bloom.c10
-rw-r--r--t/helper/test-config.c20
-rw-r--r--t/helper/test-csprng.c2
-rw-r--r--t/helper/test-date.c2
-rw-r--r--t/helper/test-delta.c77
-rw-r--r--t/helper/test-dir-iterator.c1
-rw-r--r--t/helper/test-find-pack.c4
-rw-r--r--t/helper/test-getcwd.c2
-rw-r--r--t/helper/test-hash-speed.c8
-rw-r--r--t/helper/test-hash.c10
-rw-r--r--t/helper/test-hashmap.c9
-rw-r--r--t/helper/test-json-writer.c4
-rw-r--r--t/helper/test-name-hash.c23
-rw-r--r--t/helper/test-pack-deltas.c148
-rw-r--r--t/helper/test-pack-mtimes.c4
-rw-r--r--t/helper/test-parse-options.c67
-rw-r--r--t/helper/test-partial-clone.c4
-rw-r--r--t/helper/test-path-utils.c35
-rw-r--r--t/helper/test-path-walk.c134
-rw-r--r--t/helper/test-proc-receive.c2
-rw-r--r--t/helper/test-progress.c6
-rw-r--r--t/helper/test-reach.c6
-rw-r--r--t/helper/test-read-cache.c3
-rw-r--r--t/helper/test-read-graph.c8
-rw-r--r--t/helper/test-read-midx.c33
-rw-r--r--t/helper/test-ref-store.c18
-rw-r--r--t/helper/test-reftable.c81
-rw-r--r--t/helper/test-rot13-filter.c4
-rw-r--r--t/helper/test-serve-v2.c7
-rw-r--r--t/helper/test-sha1.c7
-rwxr-xr-xt/helper/test-sha1.sh40
-rw-r--r--t/helper/test-sha256.c2
-rw-r--r--t/helper/test-simple-ipc.c4
-rw-r--r--t/helper/test-string-list.c96
-rw-r--r--t/helper/test-submodule-nested-repo-config.c2
-rw-r--r--t/helper/test-submodule.c10
-rw-r--r--t/helper/test-tool.c5
-rw-r--r--t/helper/test-tool.h7
-rw-r--r--t/helper/test-truncate.c3
-rw-r--r--t/helper/test-userdiff.c2
-rw-r--r--t/helper/test-windows-named-pipe.c2
-rw-r--r--t/helper/test-zlib.c62
-rw-r--r--t/interop/Makefile5
-rw-r--r--t/lib-credential.sh15
-rw-r--r--t/lib-diff.sh4
-rw-r--r--t/lib-gettext.sh2
-rw-r--r--t/lib-gpg.sh6
-rw-r--r--t/lib-httpd.sh2
-rw-r--r--t/lib-httpd/apache.conf6
-rw-r--r--t/lib-httpd/apply-one-time-perl.sh27
-rw-r--r--t/lib-httpd/apply-one-time-script.sh26
-rw-r--r--t/lib-loose.sh30
-rw-r--r--t/lib-merge.sh13
-rw-r--r--t/lib-t6000.sh13
-rw-r--r--t/meson.build172
-rw-r--r--t/perf/Makefile5
-rwxr-xr-xt/perf/aggregate.perl2
-rwxr-xr-xt/perf/p1501-rev-parse-oneline.sh71
-rwxr-xr-xt/perf/p2000-sparse-operations.sh3
-rwxr-xr-xt/perf/p5313-pack-objects.sh74
-rwxr-xr-xt/perf/p5314-name-hash.sh28
-rwxr-xr-xt/perf/p5332-multi-pack-reuse.sh2
-rwxr-xr-xt/perf/p7821-grep-engines-fixed.sh6
-rwxr-xr-xt/perf/p8020-last-modified.sh22
-rwxr-xr-xt/perf/p9210-scalar.sh3
-rw-r--r--t/perf/perf-lib.sh46
-rwxr-xr-xt/perf/run4
-rw-r--r--t/show-ref-exists-tests.sh77
-rwxr-xr-xt/t0000-basic.sh39
-rwxr-xr-xt/t0001-init.sh83
-rwxr-xr-xt/t0008-ignores.sh4
-rwxr-xr-xt/t0012-help.sh3
-rwxr-xr-xt/t0021-conversion.sh17
-rwxr-xr-xt/t0040-parse-options.sh93
-rwxr-xr-xt/t0050-filesystem.sh30
-rwxr-xr-xt/t0060-path-utils.sh10
-rwxr-xr-xt/t0063-string-list.sh142
-rwxr-xr-xt/t0090-cache-tree.sh4
-rwxr-xr-xt/t0091-bugreport.sh3
-rwxr-xr-xt/t0210-trace2-normal.sh64
-rw-r--r--t/t0210/scrub_normal.perl54
-rwxr-xr-xt/t0211-trace2-perf.sh6
-rwxr-xr-xt/t0411-clone-from-partial.sh6
-rwxr-xr-xt/t0450-txt-doc-vs-help.sh61
-rw-r--r--t/t0450/adoc-help-mismatches (renamed from t/t0450/txt-help-mismatches)3
-rw-r--r--t/t0450/adoc-missing9
-rwxr-xr-xt/t0602-reffiles-fsck.sh1243
-rwxr-xr-xt/t0610-reftable-basics.sh18
-rwxr-xr-xt/t0612-reftable-jgit-compatibility.sh13
-rwxr-xr-xt/t0613-reftable-write-options.sh35
-rwxr-xr-xt/t1001-read-tree-m-2way.sh2
-rwxr-xr-xt/t1006-cat-file.sh488
-rwxr-xr-xt/t1007-hash-object.sh23
-rwxr-xr-xt/t1010-mktree.sh4
-rwxr-xr-xt/t1021-rerere-in-workdir.sh58
-rwxr-xr-xt/t1050-large.sh3
-rwxr-xr-xt/t1092-sparse-checkout-compatibility.sh166
-rwxr-xr-xt/t1400-update-ref.sh337
-rwxr-xr-xt/t1403-show-ref.sh67
-rwxr-xr-xt/t1408-packed-refs.sh15
-rwxr-xr-xt/t1410-reflog.sh154
-rwxr-xr-xt/t1416-ref-transaction-hooks.sh2
-rwxr-xr-xt/t1419-exclude-refs.sh26
-rwxr-xr-xt/t1421-reflog-write.sh126
-rwxr-xr-xt/t1422-show-ref-exists.sh9
-rwxr-xr-xt/t1450-fsck.sh38
-rwxr-xr-xt/t1460-refs-migrate.sh77
-rwxr-xr-xt/t1461-refs-list.sh8
-rwxr-xr-xt/t1462-refs-exists.sh10
-rwxr-xr-xt/t1512-rev-parse-disambiguation.sh5
-rwxr-xr-xt/t1517-outside-repo.sh42
-rwxr-xr-xt/t1900-repo.sh113
-rwxr-xr-xt/t2006-checkout-index-basic.sh7
-rwxr-xr-xt/t2400-worktree-add.sh20
-rwxr-xr-xt/t2501-cwd-empty.sh2
-rwxr-xr-xt/t3000-ls-files-others.sh19
-rwxr-xr-xt/t3004-ls-files-basic.sh7
-rwxr-xr-xt/t3200-branch.sh14
-rwxr-xr-xt/t3203-branch-output.sh28
-rwxr-xr-xt/t3300-funny-names.sh6
-rwxr-xr-xt/t3404-rebase-interactive.sh69
-rwxr-xr-xt/t3415-rebase-autosquash.sh24
-rwxr-xr-xt/t3418-rebase-continue.sh13
-rwxr-xr-xt/t3430-rebase-merges.sh41
-rwxr-xr-xt/t3512-cherry-pick-submodule.sh5
-rwxr-xr-xt/t3513-revert-submodule.sh4
-rwxr-xr-xt/t3600-rm.sh5
-rwxr-xr-xt/t3650-replay-basics.sh22
-rwxr-xr-xt/t3701-add-interactive.sh119
-rwxr-xr-xt/t3903-stash.sh173
-rwxr-xr-xt/t4000-diff-format.sh2
-rwxr-xr-xt/t4013-diff-various.sh46
-rwxr-xr-xt/t4014-format-patch.sh30
-rwxr-xr-xt/t4015-diff-whitespace.sh8
-rw-r--r--t/t4018/bash-bashism-style-complete-line-capture4
-rw-r--r--t/t4018/bash-posix-style-complete-line-capture4
-rw-r--r--t/t4018/bash-posix-style-single-command-function3
-rw-r--r--t/t4018/ini-section5
-rw-r--r--t/t4018/ini-section-noindent5
-rw-r--r--t/t4018/ini-section-same-line4
-rw-r--r--t/t4018/ini-subsection12
-rw-r--r--t/t4018/ini-subsection-noindent12
-rw-r--r--t/t4018/r-indent6
-rw-r--r--t/t4018/r-indent-nested10
-rw-r--r--t/t4018/r-noindent6
-rwxr-xr-xt/t4020-diff-external.sh2
-rwxr-xr-xt/t4029-diff-trailing-space.sh3
-rwxr-xr-xt/t4030-diff-textconv.sh9
-rwxr-xr-xt/t4031-diff-rewrite-binary.sh17
-rwxr-xr-xt/t4034-diff-words.sh1
-rw-r--r--t/t4034/bash/expect36
-rw-r--r--t/t4034/bash/post31
-rw-r--r--t/t4034/bash/pre31
-rwxr-xr-xt/t4041-diff-submodule-option.sh22
-rwxr-xr-xt/t4042-diff-textconv-caching.sh12
-rwxr-xr-xt/t4053-diff-no-index.sh92
-rwxr-xr-xt/t4055-diff-context.sh46
-rwxr-xr-xt/t4058-diff-duplicates.sh6
-rwxr-xr-xt/t4060-diff-submodule-option-diff-format.sh9
-rwxr-xr-xt/t4069-remerge-diff.sh7
-rwxr-xr-xt/t4070-diff-pairs.sh90
-rwxr-xr-xt/t4071-diff-minimal.sh14
-rwxr-xr-xt/t4072-diff-max-depth.sh116
-rwxr-xr-xt/t4100-apply-stat.sh13
-rwxr-xr-xt/t4103-apply-binary.sh6
-rwxr-xr-xt/t4116-apply-reverse.sh4
-rwxr-xr-xt/t4129-apply-samemode.sh231
-rwxr-xr-xt/t4140-apply-ita.sh31
-rwxr-xr-xt/t4150-am.sh10
-rwxr-xr-xt/t4151-am-abort.sh2
-rwxr-xr-xt/t4200-rerere.sh8
-rwxr-xr-xt/t4202-log.sh40
-rwxr-xr-xt/t4203-mailmap.sh45
-rwxr-xr-xt/t4205-log-pretty-formats.sh6
-rwxr-xr-xt/t4206-log-follow-harder-copies.sh32
-rwxr-xr-xt/t4209-log-pickaxe.sh16
-rwxr-xr-xt/t4216-log-bloom.sh54
-rwxr-xr-xt/t4255-am-submodule.sh1
-rw-r--r--t/t4256/1/mailinfo.c2
-rw-r--r--t/t4256/1/mailinfo.c.orig2
-rwxr-xr-xt/t4301-merge-tree-write-tree.sh51
-rwxr-xr-xt/t5004-archive-corner-cases.sh11
-rwxr-xr-xt/t5150-request-pull.sh6
-rwxr-xr-xt/t5200-update-server-info.sh5
-rwxr-xr-xt/t5300-pack-object.sh69
-rwxr-xr-xt/t5303-pack-corruption-resilience.sh6
-rwxr-xr-xt/t5304-prune.sh5
-rwxr-xr-xt/t5306-pack-nobase.sh5
-rwxr-xr-xt/t5309-pack-delta-cycles.sh34
-rwxr-xr-xt/t5310-pack-bitmaps.sh80
-rwxr-xr-xt/t5316-pack-delta-depth.sh19
-rwxr-xr-xt/t5318-commit-graph.sh12
-rwxr-xr-xt/t5319-multi-pack-index.sh46
-rwxr-xr-xt/t5323-pack-redundant.sh11
-rwxr-xr-xt/t5324-split-commit-graph.sh2
-rwxr-xr-xt/t5326-multi-pack-bitmaps.sh4
-rwxr-xr-xt/t5328-commit-graph-64bit-time.sh2
-rwxr-xr-xt/t5329-pack-objects-cruft.sh302
-rwxr-xr-xt/t5331-pack-objects-stdin.sh122
-rwxr-xr-xt/t5332-multi-pack-reuse.sh7
-rwxr-xr-xt/t5333-pseudo-merge-bitmaps.sh34
-rwxr-xr-xt/t5334-incremental-multi-pack-index.sh87
-rwxr-xr-xt/t5400-send-pack.sh9
-rwxr-xr-xt/t5401-update-hooks.sh16
-rwxr-xr-xt/t5408-send-pack-stdin.sh15
-rwxr-xr-xt/t5410-receive-pack-alternates.sh44
-rwxr-xr-xt/t5410-receive-pack.sh100
-rwxr-xr-xt/t5503-tagfollow.sh20
-rwxr-xr-xt/t5504-fetch-receive-strict.sh47
-rwxr-xr-xt/t5505-remote.sh105
-rwxr-xr-xt/t5510-fetch.sh570
-rwxr-xr-xt/t5515-fetch-merge-logic.sh47
-rwxr-xr-xt/t5516-fetch-push.sh107
-rwxr-xr-xt/t5520-pull.sh62
-rwxr-xr-xt/t5530-upload-pack-error.sh68
-rwxr-xr-xt/t5532-fetch-proxy.sh6
-rwxr-xr-xt/t5534-push-signed.sh2
-rwxr-xr-xt/t5537-fetch-shallow.sh15
-rwxr-xr-xt/t5538-push-shallow.sh41
-rwxr-xr-xt/t5540-http-push-webdav.sh10
-rwxr-xr-xt/t5543-atomic-push.sh30
-rwxr-xr-xt/t5548-push-porcelain.sh443
-rwxr-xr-xt/t5551-http-fetch-smart.sh7
-rwxr-xr-xt/t5558-clone-bundle-uri.sh202
-rwxr-xr-xt/t5562-http-backend-content-length.sh6
-rwxr-xr-xt/t5572-pull-submodule.sh5
-rwxr-xr-xt/t5601-clone.sh4
-rwxr-xr-xt/t5605-clone-local.sh5
-rwxr-xr-xt/t5607-clone-bundle.sh12
-rwxr-xr-xt/t5616-partial-clone.sh46
-rwxr-xr-xt/t5620-backfill.sh211
-rwxr-xr-xt/t5621-clone-revision.sh122
-rwxr-xr-xt/t5701-git-serve.sh31
-rwxr-xr-xt/t5702-protocol-v2.sh65
-rwxr-xr-xt/t5703-upload-pack-ref-in-want.sh29
-rwxr-xr-xt/t5710-promisor-remote-capability.sh379
-rwxr-xr-xt/t6000-rev-list-misc.sh66
-rwxr-xr-xt/t6011-rev-list-with-bad-commit.sh15
-rwxr-xr-xt/t6012-rev-list-simplify.sh2
-rwxr-xr-xt/t6013-rev-list-reverse-parents.sh10
-rwxr-xr-xt/t6020-bundle-misc.sh59
-rwxr-xr-xt/t6022-rev-list-missing.sh84
-rwxr-xr-xt/t6102-rev-list-unexpected-objects.sh6
-rwxr-xr-xt/t6115-rev-list-du.sh2
-rwxr-xr-xt/t6120-describe.sh72
-rwxr-xr-xt/t6137-pathspec-wildcards-literal.sh429
-rwxr-xr-xt/t6300-for-each-ref.sh2136
-rwxr-xr-xt/t6302-for-each-ref-filter.sh213
-rwxr-xr-xt/t6400-merge-df.sh14
-rwxr-xr-xt/t6402-merge-rename.sh125
-rwxr-xr-xt/t6404-recursive-merge.sh21
-rwxr-xr-xt/t6406-merge-attr.sh7
-rwxr-xr-xt/t6416-recursive-corner-cases.sh194
-rwxr-xr-xt/t6421-merge-partial-clone.sh7
-rwxr-xr-xt/t6422-merge-rename-corner-cases.sh41
-rwxr-xr-xt/t6423-merge-rename-directories.sh1090
-rwxr-xr-xt/t6424-merge-unrelated-index-changes.sh8
-rwxr-xr-xt/t6426-merge-skip-unneeded-updates.sh4
-rwxr-xr-xt/t6427-diff3-conflict-markers.sh2
-rwxr-xr-xt/t6428-merge-conflicts-sparse.sh2
-rwxr-xr-xt/t6430-merge-recursive.sh46
-rwxr-xr-xt/t6434-merge-recursive-rename-options.sh18
-rwxr-xr-xt/t6436-merge-overwrite.sh17
-rwxr-xr-xt/t6437-submodule-merge.sh65
-rwxr-xr-xt/t6438-submodule-directory-file-conflicts.sh5
-rwxr-xr-xt/t6439-merge-co-error-msgs.sh2
-rwxr-xr-xt/t6500-gc.sh33
-rwxr-xr-xt/t6600-test-reach.sh29
-rwxr-xr-xt/t6601-path-walk.sh418
-rwxr-xr-xt/t7001-mv.sh24
-rwxr-xr-xt/t7005-editor.sh145
-rwxr-xr-xt/t7006-pager.sh6
-rwxr-xr-xt/t7007-show.sh24
-rwxr-xr-xt/t7030-verify-tag.sh7
-rwxr-xr-xt/t7110-reset-merge.sh12
-rwxr-xr-xt/t7400-submodule-basic.sh23
-rwxr-xr-xt/t7401-submodule-summary.sh18
-rwxr-xr-xt/t7402-submodule-rebase.sh7
-rwxr-xr-xt/t7406-submodule-update.sh68
-rwxr-xr-xt/t7407-submodule-foreach.sh4
-rwxr-xr-xt/t7413-submodule-is-active.sh15
-rwxr-xr-xt/t7416-submodule-dash-url.sh3
-rwxr-xr-xt/t7422-submodule-output.sh40
-rwxr-xr-xt/t7450-bad-git-dotfiles.sh2
-rwxr-xr-xt/t7501-commit-basic-functionality.sh6
-rwxr-xr-xt/t7508-status.sh2
-rwxr-xr-xt/t7510-signed-commit.sh19
-rwxr-xr-xt/t7512-status-help.sh86
-rwxr-xr-xt/t7528-signed-commit-ssh.sh32
-rwxr-xr-xt/t7600-merge.sh76
-rwxr-xr-xt/t7602-merge-octopus-many.sh9
-rwxr-xr-xt/t7603-merge-reduce-heads.sh24
-rwxr-xr-xt/t7609-mergetool--lib.sh2
-rwxr-xr-xt/t7610-mergetool.sh40
-rwxr-xr-xt/t7615-diff-algo-with-mergy-operations.sh6
-rwxr-xr-xt/t7700-repack.sh79
-rwxr-xr-xt/t7701-repack-unpack-unreachable.sh16
-rwxr-xr-xt/t7704-repack-cruft.sh494
-rwxr-xr-xt/t7815-grep-binary.sh11
-rwxr-xr-xt/t7900-maintenance.sh180
-rwxr-xr-xt/t8001-annotate.sh6
-rwxr-xr-xt/t8002-blame.sh12
-rwxr-xr-xt/t8006-blame-textconv.sh2
-rwxr-xr-xt/t8011-blame-split-file.sh6
-rwxr-xr-xt/t8012-blame-colors.sh6
-rwxr-xr-xt/t8013-blame-ignore-revs.sh38
-rwxr-xr-xt/t8020-last-modified.sh210
-rwxr-xr-xt/t9001-send-email.sh7
-rwxr-xr-xt/t9003-help-autocorrect.sh17
-rwxr-xr-xt/t9137-git-svn-dcommit-clobber-series.sh10
-rwxr-xr-xt/t9210-scalar.sh26
-rwxr-xr-xt/t9211-scalar-clone.sh11
-rwxr-xr-xt/t9300-fast-import.sh12
-rwxr-xr-xt/t9301-fast-import-notes.sh2
-rwxr-xr-xt/t9350-fast-export.sh309
-rwxr-xr-xt/t9500-gitweb-standalone-no-errors.sh16
-rwxr-xr-xt/t9811-git-p4-label-import.sh8
-rwxr-xr-xt/t9822-git-p4-path-encoding.sh13
-rwxr-xr-xt/t9835-git-p4-metadata-encoding-python2.sh24
-rwxr-xr-xt/t9836-git-p4-metadata-encoding-python3.sh24
-rwxr-xr-xt/t9850-shell.sh2
-rwxr-xr-xt/t9902-completion.sh208
-rwxr-xr-xt/t9903-bash-prompt.sh4
-rw-r--r--t/test-lib-functions.sh92
-rw-r--r--t/test-lib.sh111
-rw-r--r--t/unit-tests/clar/clar.c2
-rw-r--r--t/unit-tests/clar/clar/fs.h10
-rwxr-xr-xt/unit-tests/generate-clar-decls.sh1
-rw-r--r--t/unit-tests/lib-oid.c32
-rw-r--r--t/unit-tests/lib-oid.h9
-rw-r--r--t/unit-tests/lib-reftable.c35
-rw-r--r--t/unit-tests/lib-reftable.h15
-rw-r--r--t/unit-tests/t-example-decorate.c74
-rw-r--r--t/unit-tests/t-mem-pool.c31
-rw-r--r--t/unit-tests/t-oid-array.c126
-rw-r--r--t/unit-tests/t-oidmap.c181
-rw-r--r--t/unit-tests/t-oidtree.c122
-rw-r--r--t/unit-tests/t-prio-queue.c91
-rw-r--r--t/unit-tests/t-reftable-basics.c201
-rw-r--r--t/unit-tests/t-reftable-block.c383
-rw-r--r--t/unit-tests/t-reftable-reader.c96
-rw-r--r--t/unit-tests/t-strbuf.c122
-rw-r--r--t/unit-tests/t-strcmp-offset.c35
-rw-r--r--t/unit-tests/t-trailer.c317
-rw-r--r--t/unit-tests/u-dir.c47
-rw-r--r--t/unit-tests/u-example-decorate.c64
-rw-r--r--t/unit-tests/u-hash.c (renamed from t/unit-tests/t-hash.c)77
-rw-r--r--t/unit-tests/u-hashmap.c (renamed from t/unit-tests/t-hashmap.c)226
-rw-r--r--t/unit-tests/u-mem-pool.c25
-rw-r--r--t/unit-tests/u-oid-array.c129
-rw-r--r--t/unit-tests/u-oidmap.c136
-rw-r--r--t/unit-tests/u-oidtree.c107
-rw-r--r--t/unit-tests/u-prio-queue.c117
-rw-r--r--t/unit-tests/u-reftable-basics.c227
-rw-r--r--t/unit-tests/u-reftable-block.c458
-rw-r--r--t/unit-tests/u-reftable-merged.c (renamed from t/unit-tests/t-reftable-merged.c)242
-rw-r--r--t/unit-tests/u-reftable-pq.c (renamed from t/unit-tests/t-reftable-pq.c)67
-rw-r--r--t/unit-tests/u-reftable-readwrite.c (renamed from t/unit-tests/t-reftable-readwrite.c)511
-rw-r--r--t/unit-tests/u-reftable-record.c (renamed from t/unit-tests/t-reftable-record.c)297
-rw-r--r--t/unit-tests/u-reftable-stack.c (renamed from t/unit-tests/t-reftable-stack.c)819
-rw-r--r--t/unit-tests/u-reftable-table.c201
-rw-r--r--t/unit-tests/u-reftable-tree.c (renamed from t/unit-tests/t-reftable-tree.c)30
-rw-r--r--t/unit-tests/u-strbuf.c119
-rw-r--r--t/unit-tests/u-strcmp-offset.c45
-rw-r--r--t/unit-tests/u-string-list.c306
-rw-r--r--t/unit-tests/u-trailer.c320
-rw-r--r--t/unit-tests/u-urlmatch-normalization.c (renamed from t/unit-tests/t-urlmatch-normalization.c)60
-rw-r--r--t/unit-tests/unit-test.c2
-rw-r--r--t/unit-tests/unit-test.h7
376 files changed, 18081 insertions, 9494 deletions
diff --git a/t/Makefile b/t/Makefile
index daa5fcae86..ab8a5b54aa 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -59,16 +59,21 @@ CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT
all:: $(DEFAULT_TEST_TARGET)
-test: pre-clean check-chainlint check-meson $(TEST_LINT)
+test: pre-clean check-meson $(TEST_LINT)
$(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup
+ifneq ($(PERL_PATH),)
+test: check-chainlint
+prove: check-chainlint
+endif
+
failed:
@failed=$$(cd '$(TEST_RESULTS_DIRECTORY_SQ)' && \
grep -l '^failed [1-9]' *.counts | \
sed -n 's/\.counts$$/.sh/p') && \
test -z "$$failed" || $(MAKE) $$failed
-prove: pre-clean check-chainlint $(TEST_LINT)
+prove: pre-clean $(TEST_LINT)
@echo "*** prove (shell & unit tests) ***"
@$(CHAINLINTSUPPRESS) TEST_OPTIONS='$(GIT_TEST_OPTS)' TEST_SHELL_PATH='$(TEST_SHELL_PATH_SQ)' $(PROVE) --exec ./run-test.sh $(GIT_PROVE_OPTS) $(T) $(UNIT_TESTS)
$(MAKE) clean-except-prove-cache
@@ -120,7 +125,6 @@ check-meson:
@mkdir -p mesontmp && \
printf "%s\n" \
"integration_tests t[0-9][0-9][0-9][0-9]-*.sh" \
- "unit_test_programs unit-tests/t-*.c" \
"clar_test_suites unit-tests/u-*.c" | \
while read -r variable pattern; do \
awk "/^$$variable = \[\$$/ {flag=1 ; next } /^]$$/ { flag=0 } flag { gsub(/^ \047/, \"\"); gsub(/\047,\$$/, \"\"); print }" meson.build >mesontmp/meson.txt && \
@@ -132,8 +136,13 @@ check-meson:
fi; \
done
-test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
+test-lint: test-lint-duplicates test-lint-executable \
test-lint-filenames
+ifneq ($(PERL_PATH),)
+test-lint: test-lint-shell-syntax
+else
+GIT_TEST_CHAIN_LINT = 0
+endif
ifneq ($(GIT_TEST_CHAIN_LINT),0)
test-lint: test-chainlint
endif
@@ -177,3 +186,12 @@ perf:
.PHONY: pre-clean $(T) aggregate-results clean valgrind perf \
check-chainlint clean-chainlint test-chainlint $(UNIT_TESTS)
+
+.PHONY: libgit-sys-test libgit-rs-test
+libgit-sys-test:
+ $(QUIET)cargo test --manifest-path ../contrib/libgit-sys/Cargo.toml
+libgit-rs-test: libgit-sys-test
+ $(QUIET)cargo test --manifest-path ../contrib/libgit-rs/Cargo.toml
+ifdef INCLUDE_LIBGIT_RS
+all:: libgit-rs-test
+endif
diff --git a/t/README b/t/README
index e84824dc00..adbbd9acf4 100644
--- a/t/README
+++ b/t/README
@@ -415,6 +415,10 @@ GIT_TEST_PACK_SPARSE=<boolean> if disabled will default the pack-objects
builtin to use the non-sparse object walk. This can still be overridden by
the --sparse command-line argument.
+GIT_TEST_PACK_PATH_WALK=<boolean> if enabled will default the pack-objects
+builtin to use the path-walk API for the object walk. This can still be
+overridden by the --no-path-walk command-line argument.
+
GIT_TEST_PRELOAD_INDEX=<boolean> exercises the preload-index code path
by overriding the minimum number of cache entries required per thread.
@@ -471,6 +475,10 @@ a test and then fails then the whole test run will abort. This can help to make
sure the expected tests are executed and not silently skipped when their
dependency breaks or is simply not present in a new environment.
+GIT_TEST_NAME_HASH_VERSION=<int>, when set, causes 'git pack-objects' to
+assume '--name-hash-version=<n>'.
+
+
Naming Tests
------------
@@ -814,7 +822,7 @@ Skipping tests
--------------
If you need to skip tests you should do so by using the three-arg form
-of the test_* functions (see the "Test harness library" section
+of the test_expect_* functions (see the "Test harness library" section
below), e.g.:
test_expect_success PERL 'I need Perl' '
@@ -961,6 +969,29 @@ see test-lib-functions.sh for the full list and their options.
test_done
fi
+ - test_lazy_prereq <prereq> <script>
+
+ Declare the way to determine if a test prerequisite <prereq> is
+ satisified or not, but delay the actual determination until the
+ prerequisite is actually used by "test_have_prereq" or the
+ three-arg form of the test_expect_* functions. For example, this
+ is how the SYMLINKS prerequisite is declared to see if the platform
+ supports symbolic links:
+
+ test_lazy_prereq SYMLINKS '
+ ln -s x y && test -h y
+ '
+
+ The script is lazily invoked when SYMLINKS prerequisite is first
+ queried by either "test_have_prereq SYMLINKS" or "test_expect_*
+ SYMLINKS ...". The script is run in a temporary directory inside
+ a subshell, so you do not have to worry about removing temporary
+ files you create there. When the script exits with status 0, the
+ prerequisite is set. Exiting with non-zero status other than 125
+ makes the prerequisite unsatisified. Exiting the script with 125
+ signals a programming error and is used to mark a prerequisite that
+ should not be used by test scripts.
+
- test_expect_code <exit-code> <command>
Run a command and ensure that it exits with the given exit code.
diff --git a/t/aggregate-results.sh b/t/aggregate-results.sh
index 6e3bcc4aec..6cb0ff11de 100755
--- a/t/aggregate-results.sh
+++ b/t/aggregate-results.sh
@@ -44,7 +44,7 @@ then
tr -s "," "\n" |
grep -v '^$' |
sort -u |
- paste -s -d ' ')
+ paste -s -d ' ' -)
if test -n "$unique_missing_prereq"
then
printf "\nmissing prereq: $unique_missing_prereq\n\n"
diff --git a/t/for-each-ref-tests.sh b/t/for-each-ref-tests.sh
new file mode 100644
index 0000000000..e3ad19298a
--- /dev/null
+++ b/t/for-each-ref-tests.sh
@@ -0,0 +1,2141 @@
+git_for_each_ref=${git_for_each_ref:-git for-each-ref}
+GNUPGHOME_NOT_USED=$GNUPGHOME
+. "$TEST_DIRECTORY"/lib-gpg.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
+
+# Mon Jul 3 23:18:43 2006 +0000
+datestamp=1151968723
+setdate_and_increment () {
+ GIT_COMMITTER_DATE="$datestamp +0200"
+ datestamp=$(expr "$datestamp" + 1)
+ GIT_AUTHOR_DATE="$datestamp +0200"
+ datestamp=$(expr "$datestamp" + 1)
+ export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
+}
+
+test_object_file_size () {
+ oid=$(git rev-parse "$1")
+ path=".git/objects/$(test_oid_to_path $oid)"
+ test_file_size "$path"
+}
+
+test_expect_success setup '
+ # setup .mailmap
+ cat >.mailmap <<-EOF &&
+ A Thor <athor@example.com> A U Thor <author@example.com>
+ C Mitter <cmitter@example.com> C O Mitter <committer@example.com>
+ EOF
+
+ setdate_and_increment &&
+ echo "Using $datestamp" > one &&
+ git add one &&
+ git commit -m "Initial" &&
+ git branch -M main &&
+ setdate_and_increment &&
+ git tag -a -m "Tagging at $datestamp" testtag &&
+ git update-ref refs/remotes/origin/main main &&
+ git remote add origin nowhere &&
+ git config branch.main.remote origin &&
+ git config branch.main.merge refs/heads/main &&
+ git remote add myfork elsewhere &&
+ git config remote.pushdefault myfork &&
+ git config push.default current
+'
+
+test_atom () {
+ case "$1" in
+ head) ref=refs/heads/main ;;
+ tag) ref=refs/tags/testtag ;;
+ sym) ref=refs/heads/sym ;;
+ *) ref=$1 ;;
+ esac
+ format=$2
+ test_do=test_expect_${4:-success}
+
+ printf '%s\n' "$3" >expected
+ $test_do $PREREQ "basic atom: $ref $format" '
+ ${git_for_each_ref} --format="%($format)" "$ref" >actual &&
+ sanitize_pgp <actual >actual.clean &&
+ test_cmp expected actual.clean
+ '
+
+ # Automatically test "contents:size" atom after testing "contents"
+ if test "$format" = "contents"
+ then
+ # for commit leg, $3 is changed there
+ expect=$(printf '%s' "$3" | wc -c)
+ $test_do $PREREQ "basic atom: $ref contents:size" '
+ type=$(git cat-file -t "$ref") &&
+ case $type in
+ tag)
+ # We cannot use $3 as it expects sanitize_pgp to run
+ git cat-file tag $ref >out &&
+ expect=$(tail -n +6 out | wc -c) &&
+ rm -f out ;;
+ tree | blob)
+ expect="" ;;
+ commit)
+ : "use the calculated expect" ;;
+ *)
+ BUG "unknown object type" ;;
+ esac &&
+ # Leave $expect unquoted to lose possible leading whitespaces
+ echo $expect >expected &&
+ ${git_for_each_ref} --format="%(contents:size)" "$ref" >actual &&
+ test_cmp expected actual
+ '
+ fi
+}
+
+hexlen=$(test_oid hexsz)
+
+test_atom head refname refs/heads/main
+test_atom head refname: refs/heads/main
+test_atom head refname:short main
+test_atom head refname:lstrip=1 heads/main
+test_atom head refname:lstrip=2 main
+test_atom head refname:lstrip=-1 main
+test_atom head refname:lstrip=-2 heads/main
+test_atom head refname:rstrip=1 refs/heads
+test_atom head refname:rstrip=2 refs
+test_atom head refname:rstrip=-1 refs
+test_atom head refname:rstrip=-2 refs/heads
+test_atom head refname:strip=1 heads/main
+test_atom head refname:strip=2 main
+test_atom head refname:strip=-1 main
+test_atom head refname:strip=-2 heads/main
+test_atom head upstream refs/remotes/origin/main
+test_atom head upstream:short origin/main
+test_atom head upstream:lstrip=2 origin/main
+test_atom head upstream:lstrip=-2 origin/main
+test_atom head upstream:rstrip=2 refs/remotes
+test_atom head upstream:rstrip=-2 refs/remotes
+test_atom head upstream:strip=2 origin/main
+test_atom head upstream:strip=-2 origin/main
+test_atom head push refs/remotes/myfork/main
+test_atom head push:short myfork/main
+test_atom head push:lstrip=1 remotes/myfork/main
+test_atom head push:lstrip=-1 main
+test_atom head push:rstrip=1 refs/remotes/myfork
+test_atom head push:rstrip=-1 refs
+test_atom head push:strip=1 remotes/myfork/main
+test_atom head push:strip=-1 main
+test_atom head objecttype commit
+test_atom head objectsize $((131 + hexlen))
+test_atom head objectsize:disk $(test_object_file_size refs/heads/main)
+test_atom head deltabase $ZERO_OID
+test_atom head objectname $(git rev-parse refs/heads/main)
+test_atom head objectname:short $(git rev-parse --short refs/heads/main)
+test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
+test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
+test_atom head tree $(git rev-parse refs/heads/main^{tree})
+test_atom head tree:short $(git rev-parse --short refs/heads/main^{tree})
+test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/main^{tree})
+test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/main^{tree})
+test_atom head parent ''
+test_atom head parent:short ''
+test_atom head parent:short=1 ''
+test_atom head parent:short=10 ''
+test_atom head numparent 0
+test_atom head object ''
+test_atom head type ''
+test_atom head raw "$(git cat-file commit refs/heads/main)
+"
+test_atom head '*objectname' ''
+test_atom head '*objecttype' ''
+test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
+test_atom head authorname 'A U Thor'
+test_atom head authorname:mailmap 'A Thor'
+test_atom head authoremail '<author@example.com>'
+test_atom head authoremail:trim 'author@example.com'
+test_atom head authoremail:localpart 'author'
+test_atom head authoremail:trim,localpart 'author'
+test_atom head authoremail:mailmap '<athor@example.com>'
+test_atom head authoremail:mailmap,trim 'athor@example.com'
+test_atom head authoremail:trim,mailmap 'athor@example.com'
+test_atom head authoremail:mailmap,localpart 'athor'
+test_atom head authoremail:localpart,mailmap 'athor'
+test_atom head authoremail:mailmap,trim,localpart,mailmap,trim 'athor'
+test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
+test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
+test_atom head committername 'C O Mitter'
+test_atom head committername:mailmap 'C Mitter'
+test_atom head committeremail '<committer@example.com>'
+test_atom head committeremail:trim 'committer@example.com'
+test_atom head committeremail:localpart 'committer'
+test_atom head committeremail:localpart,trim 'committer'
+test_atom head committeremail:mailmap '<cmitter@example.com>'
+test_atom head committeremail:mailmap,trim 'cmitter@example.com'
+test_atom head committeremail:trim,mailmap 'cmitter@example.com'
+test_atom head committeremail:mailmap,localpart 'cmitter'
+test_atom head committeremail:localpart,mailmap 'cmitter'
+test_atom head committeremail:trim,mailmap,trim,trim,localpart 'cmitter'
+test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
+test_atom head tag ''
+test_atom head tagger ''
+test_atom head taggername ''
+test_atom head taggeremail ''
+test_atom head taggeremail:trim ''
+test_atom head taggeremail:localpart ''
+test_atom head taggerdate ''
+test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
+test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
+test_atom head subject 'Initial'
+test_atom head subject:sanitize 'Initial'
+test_atom head contents:subject 'Initial'
+test_atom head body ''
+test_atom head contents:body ''
+test_atom head contents:signature ''
+test_atom head contents 'Initial
+'
+test_atom head HEAD '*'
+
+test_atom tag refname refs/tags/testtag
+test_atom tag refname:short testtag
+test_atom tag upstream ''
+test_atom tag push ''
+test_atom tag objecttype tag
+test_atom tag objectsize $((114 + hexlen))
+test_atom tag objectsize:disk $(test_object_file_size refs/tags/testtag)
+test_atom tag '*objectsize:disk' $(test_object_file_size refs/heads/main)
+test_atom tag deltabase $ZERO_OID
+test_atom tag '*deltabase' $ZERO_OID
+test_atom tag objectname $(git rev-parse refs/tags/testtag)
+test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
+test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
+test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
+test_atom tag tree ''
+test_atom tag tree:short ''
+test_atom tag tree:short=1 ''
+test_atom tag tree:short=10 ''
+test_atom tag parent ''
+test_atom tag parent:short ''
+test_atom tag parent:short=1 ''
+test_atom tag parent:short=10 ''
+test_atom tag numparent ''
+test_atom tag object $(git rev-parse refs/tags/testtag^0)
+test_atom tag type 'commit'
+test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{})
+test_atom tag '*objecttype' 'commit'
+test_atom tag author ''
+test_atom tag authorname ''
+test_atom tag authorname:mailmap ''
+test_atom tag authoremail ''
+test_atom tag authoremail:trim ''
+test_atom tag authoremail:localpart ''
+test_atom tag authoremail:trim,localpart ''
+test_atom tag authoremail:mailmap ''
+test_atom tag authoremail:mailmap,trim ''
+test_atom tag authoremail:trim,mailmap ''
+test_atom tag authoremail:mailmap,localpart ''
+test_atom tag authoremail:localpart,mailmap ''
+test_atom tag authoremail:mailmap,trim,localpart,mailmap,trim ''
+test_atom tag authordate ''
+test_atom tag committer ''
+test_atom tag committername ''
+test_atom tag committername:mailmap ''
+test_atom tag committeremail ''
+test_atom tag committeremail:trim ''
+test_atom tag committeremail:localpart ''
+test_atom tag committeremail:localpart,trim ''
+test_atom tag committeremail:mailmap ''
+test_atom tag committeremail:mailmap,trim ''
+test_atom tag committeremail:trim,mailmap ''
+test_atom tag committeremail:mailmap,localpart ''
+test_atom tag committeremail:localpart,mailmap ''
+test_atom tag committeremail:trim,mailmap,trim,trim,localpart ''
+test_atom tag committerdate ''
+test_atom tag tag 'testtag'
+test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
+test_atom tag taggername 'C O Mitter'
+test_atom tag taggername:mailmap 'C Mitter'
+test_atom tag taggeremail '<committer@example.com>'
+test_atom tag taggeremail:trim 'committer@example.com'
+test_atom tag taggeremail:localpart 'committer'
+test_atom tag taggeremail:trim,localpart 'committer'
+test_atom tag taggeremail:mailmap '<cmitter@example.com>'
+test_atom tag taggeremail:mailmap,trim 'cmitter@example.com'
+test_atom tag taggeremail:trim,mailmap 'cmitter@example.com'
+test_atom tag taggeremail:mailmap,localpart 'cmitter'
+test_atom tag taggeremail:localpart,mailmap 'cmitter'
+test_atom tag taggeremail:trim,mailmap,trim,localpart,localpart 'cmitter'
+test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
+test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
+test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
+test_atom tag subject 'Tagging at 1151968727'
+test_atom tag subject:sanitize 'Tagging-at-1151968727'
+test_atom tag contents:subject 'Tagging at 1151968727'
+test_atom tag body ''
+test_atom tag contents:body ''
+test_atom tag contents:signature ''
+test_atom tag contents 'Tagging at 1151968727
+'
+test_atom tag HEAD ' '
+
+test_expect_success 'basic atom: refs/tags/testtag *raw' '
+ git cat-file commit refs/tags/testtag^{} >expected &&
+ ${git_for_each_ref} --format="%(*raw)" refs/tags/testtag >actual &&
+ sanitize_pgp <expected >expected.clean &&
+ echo >>expected.clean &&
+ sanitize_pgp <actual >actual.clean &&
+ test_cmp expected.clean actual.clean
+'
+
+test_expect_success 'Check invalid atoms names are errors' '
+ test_must_fail ${git_for_each_ref} --format="%(INVALID)" refs/heads
+'
+
+test_expect_success 'Check format specifiers are ignored in naming date atoms' '
+ ${git_for_each_ref} --format="%(authordate)" refs/heads &&
+ ${git_for_each_ref} --format="%(authordate:default) %(authordate)" refs/heads &&
+ ${git_for_each_ref} --format="%(authordate) %(authordate:default)" refs/heads &&
+ ${git_for_each_ref} --format="%(authordate:default) %(authordate:default)" refs/heads
+'
+
+test_expect_success 'Check valid format specifiers for date fields' '
+ ${git_for_each_ref} --format="%(authordate:default)" refs/heads &&
+ ${git_for_each_ref} --format="%(authordate:relative)" refs/heads &&
+ ${git_for_each_ref} --format="%(authordate:short)" refs/heads &&
+ ${git_for_each_ref} --format="%(authordate:local)" refs/heads &&
+ ${git_for_each_ref} --format="%(authordate:iso8601)" refs/heads &&
+ ${git_for_each_ref} --format="%(authordate:rfc2822)" refs/heads
+'
+
+test_expect_success 'Check invalid format specifiers are errors' '
+ test_must_fail ${git_for_each_ref} --format="%(authordate:INVALID)" refs/heads
+'
+
+test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
+ test_must_fail ${git_for_each_ref} --format="%(objectname:short=0)" &&
+ test_must_fail ${git_for_each_ref} --format="%(objectname:short=-1)" &&
+ test_must_fail ${git_for_each_ref} --format="%(objectname:short=foo)"
+'
+
+test_bad_atom () {
+ case "$1" in
+ head) ref=refs/heads/main ;;
+ tag) ref=refs/tags/testtag ;;
+ sym) ref=refs/heads/sym ;;
+ *) ref=$1 ;;
+ esac
+ format=$2
+ test_do=test_expect_${4:-success}
+
+ printf '%s\n' "$3" >expect
+ $test_do $PREREQ "err basic atom: $ref $format" '
+ test_must_fail ${git_for_each_ref} \
+ --format="%($format)" "$ref" 2>error &&
+ test_cmp expect error
+ '
+}
+
+test_bad_atom head 'authoremail:foo' \
+ 'fatal: unrecognized %(authoremail) argument: foo'
+
+test_bad_atom head 'authoremail:mailmap,trim,bar' \
+ 'fatal: unrecognized %(authoremail) argument: bar'
+
+test_bad_atom head 'authoremail:trim,' \
+ 'fatal: unrecognized %(authoremail) argument: '
+
+test_bad_atom head 'authoremail:mailmaptrim' \
+ 'fatal: unrecognized %(authoremail) argument: trim'
+
+test_bad_atom head 'committeremail: ' \
+ 'fatal: unrecognized %(committeremail) argument: '
+
+test_bad_atom head 'committeremail: trim,foo' \
+ 'fatal: unrecognized %(committeremail) argument: trim,foo'
+
+test_bad_atom head 'committeremail:mailmap,localpart ' \
+ 'fatal: unrecognized %(committeremail) argument: '
+
+test_bad_atom head 'committeremail:trim_localpart' \
+ 'fatal: unrecognized %(committeremail) argument: _localpart'
+
+test_bad_atom head 'committeremail:localpart,,,trim' \
+ 'fatal: unrecognized %(committeremail) argument: ,,trim'
+
+test_bad_atom tag 'taggeremail:mailmap,trim, foo ' \
+ 'fatal: unrecognized %(taggeremail) argument: foo '
+
+test_bad_atom tag 'taggeremail:trim,localpart,' \
+ 'fatal: unrecognized %(taggeremail) argument: '
+
+test_bad_atom tag 'taggeremail:mailmap;localpart trim' \
+ 'fatal: unrecognized %(taggeremail) argument: ;localpart trim'
+
+test_bad_atom tag 'taggeremail:localpart trim' \
+ 'fatal: unrecognized %(taggeremail) argument: trim'
+
+test_bad_atom tag 'taggeremail:mailmap,mailmap,trim,qux,localpart,trim' \
+ 'fatal: unrecognized %(taggeremail) argument: qux,localpart,trim'
+
+test_date () {
+ f=$1 &&
+ committer_date=$2 &&
+ author_date=$3 &&
+ tagger_date=$4 &&
+ cat >expected <<-EOF &&
+ 'refs/heads/main' '$committer_date' '$author_date'
+ 'refs/tags/testtag' '$tagger_date'
+ EOF
+ (
+ ${git_for_each_ref} --shell \
+ --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
+ refs/heads &&
+ ${git_for_each_ref} --shell \
+ --format="%(refname) %(taggerdate${f:+:$f})" \
+ refs/tags
+ ) >actual &&
+ test_cmp expected actual
+}
+
+test_expect_success 'Check unformatted date fields output' '
+ test_date "" \
+ "Tue Jul 4 01:18:43 2006 +0200" \
+ "Tue Jul 4 01:18:44 2006 +0200" \
+ "Tue Jul 4 01:18:45 2006 +0200"
+'
+
+test_expect_success 'Check format "default" formatted date fields output' '
+ test_date default \
+ "Tue Jul 4 01:18:43 2006 +0200" \
+ "Tue Jul 4 01:18:44 2006 +0200" \
+ "Tue Jul 4 01:18:45 2006 +0200"
+'
+
+test_expect_success 'Check format "default-local" date fields output' '
+ test_date default-local "Mon Jul 3 23:18:43 2006" "Mon Jul 3 23:18:44 2006" "Mon Jul 3 23:18:45 2006"
+'
+
+# Don't know how to do relative check because I can't know when this script
+# is going to be run and can't fake the current time to git, and hence can't
+# provide expected output. Instead, I'll just make sure that "relative"
+# doesn't exit in error
+test_expect_success 'Check format "relative" date fields output' '
+ f=relative &&
+ (${git_for_each_ref} --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
+ ${git_for_each_ref} --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
+'
+
+# We just check that this is the same as "relative" for now.
+test_expect_success 'Check format "relative-local" date fields output' '
+ test_date relative-local \
+ "$(${git_for_each_ref} --format="%(committerdate:relative)" refs/heads)" \
+ "$(${git_for_each_ref} --format="%(authordate:relative)" refs/heads)" \
+ "$(${git_for_each_ref} --format="%(taggerdate:relative)" refs/tags)"
+'
+
+test_expect_success 'Check format "short" date fields output' '
+ test_date short 2006-07-04 2006-07-04 2006-07-04
+'
+
+test_expect_success 'Check format "short-local" date fields output' '
+ test_date short-local 2006-07-03 2006-07-03 2006-07-03
+'
+
+test_expect_success 'Check format "local" date fields output' '
+ test_date local \
+ "Mon Jul 3 23:18:43 2006" \
+ "Mon Jul 3 23:18:44 2006" \
+ "Mon Jul 3 23:18:45 2006"
+'
+
+test_expect_success 'Check format "iso8601" date fields output' '
+ test_date iso8601 \
+ "2006-07-04 01:18:43 +0200" \
+ "2006-07-04 01:18:44 +0200" \
+ "2006-07-04 01:18:45 +0200"
+'
+
+test_expect_success 'Check format "iso8601-local" date fields output' '
+ test_date iso8601-local "2006-07-03 23:18:43 +0000" "2006-07-03 23:18:44 +0000" "2006-07-03 23:18:45 +0000"
+'
+
+test_expect_success 'Check format "rfc2822" date fields output' '
+ test_date rfc2822 \
+ "Tue, 4 Jul 2006 01:18:43 +0200" \
+ "Tue, 4 Jul 2006 01:18:44 +0200" \
+ "Tue, 4 Jul 2006 01:18:45 +0200"
+'
+
+test_expect_success 'Check format "rfc2822-local" date fields output' '
+ test_date rfc2822-local "Mon, 3 Jul 2006 23:18:43 +0000" "Mon, 3 Jul 2006 23:18:44 +0000" "Mon, 3 Jul 2006 23:18:45 +0000"
+'
+
+test_expect_success 'Check format "raw" date fields output' '
+ test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
+'
+
+test_expect_success 'Check format "raw-local" date fields output' '
+ test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
+'
+
+test_expect_success 'Check format of strftime date fields' '
+ echo "my date is 2006-07-04" >expected &&
+ ${git_for_each_ref} \
+ --format="%(authordate:format:my date is %Y-%m-%d)" \
+ refs/heads >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Check format of strftime-local date fields' '
+ echo "my date is 2006-07-03" >expected &&
+ ${git_for_each_ref} \
+ --format="%(authordate:format-local:my date is %Y-%m-%d)" \
+ refs/heads >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'exercise strftime with odd fields' '
+ echo >expected &&
+ ${git_for_each_ref} --format="%(authordate:format:)" refs/heads >actual &&
+ test_cmp expected actual &&
+ long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
+ echo $long >expected &&
+ ${git_for_each_ref} --format="%(authordate:format:$long)" refs/heads >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+refs/heads/main
+refs/remotes/origin/main
+refs/tags/testtag
+EOF
+
+test_expect_success 'Verify ascending sort' '
+ ${git_for_each_ref} --format="%(refname)" --sort=refname >actual &&
+ test_cmp expected actual
+'
+
+
+cat >expected <<\EOF
+refs/tags/testtag
+refs/remotes/origin/main
+refs/heads/main
+EOF
+
+test_expect_success 'Verify descending sort' '
+ ${git_for_each_ref} --format="%(refname)" --sort=-refname >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Give help even with invalid sort atoms' '
+ test_expect_code 129 ${git_for_each_ref} --sort=bogus -h >actual 2>&1 &&
+ grep "^usage: ${git_for_each_ref}" actual
+'
+
+cat >expected <<\EOF
+refs/tags/testtag
+refs/tags/testtag-2
+EOF
+
+test_expect_success 'exercise patterns with prefixes' '
+ git tag testtag-2 &&
+ test_when_finished "git tag -d testtag-2" &&
+ ${git_for_each_ref} --format="%(refname)" \
+ refs/tags/testtag refs/tags/testtag-2 >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+refs/tags/testtag
+refs/tags/testtag-2
+EOF
+
+test_expect_success 'exercise glob patterns with prefixes' '
+ git tag testtag-2 &&
+ test_when_finished "git tag -d testtag-2" &&
+ ${git_for_each_ref} --format="%(refname)" \
+ refs/tags/testtag "refs/tags/testtag-*" >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+refs/tags/bar
+refs/tags/baz
+refs/tags/testtag
+EOF
+
+test_expect_success 'exercise patterns with prefix exclusions' '
+ for tag in foo/one foo/two foo/three bar baz
+ do
+ git tag "$tag" || return 1
+ done &&
+ test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
+ ${git_for_each_ref} --format="%(refname)" \
+ refs/tags/ --exclude=refs/tags/foo >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+refs/tags/bar
+refs/tags/baz
+refs/tags/foo/one
+refs/tags/testtag
+EOF
+
+test_expect_success 'exercise patterns with pattern exclusions' '
+ for tag in foo/one foo/two foo/three bar baz
+ do
+ git tag "$tag" || return 1
+ done &&
+ test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
+ ${git_for_each_ref} --format="%(refname)" \
+ refs/tags/ --exclude="refs/tags/foo/t*" >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+'refs/heads/main'
+'refs/remotes/origin/main'
+'refs/tags/testtag'
+EOF
+
+test_expect_success 'Quoting style: shell' '
+ ${git_for_each_ref} --shell --format="%(refname)" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Quoting style: perl' '
+ ${git_for_each_ref} --perl --format="%(refname)" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Quoting style: python' '
+ ${git_for_each_ref} --python --format="%(refname)" >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+"refs/heads/main"
+"refs/remotes/origin/main"
+"refs/tags/testtag"
+EOF
+
+test_expect_success 'Quoting style: tcl' '
+ ${git_for_each_ref} --tcl --format="%(refname)" >actual &&
+ test_cmp expected actual
+'
+
+for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
+ test_expect_success "more than one quoting style: $i" "
+ test_must_fail ${git_for_each_ref} $i 2>err &&
+ grep '^error: more than one quoting style' err
+ "
+done
+
+test_expect_success 'setup for upstream:track[short]' '
+ test_commit two
+'
+
+test_atom head upstream:track '[ahead 1]'
+test_atom head upstream:trackshort '>'
+test_atom head upstream:track,nobracket 'ahead 1'
+test_atom head upstream:nobracket,track 'ahead 1'
+
+test_expect_success 'setup for push:track[short]' '
+ test_commit third &&
+ git update-ref refs/remotes/myfork/main main &&
+ git reset main~1
+'
+
+test_atom head push:track '[behind 1]'
+test_atom head push:trackshort '<'
+
+test_expect_success 'Check that :track[short] cannot be used with other atoms' '
+ test_must_fail ${git_for_each_ref} --format="%(refname:track)" 2>/dev/null &&
+ test_must_fail ${git_for_each_ref} --format="%(refname:trackshort)" 2>/dev/null
+'
+
+test_expect_success 'Check that :track[short] works when upstream is invalid' '
+ cat >expected <<-\EOF &&
+ [gone]
+
+ EOF
+ test_when_finished "git config branch.main.merge refs/heads/main" &&
+ git config branch.main.merge refs/heads/does-not-exist &&
+ ${git_for_each_ref} \
+ --format="%(upstream:track)$LF%(upstream:trackshort)" \
+ refs/heads >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Check for invalid refname format' '
+ test_must_fail ${git_for_each_ref} --format="%(refname:INVALID)"
+'
+
+test_expect_success 'set up color tests' '
+ cat >expected.color <<-EOF &&
+ $(git rev-parse --short refs/heads/main) <GREEN>main<RESET>
+ $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET>
+ $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET>
+ $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
+ $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
+ $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
+ EOF
+ sed "s/<[^>]*>//g" <expected.color >expected.bare &&
+ color_format="%(objectname:short) %(color:green)%(refname:short)"
+'
+
+test_expect_success TTY '%(color) shows color with a tty' '
+ test_terminal ${git_for_each_ref} --format="$color_format" >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expected.color actual
+'
+
+test_expect_success '%(color) does not show color without tty' '
+ TERM=vt100 ${git_for_each_ref} --format="$color_format" >actual &&
+ test_cmp expected.bare actual
+'
+
+test_expect_success '--color can override tty check' '
+ ${git_for_each_ref} --color --format="$color_format" >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expected.color actual
+'
+
+test_expect_success 'color.ui=always does not override tty check' '
+ git -c color.ui=always ${git_for_each_ref#git} --format="$color_format" >actual &&
+ test_cmp expected.bare actual
+'
+
+test_expect_success 'setup for describe atom tests' '
+ git init -b master describe-repo &&
+ (
+ cd describe-repo &&
+
+ test_commit --no-tag one &&
+ git tag tagone &&
+
+ test_commit --no-tag two &&
+ git tag -a -m "tag two" tagtwo
+ )
+'
+
+test_expect_success 'describe atom vs git describe' '
+ (
+ cd describe-repo &&
+
+ ${git_for_each_ref} --format="%(objectname)" \
+ refs/tags/ >obj &&
+ while read hash
+ do
+ if desc=$(git describe $hash)
+ then
+ : >expect-contains-good
+ else
+ : >expect-contains-bad
+ fi &&
+ echo "$hash $desc" || return 1
+ done <obj >expect &&
+ test_path_exists expect-contains-good &&
+ test_path_exists expect-contains-bad &&
+
+ ${git_for_each_ref} --format="%(objectname) %(describe)" \
+ refs/tags/ >actual 2>err &&
+ test_cmp expect actual &&
+ test_must_be_empty err
+ )
+'
+
+test_expect_success 'describe:tags vs describe --tags' '
+ (
+ cd describe-repo &&
+ git describe --tags >expect &&
+ ${git_for_each_ref} --format="%(describe:tags)" \
+ refs/heads/master >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'describe:abbrev=... vs describe --abbrev=...' '
+ (
+ cd describe-repo &&
+
+ # Case 1: We have commits between HEAD and the most
+ # recent tag reachable from it
+ test_commit --no-tag file &&
+ git describe --abbrev=14 >expect &&
+ ${git_for_each_ref} --format="%(describe:abbrev=14)" \
+ refs/heads/master >actual &&
+ test_cmp expect actual &&
+
+ # Make sure the hash used is at least 14 digits long
+ sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart &&
+ test 15 -le $(wc -c <hexpart) &&
+
+ # Case 2: We have a tag at HEAD, describe directly gives
+ # the name of the tag
+ git tag -a -m tagged tagname &&
+ git describe --abbrev=14 >expect &&
+ ${git_for_each_ref} --format="%(describe:abbrev=14)" \
+ refs/heads/master >actual &&
+ test_cmp expect actual &&
+ test tagname = $(cat actual)
+ )
+'
+
+test_expect_success 'describe:match=... vs describe --match ...' '
+ (
+ cd describe-repo &&
+ git tag -a -m "tag foo" tag-foo &&
+ git describe --match "*-foo" >expect &&
+ ${git_for_each_ref} --format="%(describe:match="*-foo")" \
+ refs/heads/master >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'describe:exclude:... vs describe --exclude ...' '
+ (
+ cd describe-repo &&
+ git tag -a -m "tag bar" tag-bar &&
+ git describe --exclude "*-bar" >expect &&
+ ${git_for_each_ref} --format="%(describe:exclude="*-bar")" \
+ refs/heads/master >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'deref with describe atom' '
+ (
+ cd describe-repo &&
+ cat >expect <<-\EOF &&
+
+ tagname
+ tagname
+ tagname
+
+ tagtwo
+ EOF
+ ${git_for_each_ref} --format="%(*describe)" >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'err on bad describe atom arg' '
+ (
+ cd describe-repo &&
+
+ # The bad arg is the only arg passed to describe atom
+ cat >expect <<-\EOF &&
+ fatal: unrecognized %(describe) argument: baz
+ EOF
+ test_must_fail ${git_for_each_ref} --format="%(describe:baz)" \
+ refs/heads/master 2>actual &&
+ test_cmp expect actual &&
+
+ # The bad arg is in the middle of the option string
+ # passed to the describe atom
+ cat >expect <<-\EOF &&
+ fatal: unrecognized %(describe) argument: qux=1,abbrev=14
+ EOF
+ test_must_fail ${git_for_each_ref} \
+ --format="%(describe:tags,qux=1,abbrev=14)" \
+ ref/heads/master 2>actual &&
+ test_cmp expect actual
+ )
+'
+
+cat >expected <<\EOF
+heads/main
+tags/main
+EOF
+
+test_expect_success 'Check ambiguous head and tag refs (strict)' '
+ git config --bool core.warnambiguousrefs true &&
+ git checkout -b newtag &&
+ echo "Using $datestamp" > one &&
+ git add one &&
+ git commit -m "Branch" &&
+ setdate_and_increment &&
+ git tag -m "Tagging at $datestamp" main &&
+ ${git_for_each_ref} --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+heads/main
+main
+EOF
+
+test_expect_success 'Check ambiguous head and tag refs (loose)' '
+ git config --bool core.warnambiguousrefs false &&
+ ${git_for_each_ref} --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+heads/ambiguous
+ambiguous
+EOF
+
+test_expect_success 'Check ambiguous head and tag refs II (loose)' '
+ git checkout main &&
+ git tag ambiguous testtag^0 &&
+ git branch ambiguous testtag^0 &&
+ ${git_for_each_ref} --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'create tag without tagger' '
+ git tag -a -m "Broken tag" taggerless &&
+ git tag -f taggerless $(git cat-file tag taggerless |
+ sed -e "/^tagger /d" |
+ git hash-object --literally --stdin -w -t tag)
+'
+
+test_atom refs/tags/taggerless type 'commit'
+test_atom refs/tags/taggerless tag 'taggerless'
+test_atom refs/tags/taggerless tagger ''
+test_atom refs/tags/taggerless taggername ''
+test_atom refs/tags/taggerless taggeremail ''
+test_atom refs/tags/taggerless taggeremail:trim ''
+test_atom refs/tags/taggerless taggeremail:localpart ''
+test_atom refs/tags/taggerless taggerdate ''
+test_atom refs/tags/taggerless committer ''
+test_atom refs/tags/taggerless committername ''
+test_atom refs/tags/taggerless committeremail ''
+test_atom refs/tags/taggerless committeremail:trim ''
+test_atom refs/tags/taggerless committeremail:localpart ''
+test_atom refs/tags/taggerless committerdate ''
+test_atom refs/tags/taggerless subject 'Broken tag'
+
+test_expect_success 'an unusual tag with an incomplete line' '
+
+ git tag -m "bogo" bogo &&
+ bogo=$(git cat-file tag bogo) &&
+ bogo=$(printf "%s" "$bogo" | git mktag) &&
+ git tag -f bogo "$bogo" &&
+ ${git_for_each_ref} --format "%(body)" refs/tags/bogo
+
+'
+
+test_expect_success 'create tag with subject and body content' '
+ cat >>msg <<-\EOF &&
+ the subject line
+
+ first body line
+ second body line
+ EOF
+ git tag -F msg subject-body
+'
+test_atom refs/tags/subject-body subject 'the subject line'
+test_atom refs/tags/subject-body subject:sanitize 'the-subject-line'
+test_atom refs/tags/subject-body body 'first body line
+second body line
+'
+test_atom refs/tags/subject-body contents 'the subject line
+
+first body line
+second body line
+'
+
+test_expect_success 'create tag with multiline subject' '
+ cat >msg <<-\EOF &&
+ first subject line
+ second subject line
+
+ first body line
+ second body line
+ EOF
+ git tag -F msg multiline
+'
+test_atom refs/tags/multiline subject 'first subject line second subject line'
+test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line'
+test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
+test_atom refs/tags/multiline body 'first body line
+second body line
+'
+test_atom refs/tags/multiline contents:body 'first body line
+second body line
+'
+test_atom refs/tags/multiline contents:signature ''
+test_atom refs/tags/multiline contents 'first subject line
+second subject line
+
+first body line
+second body line
+'
+
+test_expect_success GPG 'create signed tags' '
+ git tag -s -m "" signed-empty &&
+ git tag -s -m "subject line" signed-short &&
+ cat >msg <<-\EOF &&
+ subject line
+
+ body contents
+ EOF
+ git tag -s -F msg signed-long
+'
+
+sig='-----BEGIN PGP SIGNATURE-----
+-----END PGP SIGNATURE-----
+'
+
+PREREQ=GPG
+test_atom refs/tags/signed-empty subject ''
+test_atom refs/tags/signed-empty subject:sanitize ''
+test_atom refs/tags/signed-empty contents:subject ''
+test_atom refs/tags/signed-empty body "$sig"
+test_atom refs/tags/signed-empty contents:body ''
+test_atom refs/tags/signed-empty contents:signature "$sig"
+test_atom refs/tags/signed-empty contents "$sig"
+
+test_expect_success GPG 'basic atom: refs/tags/signed-empty raw' '
+ git cat-file tag refs/tags/signed-empty >expected &&
+ ${git_for_each_ref} --format="%(raw)" refs/tags/signed-empty >actual &&
+ sanitize_pgp <expected >expected.clean &&
+ echo >>expected.clean &&
+ sanitize_pgp <actual >actual.clean &&
+ test_cmp expected.clean actual.clean
+'
+
+test_atom refs/tags/signed-short subject 'subject line'
+test_atom refs/tags/signed-short subject:sanitize 'subject-line'
+test_atom refs/tags/signed-short contents:subject 'subject line'
+test_atom refs/tags/signed-short body "$sig"
+test_atom refs/tags/signed-short contents:body ''
+test_atom refs/tags/signed-short contents:signature "$sig"
+test_atom refs/tags/signed-short contents "subject line
+$sig"
+
+test_expect_success GPG 'basic atom: refs/tags/signed-short raw' '
+ git cat-file tag refs/tags/signed-short >expected &&
+ ${git_for_each_ref} --format="%(raw)" refs/tags/signed-short >actual &&
+ sanitize_pgp <expected >expected.clean &&
+ echo >>expected.clean &&
+ sanitize_pgp <actual >actual.clean &&
+ test_cmp expected.clean actual.clean
+'
+
+test_atom refs/tags/signed-long subject 'subject line'
+test_atom refs/tags/signed-long subject:sanitize 'subject-line'
+test_atom refs/tags/signed-long contents:subject 'subject line'
+test_atom refs/tags/signed-long body "body contents
+$sig"
+test_atom refs/tags/signed-long contents:body 'body contents
+'
+test_atom refs/tags/signed-long contents:signature "$sig"
+test_atom refs/tags/signed-long contents "subject line
+
+body contents
+$sig"
+
+test_expect_success GPG 'basic atom: refs/tags/signed-long raw' '
+ git cat-file tag refs/tags/signed-long >expected &&
+ ${git_for_each_ref} --format="%(raw)" refs/tags/signed-long >actual &&
+ sanitize_pgp <expected >expected.clean &&
+ echo >>expected.clean &&
+ sanitize_pgp <actual >actual.clean &&
+ test_cmp expected.clean actual.clean
+'
+
+test_expect_success 'set up refs pointing to tree and blob' '
+ git update-ref refs/mytrees/first refs/heads/main^{tree} &&
+ git update-ref refs/myblobs/first refs/heads/main:one
+'
+
+test_atom refs/mytrees/first subject ""
+test_atom refs/mytrees/first contents:subject ""
+test_atom refs/mytrees/first body ""
+test_atom refs/mytrees/first contents:body ""
+test_atom refs/mytrees/first contents:signature ""
+test_atom refs/mytrees/first contents ""
+
+test_expect_success 'basic atom: refs/mytrees/first raw' '
+ git cat-file tree refs/mytrees/first >expected &&
+ echo >>expected &&
+ ${git_for_each_ref} --format="%(raw)" refs/mytrees/first >actual &&
+ test_cmp expected actual &&
+ git cat-file -s refs/mytrees/first >expected &&
+ ${git_for_each_ref} --format="%(raw:size)" refs/mytrees/first >actual &&
+ test_cmp expected actual
+'
+
+test_atom refs/myblobs/first subject ""
+test_atom refs/myblobs/first contents:subject ""
+test_atom refs/myblobs/first body ""
+test_atom refs/myblobs/first contents:body ""
+test_atom refs/myblobs/first contents:signature ""
+test_atom refs/myblobs/first contents ""
+
+test_expect_success 'basic atom: refs/myblobs/first raw' '
+ git cat-file blob refs/myblobs/first >expected &&
+ echo >>expected &&
+ ${git_for_each_ref} --format="%(raw)" refs/myblobs/first >actual &&
+ test_cmp expected actual &&
+ git cat-file -s refs/myblobs/first >expected &&
+ ${git_for_each_ref} --format="%(raw:size)" refs/myblobs/first >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'set up refs pointing to binary blob' '
+ printf "a\0b\0c" >blob1 &&
+ printf "a\0c\0b" >blob2 &&
+ printf "\0a\0b\0c" >blob3 &&
+ printf "abc" >blob4 &&
+ printf "\0 \0 \0 " >blob5 &&
+ printf "\0 \0a\0 " >blob6 &&
+ printf " " >blob7 &&
+ >blob8 &&
+ obj=$(git hash-object -w blob1) &&
+ git update-ref refs/myblobs/blob1 "$obj" &&
+ obj=$(git hash-object -w blob2) &&
+ git update-ref refs/myblobs/blob2 "$obj" &&
+ obj=$(git hash-object -w blob3) &&
+ git update-ref refs/myblobs/blob3 "$obj" &&
+ obj=$(git hash-object -w blob4) &&
+ git update-ref refs/myblobs/blob4 "$obj" &&
+ obj=$(git hash-object -w blob5) &&
+ git update-ref refs/myblobs/blob5 "$obj" &&
+ obj=$(git hash-object -w blob6) &&
+ git update-ref refs/myblobs/blob6 "$obj" &&
+ obj=$(git hash-object -w blob7) &&
+ git update-ref refs/myblobs/blob7 "$obj" &&
+ obj=$(git hash-object -w blob8) &&
+ git update-ref refs/myblobs/blob8 "$obj"
+'
+
+test_expect_success 'Verify sorts with raw' '
+ cat >expected <<-EOF &&
+ refs/myblobs/blob8
+ refs/myblobs/blob5
+ refs/myblobs/blob6
+ refs/myblobs/blob3
+ refs/myblobs/blob7
+ refs/mytrees/first
+ refs/myblobs/first
+ refs/myblobs/blob1
+ refs/myblobs/blob2
+ refs/myblobs/blob4
+ refs/heads/main
+ EOF
+ ${git_for_each_ref} --format="%(refname)" --sort=raw \
+ refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'Verify sorts with raw:size' '
+ cat >expected <<-EOF &&
+ refs/myblobs/blob8
+ refs/myblobs/blob7
+ refs/myblobs/blob4
+ refs/myblobs/blob1
+ refs/myblobs/blob2
+ refs/myblobs/blob3
+ refs/myblobs/blob5
+ refs/myblobs/blob6
+ refs/myblobs/first
+ refs/mytrees/first
+ refs/heads/main
+ EOF
+ ${git_for_each_ref} --format="%(refname)" --sort=raw:size \
+ refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'validate raw atom with %(if:equals)' '
+ cat >expected <<-EOF &&
+ not equals
+ not equals
+ not equals
+ not equals
+ not equals
+ not equals
+ refs/myblobs/blob4
+ not equals
+ not equals
+ not equals
+ not equals
+ not equals
+ EOF
+ ${git_for_each_ref} --format="%(if:equals=abc)%(raw)%(then)%(refname)%(else)not equals%(end)" \
+ refs/myblobs/ refs/heads/ >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'validate raw atom with %(if:notequals)' '
+ cat >expected <<-EOF &&
+ refs/heads/ambiguous
+ refs/heads/main
+ refs/heads/newtag
+ refs/myblobs/blob1
+ refs/myblobs/blob2
+ refs/myblobs/blob3
+ equals
+ refs/myblobs/blob5
+ refs/myblobs/blob6
+ refs/myblobs/blob7
+ refs/myblobs/blob8
+ refs/myblobs/first
+ EOF
+ ${git_for_each_ref} --format="%(if:notequals=abc)%(raw)%(then)%(refname)%(else)equals%(end)" \
+ refs/myblobs/ refs/heads/ >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'empty raw refs with %(if)' '
+ cat >expected <<-EOF &&
+ refs/myblobs/blob1 not empty
+ refs/myblobs/blob2 not empty
+ refs/myblobs/blob3 not empty
+ refs/myblobs/blob4 not empty
+ refs/myblobs/blob5 not empty
+ refs/myblobs/blob6 not empty
+ refs/myblobs/blob7 empty
+ refs/myblobs/blob8 empty
+ refs/myblobs/first not empty
+ EOF
+ ${git_for_each_ref} --format="%(refname) %(if)%(raw)%(then)not empty%(else)empty%(end)" \
+ refs/myblobs/ >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success '%(raw) with --python must fail' '
+ test_must_fail ${git_for_each_ref} --format="%(raw)" --python
+'
+
+test_expect_success '%(raw) with --tcl must fail' '
+ test_must_fail ${git_for_each_ref} --format="%(raw)" --tcl
+'
+
+test_expect_success PERL_TEST_HELPERS '%(raw) with --perl' '
+ ${git_for_each_ref} --format="\$name= %(raw);
+print \"\$name\"" refs/myblobs/blob1 --perl | perl >actual &&
+ cmp blob1 actual &&
+ ${git_for_each_ref} --format="\$name= %(raw);
+print \"\$name\"" refs/myblobs/blob3 --perl | perl >actual &&
+ cmp blob3 actual &&
+ ${git_for_each_ref} --format="\$name= %(raw);
+print \"\$name\"" refs/myblobs/blob8 --perl | perl >actual &&
+ cmp blob8 actual &&
+ ${git_for_each_ref} --format="\$name= %(raw);
+print \"\$name\"" refs/myblobs/first --perl | perl >actual &&
+ cmp one actual &&
+ git cat-file tree refs/mytrees/first > expected &&
+ ${git_for_each_ref} --format="\$name= %(raw);
+print \"\$name\"" refs/mytrees/first --perl | perl >actual &&
+ cmp expected actual
+'
+
+test_expect_success '%(raw) with --shell must fail' '
+ test_must_fail ${git_for_each_ref} --format="%(raw)" --shell
+'
+
+test_expect_success '%(raw) with --shell and --sort=raw must fail' '
+ test_must_fail ${git_for_each_ref} --format="%(raw)" --sort=raw --shell
+'
+
+test_expect_success '%(raw:size) with --shell' '
+ ${git_for_each_ref} --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect &&
+ ${git_for_each_ref} --format="%(raw:size)" --shell >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success "${git_for_each_ref} --format compare with cat-file --batch" '
+ git rev-parse refs/mytrees/first | git cat-file --batch >expected &&
+ ${git_for_each_ref} --format="%(objectname) %(objecttype) %(objectsize)
+%(raw)" refs/mytrees/first >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'verify sorts with contents:size' '
+ cat >expect <<-\EOF &&
+ refs/heads/main
+ refs/heads/newtag
+ refs/heads/ambiguous
+ EOF
+ ${git_for_each_ref} --format="%(refname)" \
+ --sort=contents:size refs/heads/ >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'set up multiple-sort tags' '
+ for when in 100000 200000
+ do
+ for email in user1 user2
+ do
+ for ref in ref1 ref2
+ do
+ GIT_COMMITTER_DATE="@$when +0000" \
+ GIT_COMMITTER_EMAIL="$email@example.com" \
+ git tag -m "tag $ref-$when-$email" \
+ multi-$ref-$when-$email || return 1
+ done
+ done
+ done
+'
+
+test_expect_success 'Verify sort with multiple keys' '
+ cat >expected <<-\EOF &&
+ 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
+ 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
+ 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
+ 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
+ 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
+ 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
+ 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
+ 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
+ EOF
+ ${git_for_each_ref} \
+ --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
+ --sort=-refname \
+ --sort=taggeremail \
+ --sort=taggerdate \
+ "refs/tags/multi-*" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'equivalent sorts fall back on refname' '
+ cat >expected <<-\EOF &&
+ 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
+ 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
+ 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
+ 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
+ 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
+ 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
+ 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
+ 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
+ EOF
+ ${git_for_each_ref} \
+ --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
+ --sort=taggerdate \
+ "refs/tags/multi-*" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success '--no-sort cancels the previous sort keys' '
+ cat >expected <<-\EOF &&
+ 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
+ 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
+ 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
+ 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
+ 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
+ 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
+ 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
+ 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
+ EOF
+ ${git_for_each_ref} \
+ --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
+ --sort=-refname \
+ --sort=taggeremail \
+ --no-sort \
+ --sort=taggerdate \
+ "refs/tags/multi-*" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success '--no-sort without subsequent --sort prints expected refs' '
+ cat >expected <<-\EOF &&
+ refs/tags/multi-ref1-100000-user1
+ refs/tags/multi-ref1-100000-user2
+ refs/tags/multi-ref1-200000-user1
+ refs/tags/multi-ref1-200000-user2
+ refs/tags/multi-ref2-100000-user1
+ refs/tags/multi-ref2-100000-user2
+ refs/tags/multi-ref2-200000-user1
+ refs/tags/multi-ref2-200000-user2
+ EOF
+
+ # Sort the results with `sort` for a consistent comparison against
+ # expected
+ ${git_for_each_ref} \
+ --format="%(refname)" \
+ --no-sort \
+ "refs/tags/multi-*" | sort >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'set up custom date sorting' '
+ # Dates:
+ # - Wed Feb 07 2024 21:34:20 +0000
+ # - Tue Dec 14 1999 00:05:22 +0000
+ # - Fri Jun 04 2021 11:26:51 +0000
+ # - Mon Jan 22 2007 16:44:01 GMT+0000
+ i=1 &&
+ for when in 1707341660 945129922 1622806011 1169484241
+ do
+ GIT_COMMITTER_DATE="@$when +0000" \
+ GIT_COMMITTER_EMAIL="user@example.com" \
+ git tag -m "tag $when" custom-dates-$i &&
+ i=$(($i+1)) || return 1
+ done
+'
+
+test_expect_success 'sort by date defaults to full timestamp' '
+ cat >expected <<-\EOF &&
+ 945129922 refs/tags/custom-dates-2
+ 1169484241 refs/tags/custom-dates-4
+ 1622806011 refs/tags/custom-dates-3
+ 1707341660 refs/tags/custom-dates-1
+ EOF
+
+ ${git_for_each_ref} \
+ --format="%(creatordate:unix) %(refname)" \
+ --sort=creatordate \
+ "refs/tags/custom-dates-*" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'sort by custom date format' '
+ cat >expected <<-\EOF &&
+ 00:05:22 refs/tags/custom-dates-2
+ 11:26:51 refs/tags/custom-dates-3
+ 16:44:01 refs/tags/custom-dates-4
+ 21:34:20 refs/tags/custom-dates-1
+ EOF
+
+ ${git_for_each_ref} \
+ --format="%(creatordate:format:%H:%M:%S) %(refname)" \
+ --sort="creatordate:format:%H:%M:%S" \
+ "refs/tags/custom-dates-*" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
+ test_when_finished "git checkout main" &&
+ ${git_for_each_ref} --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
+ sed -e "s/^\* / /" actual >expect &&
+ git checkout --orphan orphaned-branch &&
+ ${git_for_each_ref} --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
+ test_cmp expect actual
+'
+
+cat >trailers <<EOF
+Reviewed-by: A U Thor <author@example.com>
+Signed-off-by: A U Thor <author@example.com>
+[ v2 updated patch description ]
+Acked-by: A U Thor
+ <author@example.com>
+EOF
+
+unfold () {
+ perl -0pe 's/\n\s+/ /g'
+}
+
+test_expect_success 'set up trailers for next test' '
+ echo "Some contents" > two &&
+ git add two &&
+ git commit -F - <<-EOF
+ trailers: this commit message has trailers
+
+ Some message contents
+
+ $(cat trailers)
+ EOF
+'
+
+test_trailer_option () {
+ if test "$#" -eq 3
+ then
+ prereq="$1"
+ shift
+ fi &&
+ title=$1 option=$2
+ cat >expect
+ test_expect_success $prereq "$title" '
+ ${git_for_each_ref} --format="%($option)" refs/heads/main >actual &&
+ test_cmp expect actual &&
+ ${git_for_each_ref} --format="%(contents:$option)" refs/heads/main >actual &&
+ test_cmp expect actual
+ '
+}
+
+test_trailer_option PERL_TEST_HELPERS '%(trailers:unfold) unfolds trailers' \
+ 'trailers:unfold' <<-EOF
+ $(unfold <trailers)
+
+ EOF
+
+test_trailer_option '%(trailers:only) shows only "key: value" trailers' \
+ 'trailers:only' <<-EOF
+ $(grep -v patch.description <trailers)
+
+ EOF
+
+test_trailer_option '%(trailers:only=no,only=true) shows only "key: value" trailers' \
+ 'trailers:only=no,only=true' <<-EOF
+ $(grep -v patch.description <trailers)
+
+ EOF
+
+test_trailer_option '%(trailers:only=yes) shows only "key: value" trailers' \
+ 'trailers:only=yes' <<-EOF
+ $(grep -v patch.description <trailers)
+
+ EOF
+
+test_trailer_option '%(trailers:only=no) shows all trailers' \
+ 'trailers:only=no' <<-EOF
+ $(cat trailers)
+
+ EOF
+
+test_trailer_option PERL_TEST_HELPERS '%(trailers:only) and %(trailers:unfold) work together' \
+ 'trailers:only,unfold' <<-EOF
+ $(grep -v patch.description <trailers | unfold)
+
+ EOF
+
+test_trailer_option PERL_TEST_HELPERS '%(trailers:unfold) and %(trailers:only) work together' \
+ 'trailers:unfold,only' <<-EOF
+ $(grep -v patch.description <trailers | unfold)
+
+ EOF
+
+test_trailer_option '%(trailers:key=foo) shows that trailer' \
+ 'trailers:key=Signed-off-by' <<-EOF
+ Signed-off-by: A U Thor <author@example.com>
+
+ EOF
+
+test_trailer_option '%(trailers:key=foo) is case insensitive' \
+ 'trailers:key=SiGned-oFf-bY' <<-EOF
+ Signed-off-by: A U Thor <author@example.com>
+
+ EOF
+
+test_trailer_option '%(trailers:key=foo:) trailing colon also works' \
+ 'trailers:key=Signed-off-by:' <<-EOF
+ Signed-off-by: A U Thor <author@example.com>
+
+ EOF
+
+test_trailer_option '%(trailers:key=foo) multiple keys' \
+ 'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF
+ Reviewed-by: A U Thor <author@example.com>
+ Signed-off-by: A U Thor <author@example.com>
+
+ EOF
+
+test_trailer_option '%(trailers:key=nonexistent) becomes empty' \
+ 'trailers:key=Shined-off-by:' <<-EOF
+
+ EOF
+
+test_trailer_option '%(trailers:key=foo) handles multiple lines even if folded' \
+ 'trailers:key=Acked-by' <<-EOF
+ $(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by)
+
+ EOF
+
+test_trailer_option '%(trailers:key=foo,unfold) properly unfolds' \
+ 'trailers:key=Signed-Off-by,unfold' <<-EOF
+ $(unfold <trailers | grep Signed-off-by)
+
+ EOF
+
+test_trailer_option '%(trailers:key=foo,only=no) also includes nontrailer lines' \
+ 'trailers:key=Signed-off-by,only=no' <<-EOF
+ Signed-off-by: A U Thor <author@example.com>
+ $(grep patch.description <trailers)
+
+ EOF
+
+test_trailer_option '%(trailers:key=foo,valueonly) shows only value' \
+ 'trailers:key=Signed-off-by,valueonly' <<-EOF
+ A U Thor <author@example.com>
+
+ EOF
+
+test_trailer_option '%(trailers:separator) changes separator' \
+ 'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
+ Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com>
+ EOF
+
+test_trailer_option '%(trailers:key_value_separator) changes key-value separator' \
+ 'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
+ Reviewed-by,A U Thor <author@example.com>
+ Signed-off-by,A U Thor <author@example.com>
+
+ EOF
+
+test_trailer_option '%(trailers:separator,key_value_separator) changes both separators' \
+ 'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
+ Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com>
+ EOF
+
+test_expect_success 'multiple %(trailers) use their own options' '
+ git tag -F - tag-with-trailers <<-\EOF &&
+ body
+
+ one: foo
+ one: bar
+ two: baz
+ two: qux
+ EOF
+ t1="%(trailers:key=one,key_value_separator=W,separator=X)" &&
+ t2="%(trailers:key=two,key_value_separator=Y,separator=Z)" &&
+ ${git_for_each_ref} --format="$t1%0a$t2" refs/tags/tag-with-trailers >actual &&
+ cat >expect <<-\EOF &&
+ oneWfooXoneWbar
+ twoYbazZtwoYqux
+ EOF
+ test_cmp expect actual
+'
+
+test_failing_trailer_option () {
+ title=$1 option=$2
+ cat >expect
+ test_expect_success "$title" '
+ # error message cannot be checked under i18n
+ test_must_fail ${git_for_each_ref} --format="%($option)" refs/heads/main 2>actual &&
+ test_cmp expect actual &&
+ test_must_fail ${git_for_each_ref} --format="%(contents:$option)" refs/heads/main 2>actual &&
+ test_cmp expect actual
+ '
+}
+
+test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \
+ 'trailers:unsupported' <<-\EOF
+ fatal: unknown %(trailers) argument: unsupported
+ EOF
+
+test_failing_trailer_option '%(trailers:key) without value is error' \
+ 'trailers:key' <<-\EOF
+ fatal: expected %(trailers:key=<value>)
+ EOF
+
+test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
+ cat >expect <<-EOF &&
+ fatal: unrecognized %(contents) argument: trailersonly
+ EOF
+ test_must_fail ${git_for_each_ref} --format="%(contents:trailersonly)" 2>actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'basic atom: head contents:trailers' '
+ ${git_for_each_ref} --format="%(contents:trailers)" refs/heads/main >actual &&
+ sanitize_pgp <actual >actual.clean &&
+ # ${git_for_each_ref} ends with a blank line
+ cat >expect <<-EOF &&
+ $(cat trailers)
+
+ EOF
+ test_cmp expect actual.clean
+'
+
+test_expect_success 'basic atom: rest must fail' '
+ test_must_fail ${git_for_each_ref} --format="%(rest)" refs/heads/main
+'
+
+test_expect_success 'HEAD atom does not take arguments' '
+ test_must_fail ${git_for_each_ref} --format="%(HEAD:foo)" 2>err &&
+ echo "fatal: %(HEAD) does not take arguments" >expect &&
+ test_cmp expect err
+'
+
+test_expect_success 'subject atom rejects unknown arguments' '
+ test_must_fail ${git_for_each_ref} --format="%(subject:foo)" 2>err &&
+ echo "fatal: unrecognized %(subject) argument: foo" >expect &&
+ test_cmp expect err
+'
+
+test_expect_success 'refname atom rejects unknown arguments' '
+ test_must_fail ${git_for_each_ref} --format="%(refname:foo)" 2>err &&
+ echo "fatal: unrecognized %(refname) argument: foo" >expect &&
+ test_cmp expect err
+'
+
+test_expect_success 'trailer parsing not fooled by --- line' '
+ git commit --allow-empty -F - <<-\EOF &&
+ this is the subject
+
+ This is the body. The message has a "---" line which would confuse a
+ message+patch parser. But here we know we have only a commit message,
+ so we get it right.
+
+ trailer: wrong
+ ---
+ This is more body.
+
+ trailer: right
+ EOF
+
+ {
+ echo "trailer: right" &&
+ echo
+ } >expect &&
+ ${git_for_each_ref} --format="%(trailers)" refs/heads/main >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'Add symbolic ref for the following tests' '
+ git symbolic-ref refs/heads/sym refs/heads/main
+'
+
+cat >expected <<EOF
+refs/heads/main
+EOF
+
+test_expect_success 'Verify usage of %(symref) atom' '
+ ${git_for_each_ref} --format="%(symref)" refs/heads/sym >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF
+heads/main
+EOF
+
+test_expect_success 'Verify usage of %(symref:short) atom' '
+ ${git_for_each_ref} --format="%(symref:short)" refs/heads/sym >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF
+main
+heads/main
+EOF
+
+test_expect_success 'Verify usage of %(symref:lstrip) atom' '
+ ${git_for_each_ref} --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
+ ${git_for_each_ref} --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
+ test_cmp expected actual &&
+
+ ${git_for_each_ref} --format="%(symref:strip=2)" refs/heads/sym > actual &&
+ ${git_for_each_ref} --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF
+refs
+refs/heads
+EOF
+
+test_expect_success 'Verify usage of %(symref:rstrip) atom' '
+ ${git_for_each_ref} --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
+ ${git_for_each_ref} --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
+ test_cmp expected actual
+'
+
+test_expect_success ':remotename and :remoteref' '
+ git init remote-tests &&
+ (
+ cd remote-tests &&
+ test_commit initial &&
+ git branch -M main &&
+ git remote add from fifth.coffee:blub &&
+ git config branch.main.remote from &&
+ git config branch.main.merge refs/heads/stable &&
+ git remote add to southridge.audio:repo &&
+ git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
+ git config branch.main.pushRemote to &&
+ for pair in "%(upstream)=refs/remotes/from/stable" \
+ "%(upstream:remotename)=from" \
+ "%(upstream:remoteref)=refs/heads/stable" \
+ "%(push)=refs/remotes/to/pushed/main" \
+ "%(push:remotename)=to" \
+ "%(push:remoteref)=refs/heads/pushed/main"
+ do
+ echo "${pair#*=}" >expect &&
+ ${git_for_each_ref} --format="${pair%=*}" \
+ refs/heads/main >actual &&
+ test_cmp expect actual || exit 1
+ done &&
+ git branch push-simple &&
+ git config branch.push-simple.pushRemote from &&
+ actual="$(${git_for_each_ref} \
+ --format="%(push:remotename),%(push:remoteref)" \
+ refs/heads/push-simple)" &&
+ test from, = "$actual"
+ )
+'
+
+test_expect_success "${git_for_each_ref} --ignore-case ignores case" '
+ ${git_for_each_ref} --format="%(refname)" refs/heads/MAIN >actual &&
+ test_must_be_empty actual &&
+
+ echo refs/heads/main >expect &&
+ ${git_for_each_ref} --format="%(refname)" --ignore-case \
+ refs/heads/MAIN >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success "${git_for_each_ref} --omit-empty works" '
+ ${git_for_each_ref} --format="%(refname)" >actual &&
+ test_line_count -gt 1 actual &&
+ ${git_for_each_ref} --format="%(if:equals=refs/heads/main)%(refname)%(then)%(refname)%(end)" --omit-empty >actual &&
+ echo refs/heads/main >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success "${git_for_each_ref} --ignore-case works on multiple sort keys" '
+ # name refs numerically to avoid case-insensitive filesystem conflicts
+ nr=0 &&
+ for email in a A b B
+ do
+ for subject in a A b B
+ do
+ GIT_COMMITTER_EMAIL="$email@example.com" \
+ git tag -m "tag $subject" icase-$(printf %02d $nr) &&
+ nr=$((nr+1))||
+ return 1
+ done
+ done &&
+ ${git_for_each_ref} --ignore-case \
+ --format="%(taggeremail) %(subject) %(refname)" \
+ --sort=refname \
+ --sort=subject \
+ --sort=taggeremail \
+ refs/tags/icase-* >actual &&
+ cat >expect <<-\EOF &&
+ <a@example.com> tag a refs/tags/icase-00
+ <a@example.com> tag A refs/tags/icase-01
+ <A@example.com> tag a refs/tags/icase-04
+ <A@example.com> tag A refs/tags/icase-05
+ <a@example.com> tag b refs/tags/icase-02
+ <a@example.com> tag B refs/tags/icase-03
+ <A@example.com> tag b refs/tags/icase-06
+ <A@example.com> tag B refs/tags/icase-07
+ <b@example.com> tag a refs/tags/icase-08
+ <b@example.com> tag A refs/tags/icase-09
+ <B@example.com> tag a refs/tags/icase-12
+ <B@example.com> tag A refs/tags/icase-13
+ <b@example.com> tag b refs/tags/icase-10
+ <b@example.com> tag B refs/tags/icase-11
+ <B@example.com> tag b refs/tags/icase-14
+ <B@example.com> tag B refs/tags/icase-15
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success "${git_for_each_ref} reports broken tags" '
+ git tag -m "good tag" broken-tag-good HEAD &&
+ git cat-file tag broken-tag-good >good &&
+ sed s/commit/blob/ <good >bad &&
+ bad=$(git hash-object -w -t tag bad) &&
+ git update-ref refs/tags/broken-tag-bad $bad &&
+ test_must_fail ${git_for_each_ref} --format="%(*objectname)" \
+ refs/tags/broken-tag-*
+'
+
+test_expect_success 'set up tag with signature and no blank lines' '
+ git tag -F - fake-sig-no-blanks <<-\EOF
+ this is the subject
+ -----BEGIN PGP SIGNATURE-----
+ not a real signature, but we just care about the
+ subject/body parsing. It is important here that
+ there are no blank lines in the signature.
+ -----END PGP SIGNATURE-----
+ EOF
+'
+
+test_atom refs/tags/fake-sig-no-blanks contents:subject 'this is the subject'
+test_atom refs/tags/fake-sig-no-blanks contents:body ''
+test_atom refs/tags/fake-sig-no-blanks contents:signature "$sig"
+
+test_expect_success 'set up tag with CRLF signature' '
+ append_cr <<-\EOF |
+ this is the subject
+ -----BEGIN PGP SIGNATURE-----
+
+ not a real signature, but we just care about
+ the subject/body parsing. It is important here
+ that there is a blank line separating this
+ from the signature header.
+ -----END PGP SIGNATURE-----
+ EOF
+ git tag -F - --cleanup=verbatim fake-sig-crlf
+'
+
+test_atom refs/tags/fake-sig-crlf contents:subject 'this is the subject'
+test_atom refs/tags/fake-sig-crlf contents:body ''
+
+# CRLF is retained in the signature, so we have to pass our expected value
+# through append_cr. But test_atom requires a shell string, which means command
+# substitution, and the shell will strip trailing newlines from the output of
+# the substitution. Hack around it by adding and then removing a dummy line.
+sig_crlf="$(printf "%s" "$sig" | append_cr; echo dummy)"
+sig_crlf=${sig_crlf%dummy}
+test_atom refs/tags/fake-sig-crlf contents:signature "$sig_crlf"
+
+test_expect_success 'set up tag with signature and trailers' '
+ git tag -F - fake-sig-trailer <<-\EOF
+ this is the subject
+
+ this is the body
+
+ My-Trailer: foo
+ -----BEGIN PGP SIGNATURE-----
+
+ not a real signature, but we just care about the
+ subject/body/trailer parsing.
+ -----END PGP SIGNATURE-----
+ EOF
+'
+
+# use "separator=" here to suppress the terminating newline
+test_atom refs/tags/fake-sig-trailer trailers:separator= 'My-Trailer: foo'
+
+test_expect_success "${git_for_each_ref} --stdin: empty" '
+ >in &&
+ ${git_for_each_ref} --format="%(refname)" --stdin <in >actual &&
+ ${git_for_each_ref} --format="%(refname)" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success "${git_for_each_ref} --stdin: fails if extra args" '
+ >in &&
+ test_must_fail ${git_for_each_ref} --format="%(refname)" \
+ --stdin refs/heads/extra <in 2>err &&
+ grep "unknown arguments supplied with --stdin" err
+'
+
+test_expect_success "${git_for_each_ref} --stdin: matches" '
+ cat >in <<-EOF &&
+ refs/tags/multi*
+ refs/heads/amb*
+ EOF
+
+ cat >expect <<-EOF &&
+ refs/heads/ambiguous
+ refs/tags/multi-ref1-100000-user1
+ refs/tags/multi-ref1-100000-user2
+ refs/tags/multi-ref1-200000-user1
+ refs/tags/multi-ref1-200000-user2
+ refs/tags/multi-ref2-100000-user1
+ refs/tags/multi-ref2-100000-user2
+ refs/tags/multi-ref2-200000-user1
+ refs/tags/multi-ref2-200000-user2
+ refs/tags/multiline
+ EOF
+
+ ${git_for_each_ref} --format="%(refname)" --stdin <in >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success "${git_for_each_ref} with non-existing refs" '
+ cat >in <<-EOF &&
+ refs/heads/this-ref-does-not-exist
+ refs/tags/bogus
+ EOF
+
+ ${git_for_each_ref} --format="%(refname)" --stdin <in >actual &&
+ test_must_be_empty actual &&
+
+ xargs ${git_for_each_ref} --format="%(refname)" <in >actual &&
+ test_must_be_empty actual
+'
+
+test_expect_success "${git_for_each_ref} with nested tags" '
+ git tag -am "Normal tag" nested/base HEAD &&
+ git tag -am "Nested tag" nested/nest1 refs/tags/nested/base &&
+ git tag -am "Double nested tag" nested/nest2 refs/tags/nested/nest1 &&
+
+ head_oid="$(git rev-parse HEAD)" &&
+ base_tag_oid="$(git rev-parse refs/tags/nested/base)" &&
+ nest1_tag_oid="$(git rev-parse refs/tags/nested/nest1)" &&
+ nest2_tag_oid="$(git rev-parse refs/tags/nested/nest2)" &&
+
+ cat >expect <<-EOF &&
+ refs/tags/nested/base $base_tag_oid tag $head_oid commit
+ refs/tags/nested/nest1 $nest1_tag_oid tag $head_oid commit
+ refs/tags/nested/nest2 $nest2_tag_oid tag $head_oid commit
+ EOF
+
+ ${git_for_each_ref} \
+ --format="%(refname) %(objectname) %(objecttype) %(*objectname) %(*objecttype)" \
+ refs/tags/nested/ >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'is-base atom with non-commits' '
+ ${git_for_each_ref} --format="%(is-base:HEAD) %(refname)" >out 2>err &&
+ grep "(HEAD) refs/heads/main" out &&
+
+ test_line_count = 2 err &&
+ grep "error: object .* is a commit, not a blob" err &&
+ grep "error: bad tag pointer to" err
+'
+
+GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
+TRUSTLEVEL_FORMAT="%(signature:trustlevel)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
+
+test_expect_success GPG 'setup for signature atom using gpg' '
+ git checkout -b signed &&
+
+ test_when_finished "test_unconfig commit.gpgSign" &&
+
+ echo "1" >file &&
+ git add file &&
+ test_tick &&
+ git commit -S -m "file: 1" &&
+ git tag first-signed &&
+
+ echo "2" >file &&
+ test_tick &&
+ git commit -a -m "file: 2" &&
+ git tag second-unsigned &&
+
+ git config commit.gpgSign 1 &&
+ echo "3" >file &&
+ test_tick &&
+ git commit -a --no-gpg-sign -m "file: 3" &&
+ git tag third-unsigned &&
+
+ test_tick &&
+ git rebase -f HEAD^^ && git tag second-signed HEAD^ &&
+ git tag third-signed &&
+
+ echo "4" >file &&
+ test_tick &&
+ git commit -a -SB7227189 -m "file: 4" &&
+ git tag fourth-signed &&
+
+ echo "5" >file &&
+ test_tick &&
+ git commit -a --no-gpg-sign -m "file: 5" &&
+ git tag fifth-unsigned &&
+
+ echo "6" >file &&
+ test_tick &&
+ git commit -a --no-gpg-sign -m "file: 6" &&
+
+ test_tick &&
+ git rebase -f HEAD^^ &&
+ git tag fifth-signed HEAD^ &&
+ git tag sixth-signed &&
+
+ echo "7" >file &&
+ test_tick &&
+ git commit -a --no-gpg-sign -m "file: 7" &&
+ git tag seventh-unsigned
+'
+
+test_expect_success GPGSSH 'setup for signature atom using ssh' '
+ test_when_finished "test_unconfig gpg.format user.signingkey" &&
+
+ test_config gpg.format ssh &&
+ test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
+ echo "8" >file &&
+ test_tick &&
+ git add file &&
+ git commit -S -m "file: 8" &&
+ git tag eighth-signed-ssh
+'
+
+test_expect_success GPG2 'bare signature atom' '
+ git verify-commit first-signed 2>expect &&
+ echo >>expect &&
+ ${git_for_each_ref} refs/tags/first-signed \
+ --format="%(signature)" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show good signature with custom format' '
+ git verify-commit first-signed &&
+ cat >expect <<-\EOF &&
+ G
+ 13B6F51ECDDE430D
+ C O Mitter <committer@example.com>
+ 73D758744BE721698EC54E8713B6F51ECDDE430D
+ 73D758744BE721698EC54E8713B6F51ECDDE430D
+ EOF
+ ${git_for_each_ref} refs/tags/first-signed \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+test_expect_success GPGSSH 'show good signature with custom format with ssh' '
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
+ FINGERPRINT=$(ssh-keygen -lf "${GPGSSH_KEY_PRIMARY}" | awk "{print \$2;}") &&
+ cat >expect.tmpl <<-\EOF &&
+ G
+ FINGERPRINT
+ principal with number 1
+ FINGERPRINT
+
+ EOF
+ sed "s|FINGERPRINT|$FINGERPRINT|g" expect.tmpl >expect &&
+ ${git_for_each_ref} refs/tags/eighth-signed-ssh \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'signature atom with grade option and bad signature' '
+ git cat-file commit third-signed >raw &&
+ sed -e "s/^file: 3/file: 3 forged/" raw >forged1 &&
+ FORGED1=$(git hash-object -w -t commit forged1) &&
+ git update-ref refs/tags/third-signed "$FORGED1" &&
+ test_must_fail git verify-commit "$FORGED1" &&
+
+ cat >expect <<-\EOF &&
+ B
+ 13B6F51ECDDE430D
+ C O Mitter <committer@example.com>
+
+
+ EOF
+ ${git_for_each_ref} refs/tags/third-signed \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show untrusted signature with custom format' '
+ cat >expect <<-\EOF &&
+ U
+ 65A0EEA02E30CAD7
+ Eris Discordia <discord@example.net>
+ F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
+ D4BE22311AD3131E5EDA29A461092E85B7227189
+ EOF
+ ${git_for_each_ref} refs/tags/fourth-signed \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show untrusted signature with undefined trust level' '
+ cat >expect <<-\EOF &&
+ undefined
+ 65A0EEA02E30CAD7
+ Eris Discordia <discord@example.net>
+ F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
+ D4BE22311AD3131E5EDA29A461092E85B7227189
+ EOF
+ ${git_for_each_ref} refs/tags/fourth-signed \
+ --format="$TRUSTLEVEL_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show untrusted signature with ultimate trust level' '
+ cat >expect <<-\EOF &&
+ ultimate
+ 13B6F51ECDDE430D
+ C O Mitter <committer@example.com>
+ 73D758744BE721698EC54E8713B6F51ECDDE430D
+ 73D758744BE721698EC54E8713B6F51ECDDE430D
+ EOF
+ ${git_for_each_ref} refs/tags/sixth-signed \
+ --format="$TRUSTLEVEL_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show unknown signature with custom format' '
+ cat >expect <<-\EOF &&
+ E
+ 13B6F51ECDDE430D
+
+
+
+ EOF
+ GNUPGHOME="$GNUPGHOME_NOT_USED" ${git_for_each_ref} \
+ refs/tags/sixth-signed --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show lack of signature with custom format' '
+ cat >expect <<-\EOF &&
+ N
+
+
+
+
+ EOF
+ ${git_for_each_ref} refs/tags/seventh-unsigned \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_done
diff --git a/t/helper/meson.build b/t/helper/meson.build
index 5e83884246..675e64c010 100644
--- a/t/helper/meson.build
+++ b/t/helper/meson.build
@@ -34,12 +34,15 @@ test_tool_sources = [
'test-match-trees.c',
'test-mergesort.c',
'test-mktemp.c',
+ 'test-name-hash.c',
'test-online-cpus.c',
+ 'test-pack-deltas.c',
'test-pack-mtimes.c',
'test-parse-options.c',
'test-parse-pathspec-file.c',
'test-partial-clone.c',
'test-path-utils.c',
+ 'test-path-walk.c',
'test-pcre2-config.c',
'test-pkt-line.c',
'test-proc-receive.c',
@@ -74,18 +77,19 @@ test_tool_sources = [
'test-windows-named-pipe.c',
'test-write-cache.c',
'test-xml-encode.c',
+ 'test-zlib.c',
]
test_tool = executable('test-tool',
sources: test_tool_sources,
- dependencies: [libgit, common_main],
+ dependencies: [libgit_commonmain],
)
bin_wrappers += test_tool
test_dependencies += test_tool
test_fake_ssh = executable('test-fake-ssh',
sources: 'test-fake-ssh.c',
- dependencies: [libgit, common_main],
+ dependencies: [libgit_commonmain],
)
bin_wrappers += test_fake_ssh
test_dependencies += test_fake_ssh
diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c
index 6967c8e25c..81ed93a05c 100644
--- a/t/helper/test-advise.c
+++ b/t/helper/test-advise.c
@@ -3,6 +3,7 @@
#include "test-tool.h"
#include "advice.h"
#include "config.h"
+#include "environment.h"
#include "setup.h"
int cmd__advise_if_enabled(int argc, const char **argv)
@@ -11,7 +12,7 @@ int cmd__advise_if_enabled(int argc, const char **argv)
die("usage: %s <advice>", argv[0]);
setup_git_directory();
- git_config(git_default_config, NULL);
+ repo_config(the_repository, git_default_config, NULL);
/*
* Any advice type can be used for testing, but NESTED_TAG was
diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c
index 3f23f21072..16a01669e4 100644
--- a/t/helper/test-bitmap.c
+++ b/t/helper/test-bitmap.c
@@ -10,6 +10,11 @@ static int bitmap_list_commits(void)
return test_bitmap_commits(the_repository);
}
+static int bitmap_list_commits_with_offset(void)
+{
+ return test_bitmap_commits_with_offset(the_repository);
+}
+
static int bitmap_dump_hashes(void)
{
return test_bitmap_hashes(the_repository);
@@ -36,6 +41,8 @@ int cmd__bitmap(int argc, const char **argv)
if (argc == 2 && !strcmp(argv[1], "list-commits"))
return bitmap_list_commits();
+ if (argc == 2 && !strcmp(argv[1], "list-commits-with-offset"))
+ return bitmap_list_commits_with_offset();
if (argc == 2 && !strcmp(argv[1], "dump-hashes"))
return bitmap_dump_hashes();
if (argc == 2 && !strcmp(argv[1], "dump-pseudo-merges"))
@@ -46,6 +53,7 @@ int cmd__bitmap(int argc, const char **argv)
return bitmap_dump_pseudo_merge_objects(atoi(argv[2]));
usage("\ttest-tool bitmap list-commits\n"
+ "\ttest-tool bitmap list-commits-with-offset\n"
"\ttest-tool bitmap dump-hashes\n"
"\ttest-tool bitmap dump-pseudo-merges\n"
"\ttest-tool bitmap dump-pseudo-merge-commits <n>\n"
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index 14e075c1a1..3283544bd3 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -12,13 +12,13 @@ static struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS;
static void add_string_to_filter(const char *data, struct bloom_filter *filter) {
struct bloom_key key;
- fill_bloom_key(data, strlen(data), &key, &settings);
+ bloom_key_fill(&key, data, strlen(data), &settings);
printf("Hashes:");
for (size_t i = 0; i < settings.num_hashes; i++)
printf("0x%08x|", key.hashes[i]);
printf("\n");
add_key_to_filter(&key, filter, &settings);
- clear_bloom_key(&key);
+ bloom_key_clear(&key);
}
static void print_bloom_filter(struct bloom_filter *filter) {
@@ -44,7 +44,7 @@ static void get_bloom_filter_for_commit(const struct object_id *commit_oid)
print_bloom_filter(filter);
}
-static const char *bloom_usage = "\n"
+static const char *const bloom_usage = "\n"
" test-tool bloom get_murmur3 <string>\n"
" test-tool bloom get_murmur3_seven_highbit\n"
" test-tool bloom generate_filter <string> [<string>...]\n"
@@ -61,13 +61,13 @@ int cmd__bloom(int argc, const char **argv)
uint32_t hashed;
if (argc < 3)
usage(bloom_usage);
- hashed = murmur3_seeded_v2(0, argv[2], strlen(argv[2]));
+ hashed = test_bloom_murmur3_seeded(0, argv[2], strlen(argv[2]), 2);
printf("Murmur3 Hash with seed=0:0x%08x\n", hashed);
}
if (!strcmp(argv[1], "get_murmur3_seven_highbit")) {
uint32_t hashed;
- hashed = murmur3_seeded_v2(0, "\x99\xaa\xbb\xcc\xdd\xee\xff", 7);
+ hashed = test_bloom_murmur3_seeded(0, "\x99\xaa\xbb\xcc\xdd\xee\xff", 7, 2);
printf("Murmur3 Hash with seed=0:0x%08x\n", hashed);
}
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 75e028ab2a..9f8cca7c48 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -32,10 +32,10 @@
* ascending order of priority from a config_set
* constructed from files entered as arguments.
*
- * iterate -> iterate over all values using git_config(), and print some
+ * iterate -> iterate over all values using repo_config(), and print some
* data for each
*
- * git_config_int -> iterate over all values using git_config() and print the
+ * git_config_int -> iterate over all values using repo_config() and print the
* integer value for the entered key or die
*
* Examples:
@@ -110,7 +110,7 @@ int cmd__config(int argc, const char **argv)
fprintf(stderr, "Please, provide a command name on the command-line\n");
goto exit1;
} else if (argc == 3 && !strcmp(argv[1], "get_value")) {
- if (!git_config_get_value(argv[2], &v)) {
+ if (!repo_config_get_value(the_repository, argv[2], &v)) {
if (!v)
printf("(NULL)\n");
else
@@ -121,7 +121,7 @@ int cmd__config(int argc, const char **argv)
goto exit1;
}
} else if (argc == 3 && !strcmp(argv[1], "get_value_multi")) {
- if (!git_config_get_value_multi(argv[2], &strptr)) {
+ if (!repo_config_get_value_multi(the_repository, argv[2], &strptr)) {
for (i = 0; i < strptr->nr; i++) {
v = strptr->items[i].string;
if (!v)
@@ -137,7 +137,7 @@ int cmd__config(int argc, const char **argv)
} else if (argc == 3 && !strcmp(argv[1], "get")) {
int ret;
- if (!(ret = git_config_get(argv[2])))
+ if (!(ret = repo_config_get(the_repository, argv[2])))
goto exit0;
else if (ret == 1)
printf("Value not found for \"%s\"\n", argv[2]);
@@ -155,7 +155,7 @@ int cmd__config(int argc, const char **argv)
BUG("Key \"%s\" has unknown return %d", argv[2], ret);
goto exit1;
} else if (argc == 3 && !strcmp(argv[1], "get_int")) {
- if (!git_config_get_int(argv[2], &val)) {
+ if (!repo_config_get_int(the_repository, argv[2], &val)) {
printf("%d\n", val);
goto exit0;
} else {
@@ -163,7 +163,7 @@ int cmd__config(int argc, const char **argv)
goto exit1;
}
} else if (argc == 3 && !strcmp(argv[1], "get_bool")) {
- if (!git_config_get_bool(argv[2], &val)) {
+ if (!repo_config_get_bool(the_repository, argv[2], &val)) {
printf("%d\n", val);
goto exit0;
} else {
@@ -171,7 +171,7 @@ int cmd__config(int argc, const char **argv)
goto exit1;
}
} else if (argc == 3 && !strcmp(argv[1], "get_string")) {
- if (!git_config_get_string_tmp(argv[2], &v)) {
+ if (!repo_config_get_string_tmp(the_repository, argv[2], &v)) {
printf("%s\n", v);
goto exit0;
} else {
@@ -218,10 +218,10 @@ int cmd__config(int argc, const char **argv)
goto exit1;
}
} else if (!strcmp(argv[1], "iterate")) {
- git_config(iterate_cb, NULL);
+ repo_config(the_repository, iterate_cb, NULL);
goto exit0;
} else if (argc == 3 && !strcmp(argv[1], "git_config_int")) {
- git_config(parse_int_cb, (void *) argv[2]);
+ repo_config(the_repository, parse_int_cb, (void *) argv[2]);
goto exit0;
}
diff --git a/t/helper/test-csprng.c b/t/helper/test-csprng.c
index a4a0aca617..c86dcc4870 100644
--- a/t/helper/test-csprng.c
+++ b/t/helper/test-csprng.c
@@ -15,7 +15,7 @@ int cmd__csprng(int argc, const char **argv)
while (count) {
unsigned long chunk = count < sizeof(buf) ? count : sizeof(buf);
- if (csprng_bytes(buf, chunk) < 0) {
+ if (csprng_bytes(buf, chunk, 0) < 0) {
perror("failed to read");
return 5;
}
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index f25512de9a..87d2ad6fca 100644
--- a/t/helper/test-date.c
+++ b/t/helper/test-date.c
@@ -2,7 +2,7 @@
#include "date.h"
#include "trace.h"
-static const char *usage_msg = "\n"
+static const char *const usage_msg = "\n"
" test-tool date relative [time_t]...\n"
" test-tool date human [time_t]...\n"
" test-tool date show:<format> [time_t]...\n"
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index 6bc787a474..52ea00c937 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -11,6 +11,7 @@
#include "test-tool.h"
#include "git-compat-util.h"
#include "delta.h"
+#include "strbuf.h"
static const char usage_str[] =
"test-tool delta (-d|-p) <from_file> <data_file> <out_file>";
@@ -18,68 +19,38 @@ static const char usage_str[] =
int cmd__delta(int argc, const char **argv)
{
int fd;
- struct stat st;
- void *from_buf = NULL, *data_buf = NULL, *out_buf = NULL;
- unsigned long from_size, data_size, out_size;
- int ret = 1;
+ struct strbuf from = STRBUF_INIT, data = STRBUF_INIT;
+ char *out_buf;
+ unsigned long out_size;
- if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) {
- fprintf(stderr, "usage: %s\n", usage_str);
- return 1;
- }
+ if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p")))
+ usage(usage_str);
- fd = open(argv[2], O_RDONLY);
- if (fd < 0 || fstat(fd, &st)) {
- perror(argv[2]);
- return 1;
- }
- from_size = st.st_size;
- from_buf = xmalloc(from_size);
- if (read_in_full(fd, from_buf, from_size) < 0) {
- perror(argv[2]);
- close(fd);
- goto cleanup;
- }
- close(fd);
-
- fd = open(argv[3], O_RDONLY);
- if (fd < 0 || fstat(fd, &st)) {
- perror(argv[3]);
- goto cleanup;
- }
- data_size = st.st_size;
- data_buf = xmalloc(data_size);
- if (read_in_full(fd, data_buf, data_size) < 0) {
- perror(argv[3]);
- close(fd);
- goto cleanup;
- }
- close(fd);
+ if (strbuf_read_file(&from, argv[2], 0) < 0)
+ die_errno("unable to read '%s'", argv[2]);
+ if (strbuf_read_file(&data, argv[3], 0) < 0)
+ die_errno("unable to read '%s'", argv[3]);
if (argv[1][1] == 'd')
- out_buf = diff_delta(from_buf, from_size,
- data_buf, data_size,
+ out_buf = diff_delta(from.buf, from.len,
+ data.buf, data.len,
&out_size, 0);
else
- out_buf = patch_delta(from_buf, from_size,
- data_buf, data_size,
+ out_buf = patch_delta(from.buf, from.len,
+ data.buf, data.len,
&out_size);
- if (!out_buf) {
- fprintf(stderr, "delta operation failed (returned NULL)\n");
- goto cleanup;
- }
+ if (!out_buf)
+ die("delta operation failed (returned NULL)");
- fd = open (argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666);
- if (fd < 0 || write_in_full(fd, out_buf, out_size) < 0) {
- perror(argv[4]);
- goto cleanup;
- }
+ fd = xopen(argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ if (write_in_full(fd, out_buf, out_size) < 0)
+ die_errno("write(%s)", argv[4]);
+ if (close(fd) < 0)
+ die_errno("close(%s)", argv[4]);
- ret = 0;
-cleanup:
- free(from_buf);
- free(data_buf);
+ strbuf_release(&from);
+ strbuf_release(&data);
free(out_buf);
- return ret;
+ return 0;
}
diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c
index 6b297bd753..8d46e8ba40 100644
--- a/t/helper/test-dir-iterator.c
+++ b/t/helper/test-dir-iterator.c
@@ -53,6 +53,7 @@ int cmd__dir_iterator(int argc, const char **argv)
printf("(%s) [%s] %s\n", diter->relative_path, diter->basename,
diter->path.buf);
}
+ dir_iterator_free(diter);
if (iter_status != ITER_DONE) {
printf("dir_iterator_advance failure\n");
diff --git a/t/helper/test-find-pack.c b/t/helper/test-find-pack.c
index 85a69a4e55..611a13a326 100644
--- a/t/helper/test-find-pack.c
+++ b/t/helper/test-find-pack.c
@@ -2,7 +2,7 @@
#include "test-tool.h"
#include "object-name.h"
-#include "object-store.h"
+#include "odb.h"
#include "packfile.h"
#include "parse-options.h"
#include "setup.h"
@@ -15,7 +15,7 @@
* packfiles containing the object is not <n>.
*/
-static const char *find_pack_usage[] = {
+static const char *const find_pack_usage[] = {
"test-tool find-pack [--check-count <n>] <object>",
NULL
};
diff --git a/t/helper/test-getcwd.c b/t/helper/test-getcwd.c
index d680038a78..cd4d424079 100644
--- a/t/helper/test-getcwd.c
+++ b/t/helper/test-getcwd.c
@@ -2,7 +2,7 @@
#include "git-compat-util.h"
#include "parse-options.h"
-static const char *getcwd_usage[] = {
+static const char *const getcwd_usage[] = {
"test-tool getcwd",
NULL
};
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index 80df1aae66..fbf67fe6bd 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -3,16 +3,16 @@
#define NUM_SECONDS 3
-static inline void compute_hash(const struct git_hash_algo *algo, git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
+static inline void compute_hash(const struct git_hash_algo *algo, struct git_hash_ctx *ctx, uint8_t *final, const void *p, size_t len)
{
algo->init_fn(ctx);
- algo->update_fn(ctx, p, len);
- algo->final_fn(final, ctx);
+ git_hash_update(ctx, p, len);
+ git_hash_final(final, ctx);
}
int cmd__hash_speed(int ac, const char **av)
{
- git_hash_ctx ctx;
+ struct git_hash_ctx ctx;
unsigned char hash[GIT_MAX_RAWSZ];
clock_t initial, start, end;
unsigned bufsizes[] = { 64, 256, 1024, 8192, 16384 };
diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c
index 45d829c908..f0ee61c8b4 100644
--- a/t/helper/test-hash.c
+++ b/t/helper/test-hash.c
@@ -1,14 +1,16 @@
#include "test-tool.h"
#include "hex.h"
-int cmd_hash_impl(int ac, const char **av, int algo)
+int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
{
- git_hash_ctx ctx;
+ struct git_hash_ctx ctx;
unsigned char hash[GIT_MAX_HEXSZ];
unsigned bufsz = 8192;
int binary = 0;
char *buffer;
const struct git_hash_algo *algop = &hash_algos[algo];
+ if (unsafe)
+ algop = unsafe_hash_algo(algop);
if (ac == 2) {
if (!strcmp(av[1], "-b"))
@@ -46,9 +48,9 @@ int cmd_hash_impl(int ac, const char **av, int algo)
}
if (this_sz == 0)
break;
- algop->update_fn(&ctx, buffer, this_sz);
+ git_hash_update(&ctx, buffer, this_sz);
}
- algop->final_fn(hash, &ctx);
+ git_hash_final(hash, &ctx);
if (binary)
fwrite(hash, 1, algop->rawsz, stdout);
diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c
index 7782ae585e..56d223a283 100644
--- a/t/helper/test-hashmap.c
+++ b/t/helper/test-hashmap.c
@@ -137,6 +137,11 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
* Read stdin line by line and print result of commands to stdout:
*
* perfhashmap method rounds -> test hashmap.[ch] performance
+ *
+ * NOTE: this is not used by any of our mechanized build & test
+ * procedure, after 3469a236 (t: port helper/test-hashmap.c to
+ * unit-tests/t-hashmap.c, 2024-08-03). See the log message of that
+ * commit for the reason why this is still here.
*/
int cmd__hashmap(int argc UNUSED, const char **argv UNUSED)
{
@@ -149,8 +154,8 @@ int cmd__hashmap(int argc UNUSED, const char **argv UNUSED)
/* break line into command and up to two parameters */
string_list_setlen(&parts, 0);
- string_list_split_in_place(&parts, line.buf, DELIM, 2);
- string_list_remove_empty_items(&parts, 0);
+ string_list_split_in_place_f(&parts, line.buf, DELIM, 2,
+ STRING_LIST_SPLIT_NONEMPTY);
/* ignore empty lines */
if (!parts.nr)
diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c
index a288069b04..f8316a7d29 100644
--- a/t/helper/test-json-writer.c
+++ b/t/helper/test-json-writer.c
@@ -492,8 +492,8 @@ static int scripted(void)
/* break line into command and zero or more tokens */
string_list_setlen(&parts, 0);
- string_list_split_in_place(&parts, line, " ", -1);
- string_list_remove_empty_items(&parts, 0);
+ string_list_split_in_place_f(&parts, line, " ", -1,
+ STRING_LIST_SPLIT_NONEMPTY);
/* ignore empty lines */
if (!parts.nr || !*parts.items[0].string)
diff --git a/t/helper/test-name-hash.c b/t/helper/test-name-hash.c
new file mode 100644
index 0000000000..af1d52de10
--- /dev/null
+++ b/t/helper/test-name-hash.c
@@ -0,0 +1,23 @@
+/*
+ * test-name-hash.c: Read a list of paths over stdin and report on their
+ * name-hash and full name-hash.
+ */
+
+#include "test-tool.h"
+#include "git-compat-util.h"
+#include "pack-objects.h"
+#include "strbuf.h"
+
+int cmd__name_hash(int argc UNUSED, const char **argv UNUSED)
+{
+ struct strbuf line = STRBUF_INIT;
+
+ while (!strbuf_getline(&line, stdin)) {
+ printf("%10u ", pack_name_hash(line.buf));
+ printf("%10u ", pack_name_hash_v2((unsigned const char *)line.buf));
+ printf("%s\n", line.buf);
+ }
+
+ strbuf_release(&line);
+ return 0;
+}
diff --git a/t/helper/test-pack-deltas.c b/t/helper/test-pack-deltas.c
new file mode 100644
index 0000000000..4caa024b1e
--- /dev/null
+++ b/t/helper/test-pack-deltas.c
@@ -0,0 +1,148 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
+#include "test-tool.h"
+#include "git-compat-util.h"
+#include "delta.h"
+#include "git-zlib.h"
+#include "hash.h"
+#include "hex.h"
+#include "pack.h"
+#include "pack-objects.h"
+#include "parse-options.h"
+#include "setup.h"
+#include "strbuf.h"
+#include "string-list.h"
+
+static const char *usage_str[] = {
+ "test-tool pack-deltas --num-objects <num-objects>",
+ NULL
+};
+
+static unsigned long do_compress(void **pptr, unsigned long size)
+{
+ git_zstream stream;
+ void *in, *out;
+ unsigned long maxsize;
+
+ git_deflate_init(&stream, 1);
+ maxsize = git_deflate_bound(&stream, size);
+
+ in = *pptr;
+ out = xmalloc(maxsize);
+ *pptr = out;
+
+ stream.next_in = in;
+ stream.avail_in = size;
+ stream.next_out = out;
+ stream.avail_out = maxsize;
+ while (git_deflate(&stream, Z_FINISH) == Z_OK)
+ ; /* nothing */
+ git_deflate_end(&stream);
+
+ free(in);
+ return stream.total_out;
+}
+
+static void write_ref_delta(struct hashfile *f,
+ struct object_id *oid,
+ struct object_id *base)
+{
+ unsigned char header[MAX_PACK_OBJECT_HEADER];
+ unsigned long size, base_size, delta_size, compressed_size, hdrlen;
+ enum object_type type;
+ void *base_buf, *delta_buf;
+ void *buf = repo_read_object_file(the_repository,
+ oid, &type,
+ &size);
+
+ if (!buf)
+ die("unable to read %s", oid_to_hex(oid));
+
+ base_buf = repo_read_object_file(the_repository,
+ base, &type,
+ &base_size);
+
+ if (!base_buf)
+ die("unable to read %s", oid_to_hex(base));
+
+ delta_buf = diff_delta(base_buf, base_size,
+ buf, size, &delta_size, 0);
+
+ compressed_size = do_compress(&delta_buf, delta_size);
+
+ hdrlen = encode_in_pack_object_header(header, sizeof(header),
+ OBJ_REF_DELTA, delta_size);
+ hashwrite(f, header, hdrlen);
+ hashwrite(f, base->hash, the_repository->hash_algo->rawsz);
+ hashwrite(f, delta_buf, compressed_size);
+
+ free(buf);
+ free(base_buf);
+ free(delta_buf);
+}
+
+int cmd__pack_deltas(int argc, const char **argv)
+{
+ int num_objects = -1;
+ struct hashfile *f;
+ struct strbuf line = STRBUF_INIT;
+ struct option options[] = {
+ OPT_INTEGER('n', "num-objects", &num_objects, N_("the number of objects to write")),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, NULL,
+ options, usage_str, 0);
+
+ if (argc || num_objects < 0)
+ usage_with_options(usage_str, options);
+
+ setup_git_directory();
+
+ f = hashfd(the_repository->hash_algo, 1, "<stdout>");
+ write_pack_header(f, num_objects);
+
+ /* Read each line from stdin into 'line' */
+ while (strbuf_getline_lf(&line, stdin) != EOF) {
+ const char *type_str, *content_oid_str, *base_oid_str = NULL;
+ struct object_id content_oid, base_oid;
+ struct string_list items = STRING_LIST_INIT_NODUP;
+ /*
+ * Tokenize into two or three parts:
+ * 1. REF_DELTA, OFS_DELTA, or FULL.
+ * 2. The object ID for the content object.
+ * 3. The object ID for the base object (optional).
+ */
+ if (string_list_split_in_place(&items, line.buf, " ", 3) < 0)
+ die("invalid input format: %s", line.buf);
+
+ if (items.nr < 2)
+ die("invalid input format: %s", line.buf);
+
+ type_str = items.items[0].string;
+ content_oid_str = items.items[1].string;
+
+ if (get_oid_hex(content_oid_str, &content_oid))
+ die("invalid object: %s", content_oid_str);
+ if (items.nr >= 3) {
+ base_oid_str = items.items[2].string;
+ if (get_oid_hex(base_oid_str, &base_oid))
+ die("invalid object: %s", base_oid_str);
+ }
+ string_list_clear(&items, 0);
+
+ if (!strcmp(type_str, "REF_DELTA"))
+ write_ref_delta(f, &content_oid, &base_oid);
+ else if (!strcmp(type_str, "OFS_DELTA"))
+ die("OFS_DELTA not implemented");
+ else if (!strcmp(type_str, "FULL"))
+ die("FULL not implemented");
+ else
+ die("unknown pack type: %s", type_str);
+ }
+
+ finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK,
+ CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
+ strbuf_release(&line);
+ return 0;
+}
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index f8f9afbb5b..d51aaa3dc4 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
-#include "object-store-ll.h"
+#include "odb.h"
#include "packfile.h"
#include "pack-mtimes.h"
#include "setup.h"
@@ -24,7 +24,7 @@ static void dump_mtimes(struct packed_git *p)
}
}
-static const char *pack_mtimes_usage = "\n"
+static const char *const pack_mtimes_usage = "\n"
" test-tool pack-mtimes <pack-name.mtimes>";
int cmd__pack_mtimes(int argc, const char **argv)
diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c
index bfe45ec68b..68579d83f3 100644
--- a/t/helper/test-parse-options.c
+++ b/t/helper/test-parse-options.c
@@ -6,7 +6,7 @@
static int boolean = 0;
static int integer = 0;
-static unsigned long magnitude = 0;
+static unsigned long unsigned_integer = 0;
static timestamp_t timestamp;
static int abbrev = 7;
static int verbose = -1; /* unspecified */
@@ -120,26 +120,45 @@ int cmd__parse_options(int argc, const char **argv)
};
struct string_list expect = STRING_LIST_INIT_NODUP;
struct string_list list = STRING_LIST_INIT_NODUP;
+ uint16_t u16 = 0;
+ int16_t i16 = 0;
struct option options[] = {
OPT_BOOL(0, "yes", &boolean, "get a boolean"),
OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"),
- { OPTION_SET_INT, 'B', "no-fear", &boolean, NULL,
- "be brave", PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
+ {
+ .type = OPTION_SET_INT,
+ .short_name = 'B',
+ .long_name = "no-fear",
+ .value = &boolean,
+ .precision = sizeof(boolean),
+ .help = "be brave",
+ .flags = PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ .defval = 1,
+ },
OPT_COUNTUP('b', "boolean", &boolean, "increment by one"),
OPT_BIT('4', "or4", &boolean,
"bitwise-or boolean with ...0100", 4),
OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4),
OPT_GROUP(""),
OPT_INTEGER('i', "integer", &integer, "get a integer"),
+ OPT_INTEGER(0, "i16", &i16, "get a 16 bit integer"),
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
- OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
+ OPT_UNSIGNED('u', "unsigned", &unsigned_integer, "get an unsigned integer"),
+ OPT_UNSIGNED(0, "u16", &u16, "get a 16 bit unsigned integer"),
OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
OPT_CMDMODE(0, "mode1", &integer, "set integer to 1 (cmdmode option)", 1),
OPT_CMDMODE(0, "mode2", &integer, "set integer to 2 (cmdmode option)", 2),
- OPT_CALLBACK_F(0, "mode34", &integer, "(3|4)",
- "set integer to 3 or 4 (cmdmode option)",
- PARSE_OPT_CMDMODE, mode34_callback),
+ {
+ .type = OPTION_CALLBACK,
+ .long_name = "mode34",
+ .value = &integer,
+ .precision = sizeof(integer),
+ .argh = "(3|4)",
+ .help = "set integer to 3 or 4 (cmdmode option)",
+ .flags = PARSE_OPT_CMDMODE,
+ .callback = mode34_callback,
+ },
OPT_CALLBACK('L', "length", &integer, "str",
"get length of <str>", length_callback),
OPT_FILENAME('F', "file", &file, "set file to <file>"),
@@ -155,12 +174,30 @@ int cmd__parse_options(int argc, const char **argv)
OPT_GROUP("Magic arguments"),
OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
number_callback),
- { OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b",
- PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH },
- { OPTION_COUNTUP, 0, "ambiguous", &ambiguous, NULL,
- "positive ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG },
- { OPTION_COUNTUP, 0, "no-ambiguous", &ambiguous, NULL,
- "negative ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG },
+ {
+ .type = OPTION_COUNTUP,
+ .short_name = '+',
+ .value = &boolean,
+ .precision = sizeof(boolean),
+ .help = "same as -b",
+ .flags = PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH,
+ },
+ {
+ .type = OPTION_COUNTUP,
+ .long_name = "ambiguous",
+ .value = &ambiguous,
+ .precision = sizeof(ambiguous),
+ .help = "positive ambiguity",
+ .flags = PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ },
+ {
+ .type = OPTION_COUNTUP,
+ .long_name = "no-ambiguous",
+ .value = &ambiguous,
+ .precision = sizeof(ambiguous),
+ .help = "negative ambiguity",
+ .flags = PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ },
OPT_GROUP("Standard options"),
OPT__ABBREV(&abbrev),
OPT__VERBOSE(&verbose, "be verbose"),
@@ -188,7 +225,9 @@ int cmd__parse_options(int argc, const char **argv)
}
show(&expect, &ret, "boolean: %d", boolean);
show(&expect, &ret, "integer: %d", integer);
- show(&expect, &ret, "magnitude: %lu", magnitude);
+ show(&expect, &ret, "i16: %"PRIdMAX, (intmax_t) i16);
+ show(&expect, &ret, "unsigned: %lu", unsigned_integer);
+ show(&expect, &ret, "u16: %"PRIuMAX, (uintmax_t) u16);
show(&expect, &ret, "timestamp: %"PRItime, timestamp);
show(&expect, &ret, "string: %s", string ? string : "(not set)");
show(&expect, &ret, "abbrev: %d", abbrev);
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index a1af9710c3..d848800749 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "repository.h"
-#include "object-store-ll.h"
+#include "odb.h"
#include "setup.h"
/*
@@ -23,7 +23,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
die("could not init repo");
if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
die("could not parse oid");
- if (oid_object_info_extended(&r, &oid, &oi, 0))
+ if (odb_read_object_info_extended(r.objects, &oid, &oi, 0))
die("could not obtain object info");
printf("%d\n", (int) size);
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 72ac8d1b1b..f5f33751da 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -323,6 +323,19 @@ int cmd__path_utils(int argc, const char **argv)
return 0;
}
+ if (argc >= 2 && !strcmp(argv[1], "readlink")) {
+ struct strbuf target = STRBUF_INIT;
+ while (argc > 2) {
+ if (strbuf_readlink(&target, argv[2], 0) < 0)
+ die_errno("cannot read link at '%s'", argv[2]);
+ puts(target.buf);
+ argc--;
+ argv++;
+ }
+ strbuf_release(&target);
+ return 0;
+ }
+
if (argc >= 2 && !strcmp(argv[1], "absolute_path")) {
while (argc > 2) {
puts(absolute_path(argv[2]));
@@ -335,6 +348,7 @@ int cmd__path_utils(int argc, const char **argv)
if (argc == 4 && !strcmp(argv[1], "longest_ancestor_length")) {
int len;
struct string_list ceiling_dirs = STRING_LIST_INIT_DUP;
+ const char path_sep[] = { PATH_SEP, '\0' };
char *path = xstrdup(argv[2]);
/*
@@ -349,7 +363,7 @@ int cmd__path_utils(int argc, const char **argv)
*/
if (normalize_path_copy(path, path))
die("Path \"%s\" could not be normalized", argv[2]);
- string_list_split(&ceiling_dirs, argv[3], PATH_SEP, -1);
+ string_list_split(&ceiling_dirs, argv[3], path_sep, -1);
filter_string_list(&ceiling_dirs, 0,
normalize_ceiling_entry, NULL);
len = longest_ancestor_length(path, &ceiling_dirs);
@@ -504,6 +518,25 @@ int cmd__path_utils(int argc, const char **argv)
return !!res;
}
+ if (argc > 1 && !strcmp(argv[1], "is_path_owned_by_current_user")) {
+ int res = 0;
+
+ for (int i = 2; i < argc; i++) {
+ struct strbuf buf = STRBUF_INIT;
+
+ if (is_path_owned_by_current_user(argv[i], &buf))
+ printf("'%s' is owned by current SID\n", argv[i]);
+ else {
+ printf("'%s' is not owned by current SID: %s\n", argv[i], buf.buf);
+ res = 1;
+ }
+
+ strbuf_release(&buf);
+ }
+
+ return res;
+ }
+
fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
argv[1] ? argv[1] : "(there was none)");
return 1;
diff --git a/t/helper/test-path-walk.c b/t/helper/test-path-walk.c
new file mode 100644
index 0000000000..fe63002c2b
--- /dev/null
+++ b/t/helper/test-path-walk.c
@@ -0,0 +1,134 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
+#include "test-tool.h"
+#include "dir.h"
+#include "environment.h"
+#include "hex.h"
+#include "object-name.h"
+#include "object.h"
+#include "pretty.h"
+#include "revision.h"
+#include "setup.h"
+#include "parse-options.h"
+#include "strbuf.h"
+#include "path-walk.h"
+#include "oid-array.h"
+
+static const char * const path_walk_usage[] = {
+ N_("test-tool path-walk <options> -- <revision-options>"),
+ NULL
+};
+
+struct path_walk_test_data {
+ uintmax_t batch_nr;
+
+ uintmax_t commit_nr;
+ uintmax_t tree_nr;
+ uintmax_t blob_nr;
+ uintmax_t tag_nr;
+};
+
+static int emit_block(const char *path, struct oid_array *oids,
+ enum object_type type, void *data)
+{
+ struct path_walk_test_data *tdata = data;
+ const char *typestr;
+
+ if (type == OBJ_TREE)
+ tdata->tree_nr += oids->nr;
+ else if (type == OBJ_BLOB)
+ tdata->blob_nr += oids->nr;
+ else if (type == OBJ_COMMIT)
+ tdata->commit_nr += oids->nr;
+ else if (type == OBJ_TAG)
+ tdata->tag_nr += oids->nr;
+ else
+ BUG("we do not understand this type");
+
+ typestr = type_name(type);
+
+ /* This should never be output during tests. */
+ if (!oids->nr)
+ printf("%"PRIuMAX":%s:%s:EMPTY\n",
+ tdata->batch_nr, typestr, path);
+
+ for (size_t i = 0; i < oids->nr; i++) {
+ struct object *o = lookup_unknown_object(the_repository,
+ &oids->oid[i]);
+ printf("%"PRIuMAX":%s:%s:%s%s\n",
+ tdata->batch_nr, typestr, path,
+ oid_to_hex(&oids->oid[i]),
+ o->flags & UNINTERESTING ? ":UNINTERESTING" : "");
+ }
+
+ tdata->batch_nr++;
+ return 0;
+}
+
+int cmd__path_walk(int argc, const char **argv)
+{
+ int res, stdin_pl = 0;
+ struct rev_info revs = REV_INFO_INIT;
+ struct path_walk_info info = PATH_WALK_INFO_INIT;
+ struct path_walk_test_data data = { 0 };
+ struct option options[] = {
+ OPT_BOOL(0, "blobs", &info.blobs,
+ N_("toggle inclusion of blob objects")),
+ OPT_BOOL(0, "commits", &info.commits,
+ N_("toggle inclusion of commit objects")),
+ OPT_BOOL(0, "tags", &info.tags,
+ N_("toggle inclusion of tag objects")),
+ OPT_BOOL(0, "trees", &info.trees,
+ N_("toggle inclusion of tree objects")),
+ OPT_BOOL(0, "prune", &info.prune_all_uninteresting,
+ N_("toggle pruning of uninteresting paths")),
+ OPT_BOOL(0, "edge-aggressive", &info.edge_aggressive,
+ N_("toggle aggressive edge walk")),
+ OPT_BOOL(0, "stdin-pl", &stdin_pl,
+ N_("read a pattern list over stdin")),
+ OPT_END(),
+ };
+
+ setup_git_directory();
+ revs.repo = the_repository;
+
+ argc = parse_options(argc, argv, NULL,
+ options, path_walk_usage,
+ PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_KEEP_ARGV0);
+
+ if (argc > 1)
+ setup_revisions(argc, argv, &revs, NULL);
+ else
+ usage(path_walk_usage[0]);
+
+ info.revs = &revs;
+ info.path_fn = emit_block;
+ info.path_fn_data = &data;
+
+ if (stdin_pl) {
+ struct strbuf in = STRBUF_INIT;
+ CALLOC_ARRAY(info.pl, 1);
+
+ info.pl->use_cone_patterns = 1;
+
+ strbuf_fread(&in, 2048, stdin);
+ add_patterns_from_buffer(in.buf, in.len, "", 0, info.pl);
+ strbuf_release(&in);
+ }
+
+ res = walk_objects_by_path(&info);
+
+ printf("commits:%" PRIuMAX "\n"
+ "trees:%" PRIuMAX "\n"
+ "blobs:%" PRIuMAX "\n"
+ "tags:%" PRIuMAX "\n",
+ data.commit_nr, data.tree_nr, data.blob_nr, data.tag_nr);
+
+ if (info.pl) {
+ clear_pattern_list(info.pl);
+ free(info.pl);
+ }
+
+ release_revisions(&revs);
+ return res;
+}
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index 3703f734f3..8eccc34216 100644
--- a/t/helper/test-proc-receive.c
+++ b/t/helper/test-proc-receive.c
@@ -6,7 +6,7 @@
#include "sigchain.h"
#include "string-list.h"
-static const char *proc_receive_usage[] = {
+static const char *const proc_receive_usage[] = {
"test-tool proc-receive [<options>]",
NULL
};
diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
index 44be2645e9..1f75b7bd19 100644
--- a/t/helper/test-progress.c
+++ b/t/helper/test-progress.c
@@ -17,10 +17,14 @@
*
* See 't0500-progress-display.sh' for examples.
*/
+
+#define USE_THE_REPOSITORY_VARIABLE
#define GIT_TEST_PROGRESS_ONLY
+
#include "test-tool.h"
#include "parse-options.h"
#include "progress.h"
+#include "repository.h"
#include "strbuf.h"
#include "string-list.h"
@@ -64,7 +68,7 @@ int cmd__progress(int argc, const char **argv)
else
die("invalid input: '%s'", line.buf);
- progress = start_progress(title, total);
+ progress = start_progress(the_repository, title, total);
} else if (skip_prefix(line.buf, "progress ", (const char **) &end)) {
uint64_t item_count = strtoull(end, &end, 10);
if (*end != '\0')
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 01cf77ae65..028ec00306 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -35,7 +35,7 @@ int cmd__reach(int ac, const char **av)
struct commit_list *X, *Y;
struct object_array X_obj = OBJECT_ARRAY_INIT;
struct commit **X_array, **Y_array;
- int X_nr, X_alloc, Y_nr, Y_alloc;
+ size_t X_nr, X_alloc, Y_nr, Y_alloc;
struct strbuf buf = STRBUF_INIT;
struct repository *r = the_repository;
@@ -157,7 +157,7 @@ int cmd__reach(int ac, const char **av)
clear_contains_cache(&cache);
} else if (!strcmp(av[1], "get_reachable_subset")) {
const int reachable_flag = 1;
- int i, count = 0;
+ int count = 0;
struct commit_list *current;
struct commit_list *list = get_reachable_subset(X_array, X_nr,
Y_array, Y_nr,
@@ -169,7 +169,7 @@ int cmd__reach(int ac, const char **av)
oid_to_hex(&list->item->object.oid));
count++;
}
- for (i = 0; i < Y_nr; i++) {
+ for (size_t i = 0; i < Y_nr; i++) {
if (Y_array[i]->object.flags & reachable_flag)
count--;
}
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index e277dde8e7..9ae71cefb3 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -2,6 +2,7 @@
#include "test-tool.h"
#include "config.h"
+#include "environment.h"
#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
@@ -19,7 +20,7 @@ int cmd__read_cache(int argc, const char **argv)
if (argc == 2)
cnt = strtol(argv[1], NULL, 0);
setup_git_directory();
- git_config(git_default_config, NULL);
+ repo_config(the_repository, git_default_config, NULL);
for (i = 0; i < cnt; i++) {
repo_read_index(the_repository);
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 811dde1cb3..6a5f64e473 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -3,7 +3,7 @@
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
-#include "object-store-ll.h"
+#include "odb.h"
#include "bloom.h"
#include "setup.h"
@@ -73,15 +73,15 @@ static void dump_graph_bloom_filters(struct commit_graph *graph)
int cmd__read_graph(int argc, const char **argv)
{
struct commit_graph *graph = NULL;
- struct object_directory *odb;
+ struct odb_source *source;
int ret = 0;
setup_git_directory();
- odb = the_repository->objects->odb;
+ source = the_repository->objects->sources;
prepare_repo_settings(the_repository);
- graph = read_commit_graph_one(the_repository, odb);
+ graph = read_commit_graph_one(source);
if (!graph) {
ret = 1;
goto done;
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index fc63236961..6de5d1665a 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -4,21 +4,31 @@
#include "hex.h"
#include "midx.h"
#include "repository.h"
-#include "object-store-ll.h"
+#include "odb.h"
#include "pack-bitmap.h"
#include "packfile.h"
#include "setup.h"
#include "gettext.h"
#include "pack-revindex.h"
+static struct multi_pack_index *setup_midx(const char *object_dir)
+{
+ struct odb_source *source;
+ setup_git_directory();
+ source = odb_find_source(the_repository->objects, object_dir);
+ if (!source)
+ source = odb_add_to_alternates_memory(the_repository->objects,
+ object_dir);
+ return load_multi_pack_index(source);
+}
+
static int read_midx_file(const char *object_dir, const char *checksum,
int show_objects)
{
uint32_t i;
struct multi_pack_index *m;
- setup_git_directory();
- m = load_multi_pack_index(the_repository, object_dir, 1);
+ m = setup_midx(object_dir);
if (!m)
return 1;
@@ -56,7 +66,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,
for (i = 0; i < m->num_packs; i++)
printf("%s\n", m->pack_names[i]);
- printf("object-dir: %s\n", m->object_dir);
+ printf("object-dir: %s\n", m->source->path);
if (show_objects) {
struct object_id oid;
@@ -65,7 +75,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,
for (i = 0; i < m->num_objects; i++) {
nth_midxed_object_oid(&oid, m,
i + m->num_objects_in_base);
- fill_midx_entry(the_repository, &oid, &e, m);
+ fill_midx_entry(m, &oid, &e);
printf("%s %"PRIu64"\t%s\n",
oid_to_hex(&oid), e.offset, e.p->pack_name);
@@ -81,8 +91,7 @@ static int read_midx_checksum(const char *object_dir)
{
struct multi_pack_index *m;
- setup_git_directory();
- m = load_multi_pack_index(the_repository, object_dir, 1);
+ m = setup_midx(object_dir);
if (!m)
return 1;
printf("%s\n", hash_to_hex(get_midx_checksum(m)));
@@ -96,9 +105,7 @@ static int read_midx_preferred_pack(const char *object_dir)
struct multi_pack_index *midx = NULL;
uint32_t preferred_pack;
- setup_git_directory();
-
- midx = load_multi_pack_index(the_repository, object_dir, 1);
+ midx = setup_midx(object_dir);
if (!midx)
return 1;
@@ -119,14 +126,12 @@ static int read_midx_bitmapped_packs(const char *object_dir)
struct bitmapped_pack pack;
uint32_t i;
- setup_git_directory();
-
- midx = load_multi_pack_index(the_repository, object_dir, 1);
+ midx = setup_midx(object_dir);
if (!midx)
return 1;
for (i = 0; i < midx->num_packs + midx->num_packs_in_base; i++) {
- if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0) {
+ if (nth_bitmapped_pack(midx, &pack, i) < 0) {
close_midx(midx);
return 1;
}
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 1cc05f043a..83b06d39a3 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -5,7 +5,7 @@
#include "refs.h"
#include "setup.h"
#include "worktree.h"
-#include "object-store-ll.h"
+#include "odb.h"
#include "path.h"
#include "repository.h"
#include "strbuf.h"
@@ -29,7 +29,7 @@ static unsigned int parse_flags(const char *str, struct flag_definition *defs)
if (!strcmp(str, "0"))
return 0;
- string_list_split(&masks, str, ',', 64);
+ string_list_split(&masks, str, ",", 64);
for (size_t i = 0; i < masks.nr; i++) {
const char *name = masks.items[i].string;
struct flag_definition *def = defs;
@@ -75,12 +75,11 @@ static const char **get_store(const char **argv, struct ref_store **refs)
*refs = get_main_ref_store(the_repository);
} else if (skip_prefix(argv[0], "submodule:", &gitdir)) {
struct strbuf sb = STRBUF_INIT;
- int ret;
- ret = strbuf_git_path_submodule(&sb, gitdir, "objects/");
- if (ret)
- die("strbuf_git_path_submodule failed: %d", ret);
- add_to_alternates_memory(sb.buf);
+ if (!repo_submodule_path_append(the_repository,
+ &sb, gitdir, "objects/"))
+ die("computing submodule path failed");
+ odb_add_to_alternates_memory(the_repository->objects, sb.buf);
strbuf_release(&sb);
*refs = repo_get_submodule_ref_store(the_repository, gitdir);
@@ -180,7 +179,7 @@ static int cmd_for_each_ref__exclude(struct ref_store *refs, const char **argv)
static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
{
- struct object_id oid = *null_oid();
+ struct object_id oid = *null_oid(the_hash_algo);
const char *refname = notnull(*argv++, "refname");
int resolve_flags = arg_flags(*argv++, "resolve-flags", empty_flags);
int flags;
@@ -216,7 +215,8 @@ static int cmd_for_each_reflog(struct ref_store *refs,
return refs_for_each_reflog(refs, each_reflog, NULL);
}
-static int each_reflog_ent(struct object_id *old_oid, struct object_id *new_oid,
+static int each_reflog_ent(const char *refname UNUSED,
+ struct object_id *old_oid, struct object_id *new_oid,
const char *committer, timestamp_t timestamp,
int tz, const char *msg, void *cb_data UNUSED)
{
diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c
index 3c72ed985b..b16c0722c8 100644
--- a/t/helper/test-reftable.c
+++ b/t/helper/test-reftable.c
@@ -2,10 +2,11 @@
#include "hash.h"
#include "hex.h"
#include "reftable/system.h"
+#include "reftable/reftable-constants.h"
#include "reftable/reftable-error.h"
#include "reftable/reftable-merged.h"
-#include "reftable/reftable-reader.h"
#include "reftable/reftable-stack.h"
+#include "reftable/reftable-table.h"
#include "test-tool.h"
static void print_help(void)
@@ -20,6 +21,72 @@ static void print_help(void)
"\n");
}
+static int dump_blocks(const char *tablename)
+{
+ struct reftable_table_iterator ti = { 0 };
+ struct reftable_block_source src = { 0 };
+ struct reftable_table *table = NULL;
+ uint8_t section_type = 0;
+ int err;
+
+ err = reftable_block_source_from_file(&src, tablename);
+ if (err < 0)
+ goto done;
+
+ err = reftable_table_new(&table, &src, tablename);
+ if (err < 0)
+ goto done;
+
+ err = reftable_table_iterator_init(&ti, table);
+ if (err < 0)
+ goto done;
+
+ printf("header:\n");
+ printf(" block_size: %d\n", table->block_size);
+
+ while (1) {
+ const struct reftable_block *block;
+
+ err = reftable_table_iterator_next(&ti, &block);
+ if (err < 0)
+ goto done;
+ if (err > 0)
+ break;
+
+ if (block->block_type != section_type) {
+ const char *section;
+ switch (block->block_type) {
+ case REFTABLE_BLOCK_TYPE_LOG:
+ section = "log";
+ break;
+ case REFTABLE_BLOCK_TYPE_REF:
+ section = "ref";
+ break;
+ case REFTABLE_BLOCK_TYPE_OBJ:
+ section = "obj";
+ break;
+ case REFTABLE_BLOCK_TYPE_INDEX:
+ section = "idx";
+ break;
+ default:
+ err = -1;
+ goto done;
+ }
+
+ section_type = block->block_type;
+ printf("%s:\n", section);
+ }
+
+ printf(" - length: %u\n", block->restart_off);
+ printf(" restarts: %u\n", block->restart_count);
+ }
+
+done:
+ reftable_table_iterator_release(&ti);
+ reftable_table_decref(table);
+ return err;
+}
+
static int dump_table(struct reftable_merged_table *mt)
{
struct reftable_iterator it = { NULL };
@@ -126,19 +193,19 @@ static int dump_reftable(const char *tablename)
{
struct reftable_block_source src = { 0 };
struct reftable_merged_table *mt = NULL;
- struct reftable_reader *r = NULL;
+ struct reftable_table *table = NULL;
int err;
err = reftable_block_source_from_file(&src, tablename);
if (err < 0)
goto done;
- err = reftable_reader_new(&r, &src, tablename);
+ err = reftable_table_new(&table, &src, tablename);
if (err < 0)
goto done;
- err = reftable_merged_table_new(&mt, &r, 1,
- reftable_reader_hash_id(r));
+ err = reftable_merged_table_new(&mt, &table, 1,
+ reftable_table_hash_id(table));
if (err < 0)
goto done;
@@ -146,7 +213,7 @@ static int dump_reftable(const char *tablename)
done:
reftable_merged_table_free(mt);
- reftable_reader_decref(r);
+ reftable_table_decref(table);
return err;
}
@@ -184,7 +251,7 @@ int cmd__dump_reftable(int argc, const char **argv)
arg = argv[1];
if (opt_dump_blocks) {
- err = reftable_reader_print_blocks(arg);
+ err = dump_blocks(arg);
} else if (opt_dump_table) {
err = dump_reftable(arg);
} else if (opt_dump_stack) {
diff --git a/t/helper/test-rot13-filter.c b/t/helper/test-rot13-filter.c
index ff407b575c..ad37e10034 100644
--- a/t/helper/test-rot13-filter.c
+++ b/t/helper/test-rot13-filter.c
@@ -1,6 +1,6 @@
/*
* Example implementation for the Git filter protocol version 2
- * See Documentation/gitattributes.txt, section "Filter Protocol"
+ * See Documentation/gitattributes.adoc, section "Filter Protocol"
*
* Usage: test-tool rot13-filter [--always-delay] --log=<path> <capabilities>
*
@@ -324,7 +324,7 @@ static void packet_initialize(void)
packet_flush(1);
}
-static const char *rot13_usage[] = {
+static const char *const rot13_usage[] = {
"test-tool rot13-filter [--always-delay] --log=<path> <capabilities>",
NULL
};
diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c
index 054cbcf5d8..63a200b8d4 100644
--- a/t/helper/test-serve-v2.c
+++ b/t/helper/test-serve-v2.c
@@ -1,6 +1,9 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
#include "test-tool.h"
#include "gettext.h"
#include "parse-options.h"
+#include "repository.h"
#include "serve.h"
#include "setup.h"
@@ -28,9 +31,9 @@ int cmd__serve_v2(int argc, const char **argv)
PARSE_OPT_KEEP_UNKNOWN_OPT);
if (advertise_capabilities)
- protocol_v2_advertise_capabilities();
+ protocol_v2_advertise_capabilities(the_repository);
else
- protocol_v2_serve_loop(stateless_rpc);
+ protocol_v2_serve_loop(the_repository, stateless_rpc);
return 0;
}
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index e60d000c03..349540c4df 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -3,7 +3,7 @@
int cmd__sha1(int ac, const char **av)
{
- return cmd_hash_impl(ac, av, GIT_HASH_SHA1);
+ return cmd_hash_impl(ac, av, GIT_HASH_SHA1, 0);
}
int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)
@@ -13,3 +13,8 @@ int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)
#endif
return 1;
}
+
+int cmd__sha1_unsafe(int ac, const char **av)
+{
+ return cmd_hash_impl(ac, av, GIT_HASH_SHA1, 1);
+}
diff --git a/t/helper/test-sha1.sh b/t/helper/test-sha1.sh
index 84594885c7..f03b784ddc 100755
--- a/t/helper/test-sha1.sh
+++ b/t/helper/test-sha1.sh
@@ -3,25 +3,31 @@
dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
/usr/bin/time t/helper/test-tool sha1 >/dev/null
+dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
+/usr/bin/time t/helper/test-tool sha1-unsafe >/dev/null
+
while read expect cnt pfx
do
case "$expect" in '#'*) continue ;; esac
- actual=$(
- {
- test -z "$pfx" || echo "$pfx"
- dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
- perl -pe 'y/\000/g/'
- } | ./t/helper/test-tool sha1 $cnt
- )
- if test "$expect" = "$actual"
- then
- echo "OK: $expect $cnt $pfx"
- else
- echo >&2 "OOPS: $cnt"
- echo >&2 "expect: $expect"
- echo >&2 "actual: $actual"
- exit 1
- fi
+ for sha1 in sha1 sha1-unsafe
+ do
+ actual=$(
+ {
+ test -z "$pfx" || echo "$pfx"
+ dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
+ tr "\000" "g"
+ } | ./t/helper/test-tool $sha1 $cnt
+ )
+ if test "$expect" = "$actual"
+ then
+ echo "OK ($sha1): $expect $cnt $pfx"
+ else
+ echo >&2 "OOPS ($sha1): $cnt"
+ echo >&2 "expect ($sha1): $expect"
+ echo >&2 "actual ($sha1): $actual"
+ exit 1
+ fi
+ done
done <<EOF
da39a3ee5e6b4b0d3255bfef95601890afd80709 0
3f786850e387550fdab836ed7e6dc881de23001b 0 a
@@ -55,7 +61,7 @@ do
{
test -z "$pfx" || echo "$pfx"
dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
- perl -pe 'y/\000/g/'
+ tr "\000" "g"
} | sha1sum |
sed -e 's/ .*//'
)
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 2fb20438f3..7fd0aa1fcd 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -3,5 +3,5 @@
int cmd__sha256(int ac, const char **av)
{
- return cmd_hash_impl(ac, av, GIT_HASH_SHA256);
+ return cmd_hash_impl(ac, av, GIT_HASH_SHA256, 0);
}
diff --git a/t/helper/test-simple-ipc.c b/t/helper/test-simple-ipc.c
index fb5927775d..03cc5eea2c 100644
--- a/t/helper/test-simple-ipc.c
+++ b/t/helper/test-simple-ipc.c
@@ -612,8 +612,8 @@ int cmd__simple_ipc(int argc, const char **argv)
if (argc < 2)
usage_with_options(simple_ipc_usage, options);
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage_with_options(simple_ipc_usage, options);
+ show_usage_with_options_if_asked(argc, argv,
+ simple_ipc_usage, options);
if (argc == 2 && !strcmp(argv[1], "SUPPORTS_SIMPLE_IPC"))
return 0;
diff --git a/t/helper/test-string-list.c b/t/helper/test-string-list.c
index 6f10c5a435..6be0cdb8e2 100644
--- a/t/helper/test-string-list.c
+++ b/t/helper/test-string-list.c
@@ -1,105 +1,9 @@
-#define DISABLE_SIGN_COMPARE_WARNINGS
-
#include "test-tool.h"
#include "strbuf.h"
#include "string-list.h"
-/*
- * Parse an argument into a string list. arg should either be a
- * ':'-separated list of strings, or "-" to indicate an empty string
- * list (as opposed to "", which indicates a string list containing a
- * single empty string). list->strdup_strings must be set.
- */
-static void parse_string_list(struct string_list *list, const char *arg)
-{
- if (!strcmp(arg, "-"))
- return;
-
- (void)string_list_split(list, arg, ':', -1);
-}
-
-static void write_list(const struct string_list *list)
-{
- int i;
- for (i = 0; i < list->nr; i++)
- printf("[%d]: \"%s\"\n", i, list->items[i].string);
-}
-
-static void write_list_compact(const struct string_list *list)
-{
- int i;
- if (!list->nr)
- printf("-\n");
- else {
- printf("%s", list->items[0].string);
- for (i = 1; i < list->nr; i++)
- printf(":%s", list->items[i].string);
- printf("\n");
- }
-}
-
-static int prefix_cb(struct string_list_item *item, void *cb_data)
-{
- const char *prefix = (const char *)cb_data;
- return starts_with(item->string, prefix);
-}
-
int cmd__string_list(int argc, const char **argv)
{
- if (argc == 5 && !strcmp(argv[1], "split")) {
- struct string_list list = STRING_LIST_INIT_DUP;
- int i;
- const char *s = argv[2];
- int delim = *argv[3];
- int maxsplit = atoi(argv[4]);
-
- i = string_list_split(&list, s, delim, maxsplit);
- printf("%d\n", i);
- write_list(&list);
- string_list_clear(&list, 0);
- return 0;
- }
-
- if (argc == 5 && !strcmp(argv[1], "split_in_place")) {
- struct string_list list = STRING_LIST_INIT_NODUP;
- int i;
- char *s = xstrdup(argv[2]);
- const char *delim = argv[3];
- int maxsplit = atoi(argv[4]);
-
- i = string_list_split_in_place(&list, s, delim, maxsplit);
- printf("%d\n", i);
- write_list(&list);
- string_list_clear(&list, 0);
- free(s);
- return 0;
- }
-
- if (argc == 4 && !strcmp(argv[1], "filter")) {
- /*
- * Retain only the items that have the specified prefix.
- * Arguments: list|- prefix
- */
- struct string_list list = STRING_LIST_INIT_DUP;
- const char *prefix = argv[3];
-
- parse_string_list(&list, argv[2]);
- filter_string_list(&list, 0, prefix_cb, (void *)prefix);
- write_list_compact(&list);
- string_list_clear(&list, 0);
- return 0;
- }
-
- if (argc == 3 && !strcmp(argv[1], "remove_duplicates")) {
- struct string_list list = STRING_LIST_INIT_DUP;
-
- parse_string_list(&list, argv[2]);
- string_list_remove_duplicates(&list, 0);
- write_list_compact(&list);
- string_list_clear(&list, 0);
- return 0;
- }
-
if (argc == 2 && !strcmp(argv[1], "sort")) {
struct string_list list = STRING_LIST_INIT_NODUP;
struct strbuf sb = STRBUF_INIT;
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
index 6dce957153..2710341cd5 100644
--- a/t/helper/test-submodule-nested-repo-config.c
+++ b/t/helper/test-submodule-nested-repo-config.c
@@ -21,7 +21,7 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv)
setup_git_directory();
- if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid())) {
+ if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid(the_hash_algo))) {
die_usage(argv, "Submodule not found.");
}
diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c
index 22e518d229..0133852e1e 100644
--- a/t/helper/test-submodule.c
+++ b/t/helper/test-submodule.c
@@ -12,33 +12,33 @@
#define TEST_TOOL_CHECK_NAME_USAGE \
"test-tool submodule check-name"
-static const char *submodule_check_name_usage[] = {
+static const char *const submodule_check_name_usage[] = {
TEST_TOOL_CHECK_NAME_USAGE,
NULL
};
#define TEST_TOOL_CHECK_URL_USAGE \
"test-tool submodule check-url"
-static const char *submodule_check_url_usage[] = {
+static const char *const submodule_check_url_usage[] = {
TEST_TOOL_CHECK_URL_USAGE,
NULL
};
#define TEST_TOOL_IS_ACTIVE_USAGE \
"test-tool submodule is-active <name>"
-static const char *submodule_is_active_usage[] = {
+static const char *const submodule_is_active_usage[] = {
TEST_TOOL_IS_ACTIVE_USAGE,
NULL
};
#define TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE \
"test-tool submodule resolve-relative-url <up_path> <remoteurl> <url>"
-static const char *submodule_resolve_relative_url_usage[] = {
+static const char *const submodule_resolve_relative_url_usage[] = {
TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE,
NULL,
};
-static const char *submodule_usage[] = {
+static const char *const submodule_usage[] = {
TEST_TOOL_CHECK_NAME_USAGE,
TEST_TOOL_CHECK_URL_USAGE,
TEST_TOOL_IS_ACTIVE_USAGE,
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 4a7aa993ba..a7abc618b3 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -44,7 +44,9 @@ static struct test_cmd cmds[] = {
{ "match-trees", cmd__match_trees },
{ "mergesort", cmd__mergesort },
{ "mktemp", cmd__mktemp },
+ { "name-hash", cmd__name_hash },
{ "online-cpus", cmd__online_cpus },
+ { "pack-deltas", cmd__pack_deltas },
{ "pack-mtimes", cmd__pack_mtimes },
{ "parse-options", cmd__parse_options },
{ "parse-options-flags", cmd__parse_options_flags },
@@ -52,6 +54,7 @@ static struct test_cmd cmds[] = {
{ "parse-subcommand", cmd__parse_subcommand },
{ "partial-clone", cmd__partial_clone },
{ "path-utils", cmd__path_utils },
+ { "path-walk", cmd__path_walk },
{ "pcre2-config", cmd__pcre2_config },
{ "pkt-line", cmd__pkt_line },
{ "proc-receive", cmd__proc_receive },
@@ -70,6 +73,7 @@ static struct test_cmd cmds[] = {
{ "serve-v2", cmd__serve_v2 },
{ "sha1", cmd__sha1 },
{ "sha1-is-sha1dc", cmd__sha1_is_sha1dc },
+ { "sha1-unsafe", cmd__sha1_unsafe },
{ "sha256", cmd__sha256 },
{ "sigchain", cmd__sigchain },
{ "simple-ipc", cmd__simple_ipc },
@@ -87,6 +91,7 @@ static struct test_cmd cmds[] = {
{ "windows-named-pipe", cmd__windows_named_pipe },
#endif
{ "write-cache", cmd__write_cache },
+ { "zlib", cmd__zlib },
};
static NORETURN void die_usage(void)
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index 21802ac27d..7f150fa1eb 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -37,7 +37,9 @@ int cmd__lazy_init_name_hash(int argc, const char **argv);
int cmd__match_trees(int argc, const char **argv);
int cmd__mergesort(int argc, const char **argv);
int cmd__mktemp(int argc, const char **argv);
+int cmd__name_hash(int argc, const char **argv);
int cmd__online_cpus(int argc, const char **argv);
+int cmd__pack_deltas(int argc, const char **argv);
int cmd__pack_mtimes(int argc, const char **argv);
int cmd__parse_options(int argc, const char **argv);
int cmd__parse_options_flags(int argc, const char **argv);
@@ -45,6 +47,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);
int cmd__parse_subcommand(int argc, const char **argv);
int cmd__partial_clone(int argc, const char **argv);
int cmd__path_utils(int argc, const char **argv);
+int cmd__path_walk(int argc, const char **argv);
int cmd__pcre2_config(int argc, const char **argv);
int cmd__pkt_line(int argc, const char **argv);
int cmd__proc_receive(int argc, const char **argv);
@@ -63,6 +66,7 @@ int cmd__scrap_cache_tree(int argc, const char **argv);
int cmd__serve_v2(int argc, const char **argv);
int cmd__sha1(int argc, const char **argv);
int cmd__sha1_is_sha1dc(int argc, const char **argv);
+int cmd__sha1_unsafe(int argc, const char **argv);
int cmd__sha256(int argc, const char **argv);
int cmd__sigchain(int argc, const char **argv);
int cmd__simple_ipc(int argc, const char **argv);
@@ -80,7 +84,8 @@ int cmd__wildmatch(int argc, const char **argv);
int cmd__windows_named_pipe(int argc, const char **argv);
#endif
int cmd__write_cache(int argc, const char **argv);
+int cmd__zlib(int argc, const char **argv);
-int cmd_hash_impl(int ac, const char **av, int algo);
+int cmd_hash_impl(int ac, const char **av, int algo, int unsafe);
#endif
diff --git a/t/helper/test-truncate.c b/t/helper/test-truncate.c
index 3931deaec7..2820cc7ed7 100644
--- a/t/helper/test-truncate.c
+++ b/t/helper/test-truncate.c
@@ -21,5 +21,8 @@ int cmd__truncate(int argc, const char **argv)
if (ftruncate(fd, (off_t) sz) < 0)
die_errno("failed to truncate file");
+
+ close(fd);
+
return 0;
}
diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c
index 94c48ababb..aa3a9894d2 100644
--- a/t/helper/test-userdiff.c
+++ b/t/helper/test-userdiff.c
@@ -41,7 +41,7 @@ int cmd__userdiff(int argc, const char **argv)
if (want & USERDIFF_DRIVER_TYPE_CUSTOM) {
setup_git_directory();
- git_config(cmd__userdiff_config, NULL);
+ repo_config(the_repository, cmd__userdiff_config, NULL);
}
for_each_userdiff_driver(driver_cb, &want);
diff --git a/t/helper/test-windows-named-pipe.c b/t/helper/test-windows-named-pipe.c
index ae52183e63..bd73784ceb 100644
--- a/t/helper/test-windows-named-pipe.c
+++ b/t/helper/test-windows-named-pipe.c
@@ -3,7 +3,7 @@
#include "strbuf.h"
#ifdef GIT_WINDOWS_NATIVE
-static const char *usage_string = "<pipe-filename>";
+static const char *const usage_string = "<pipe-filename>";
#define TEST_BUFSIZE (4096)
diff --git a/t/helper/test-zlib.c b/t/helper/test-zlib.c
new file mode 100644
index 0000000000..de7e9edee1
--- /dev/null
+++ b/t/helper/test-zlib.c
@@ -0,0 +1,62 @@
+#include "test-tool.h"
+#include "git-zlib.h"
+#include "strbuf.h"
+
+static const char *zlib_usage = "test-tool zlib [inflate|deflate]";
+
+static void do_zlib(struct git_zstream *stream,
+ int (*zlib_func)(git_zstream *, int),
+ int fd_in, int fd_out)
+{
+ struct strbuf buf_in = STRBUF_INIT;
+ int status = Z_OK;
+
+ if (strbuf_read(&buf_in, fd_in, 0) < 0)
+ die_errno("read error");
+
+ stream->next_in = (unsigned char *)buf_in.buf;
+ stream->avail_in = buf_in.len;
+
+ while (status == Z_OK ||
+ (status == Z_BUF_ERROR && !stream->avail_out)) {
+ unsigned char buf_out[4096];
+
+ stream->next_out = buf_out;
+ stream->avail_out = sizeof(buf_out);
+
+ status = zlib_func(stream, Z_FINISH);
+ if (write_in_full(fd_out, buf_out,
+ sizeof(buf_out) - stream->avail_out) < 0)
+ die_errno("write error");
+ }
+
+ if (status != Z_STREAM_END)
+ die("zlib error %d", status);
+
+ strbuf_release(&buf_in);
+}
+
+int cmd__zlib(int argc, const char **argv)
+{
+ git_zstream stream;
+
+ if (argc != 2)
+ usage(zlib_usage);
+
+ memset(&stream, 0, sizeof(stream));
+
+ if (!strcmp(argv[1], "inflate")) {
+ git_inflate_init(&stream);
+ do_zlib(&stream, git_inflate, 0, 1);
+ git_inflate_end(&stream);
+ } else if (!strcmp(argv[1], "deflate")) {
+ git_deflate_init(&stream, Z_DEFAULT_COMPRESSION);
+ do_zlib(&stream, git_deflate, 0, 1);
+ git_deflate_end(&stream);
+ } else {
+ error("unknown mode: %s", argv[1]);
+ usage(zlib_usage);
+ }
+
+ return 0;
+}
diff --git a/t/interop/Makefile b/t/interop/Makefile
index 6911c2915a..4ff4ed0616 100644
--- a/t/interop/Makefile
+++ b/t/interop/Makefile
@@ -1,3 +1,6 @@
+# The default target of this Makefile is...
+all::
+
# Import tree-wide shared Makefile behavior and libraries
include ../../shared.mak
@@ -8,7 +11,7 @@ SHELL_PATH ?= $(SHELL)
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
T = $(sort $(wildcard i[0-9][0-9][0-9][0-9]-*.sh))
-all: $(T)
+all:: $(T)
$(T):
@echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
diff --git a/t/lib-credential.sh b/t/lib-credential.sh
index 58b9c74060..cc6bf9aa5f 100644
--- a/t/lib-credential.sh
+++ b/t/lib-credential.sh
@@ -566,6 +566,21 @@ helper_test_authtype() {
EOF
'
+ test_expect_success "helper ($HELPER) gets authtype and credential only if request has authtype capability" '
+ check fill $HELPER <<-\EOF
+ protocol=https
+ host=git.example.com
+ --
+ protocol=https
+ host=git.example.com
+ username=askpass-username
+ password=askpass-password
+ --
+ askpass: Username for '\''https://git.example.com'\'':
+ askpass: Password for '\''https://askpass-username@git.example.com'\'':
+ EOF
+ '
+
test_expect_success "helper ($HELPER) stores authtype and credential with username" '
check approve $HELPER <<-\EOF
capability[]=authtype
diff --git a/t/lib-diff.sh b/t/lib-diff.sh
index c4606bd4b7..12b3c8fcc6 100644
--- a/t/lib-diff.sh
+++ b/t/lib-diff.sh
@@ -21,8 +21,8 @@ compare_diff_raw_z () {
# Also we do not check SHA1 hash generation in this test, which
# is a job for t0000-basic.sh
- perl -pe 'y/\000/\012/' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
- perl -pe 'y/\000/\012/' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
+ tr "\000" "\012" <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
+ tr "\000" "\012" <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
test_cmp .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
}
diff --git a/t/lib-gettext.sh b/t/lib-gettext.sh
index 7a734c6973..b3dd68b0b9 100644
--- a/t/lib-gettext.sh
+++ b/t/lib-gettext.sh
@@ -7,7 +7,7 @@
. ./test-lib.sh
GIT_TEXTDOMAINDIR="$GIT_TEST_TEXTDOMAINDIR"
-GIT_PO_PATH="$GIT_TEST_POPATH"
+GIT_PO_PATH="$GIT_SOURCE_DIR/po"
export GIT_TEXTDOMAINDIR GIT_PO_PATH
if test -n "$GIT_TEST_INSTALLED"
diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh
index 3845b6ac44..937b876bd0 100644
--- a/t/lib-gpg.sh
+++ b/t/lib-gpg.sh
@@ -192,9 +192,5 @@ test_lazy_prereq GPGSSH_VERIFYTIME '
'
sanitize_pgp() {
- perl -ne '
- /^-----END PGP/ and $in_pgp = 0;
- print unless $in_pgp;
- /^-----BEGIN PGP/ and $in_pgp = 1;
- '
+ sed "/^-----BEGIN PGP/,/^-----END PGP/{/^-/p;d;}"
}
diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh
index d83bafeab3..5091db949b 100644
--- a/t/lib-httpd.sh
+++ b/t/lib-httpd.sh
@@ -165,7 +165,7 @@ prepare_httpd() {
install_script broken-smart-http.sh
install_script error-smart-http.sh
install_script error.sh
- install_script apply-one-time-perl.sh
+ install_script apply-one-time-script.sh
install_script nph-custom-auth.sh
ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf
index 022276a6b9..e631ab0eb5 100644
--- a/t/lib-httpd/apache.conf
+++ b/t/lib-httpd/apache.conf
@@ -135,7 +135,7 @@ SetEnv PERL_PATH ${PERL_PATH}
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
SetEnv GIT_HTTP_EXPORT_ALL
</LocationMatch>
-<LocationMatch /one_time_perl/>
+<LocationMatch /one_time_script/>
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
SetEnv GIT_HTTP_EXPORT_ALL
</LocationMatch>
@@ -159,7 +159,7 @@ ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
ScriptAlias /broken_smart/ broken-smart-http.sh/
ScriptAlias /error_smart/ error-smart-http.sh/
ScriptAlias /error/ error.sh/
-ScriptAliasMatch /one_time_perl/(.*) apply-one-time-perl.sh/$1
+ScriptAliasMatch /one_time_script/(.*) apply-one-time-script.sh/$1
ScriptAliasMatch /custom_auth/(.*) nph-custom-auth.sh/$1
<Directory ${GIT_EXEC_PATH}>
Options FollowSymlinks
@@ -182,7 +182,7 @@ ScriptAliasMatch /custom_auth/(.*) nph-custom-auth.sh/$1
<Files error.sh>
Options ExecCGI
</Files>
-<Files apply-one-time-perl.sh>
+<Files apply-one-time-script.sh>
Options ExecCGI
</Files>
<Files ${GIT_EXEC_PATH}/git-http-backend>
diff --git a/t/lib-httpd/apply-one-time-perl.sh b/t/lib-httpd/apply-one-time-perl.sh
deleted file mode 100644
index d7f9fed6ae..0000000000
--- a/t/lib-httpd/apply-one-time-perl.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-
-# If "one-time-perl" exists in $HTTPD_ROOT_PATH, run perl on the HTTP response,
-# using the contents of "one-time-perl" as the perl command to be run. If the
-# response was modified as a result, delete "one-time-perl" so that subsequent
-# HTTP responses are no longer modified.
-#
-# This can be used to simulate the effects of the repository changing in
-# between HTTP request-response pairs.
-if test -f one-time-perl
-then
- LC_ALL=C
- export LC_ALL
-
- "$GIT_EXEC_PATH/git-http-backend" >out
- "$PERL_PATH" -pe "$(cat one-time-perl)" out >out_modified
-
- if cmp -s out out_modified
- then
- cat out
- else
- cat out_modified
- rm one-time-perl
- fi
-else
- "$GIT_EXEC_PATH/git-http-backend"
-fi
diff --git a/t/lib-httpd/apply-one-time-script.sh b/t/lib-httpd/apply-one-time-script.sh
new file mode 100644
index 0000000000..b1682944e2
--- /dev/null
+++ b/t/lib-httpd/apply-one-time-script.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# If "one-time-script" exists in $HTTPD_ROOT_PATH, run the script on the HTTP
+# response. If the response was modified as a result, delete "one-time-script"
+# so that subsequent HTTP responses are no longer modified.
+#
+# This can be used to simulate the effects of the repository changing in
+# between HTTP request-response pairs.
+if test -f one-time-script
+then
+ LC_ALL=C
+ export LC_ALL
+
+ "$GIT_EXEC_PATH/git-http-backend" >out
+ ./one-time-script out >out_modified
+
+ if cmp -s out out_modified
+ then
+ cat out
+ else
+ cat out_modified
+ rm one-time-script
+ fi
+else
+ "$GIT_EXEC_PATH/git-http-backend"
+fi
diff --git a/t/lib-loose.sh b/t/lib-loose.sh
new file mode 100644
index 0000000000..3613631eaf
--- /dev/null
+++ b/t/lib-loose.sh
@@ -0,0 +1,30 @@
+# Support routines for hand-crafting loose objects.
+
+# Write a loose object into the odb at $1, with object type $2 and contents
+# from stdin. Writes the oid to stdout. Example:
+#
+# oid=$(echo foo | loose_obj .git/objects blob)
+#
+loose_obj () {
+ cat >tmp_loose.content &&
+ size=$(wc -c <tmp_loose.content) &&
+ {
+ # Do not quote $size here; we want the shell
+ # to strip whitespace that "wc" adds on some platforms.
+ printf "%s %s\0" "$2" $size &&
+ cat tmp_loose.content
+ } >tmp_loose.raw &&
+
+ oid=$(test-tool $test_hash_algo <tmp_loose.raw) &&
+ suffix=${oid#??} &&
+ prefix=${oid%$suffix} &&
+ dir=$1/$prefix &&
+ file=$dir/$suffix &&
+
+ test-tool zlib deflate <tmp_loose.raw >tmp_loose.zlib &&
+ mkdir -p "$dir" &&
+ mv tmp_loose.zlib "$file" &&
+
+ rm tmp_loose.raw tmp_loose.content &&
+ echo "$oid"
+}
diff --git a/t/lib-merge.sh b/t/lib-merge.sh
deleted file mode 100644
index 8734ebfc17..0000000000
--- a/t/lib-merge.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-# Helper functions used by merge tests.
-
-test_expect_merge_algorithm () {
- status_for_recursive=$1 status_for_ort=$2
- shift 2
-
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_expect_${status_for_ort} "$@"
- else
- test_expect_${status_for_recursive} "$@"
- fi
-}
diff --git a/t/lib-t6000.sh b/t/lib-t6000.sh
index fba6778ca3..35c5472465 100644
--- a/t/lib-t6000.sh
+++ b/t/lib-t6000.sh
@@ -109,13 +109,12 @@ check_output () {
# All alphanums translated into -'s which are then compressed and stripped
# from front and back.
name_from_description () {
- perl -pe '
- s/[^A-Za-z0-9.]/-/g;
- s/-+/-/g;
- s/-$//;
- s/^-//;
- y/A-Z/a-z/;
- '
+ sed \
+ -e 's/[^A-Za-z0-9.]/-/g' \
+ -e 's/--*/-/g' \
+ -e 's/-$//' \
+ -e 's/^-//' \
+ -e 'y/A-Z/a-z/'
}
diff --git a/t/meson.build b/t/meson.build
index 602ebfe6a2..7974795fe4 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -1,11 +1,36 @@
clar_test_suites = [
'unit-tests/u-ctype.c',
+ 'unit-tests/u-dir.c',
+ 'unit-tests/u-example-decorate.c',
+ 'unit-tests/u-hash.c',
+ 'unit-tests/u-hashmap.c',
+ 'unit-tests/u-mem-pool.c',
+ 'unit-tests/u-oid-array.c',
+ 'unit-tests/u-oidmap.c',
+ 'unit-tests/u-oidtree.c',
+ 'unit-tests/u-prio-queue.c',
+ 'unit-tests/u-reftable-basics.c',
+ 'unit-tests/u-reftable-block.c',
+ 'unit-tests/u-reftable-merged.c',
+ 'unit-tests/u-reftable-pq.c',
+ 'unit-tests/u-reftable-readwrite.c',
+ 'unit-tests/u-reftable-record.c',
+ 'unit-tests/u-reftable-stack.c',
+ 'unit-tests/u-reftable-table.c',
+ 'unit-tests/u-reftable-tree.c',
+ 'unit-tests/u-strbuf.c',
+ 'unit-tests/u-strcmp-offset.c',
+ 'unit-tests/u-string-list.c',
'unit-tests/u-strvec.c',
+ 'unit-tests/u-trailer.c',
+ 'unit-tests/u-urlmatch-normalization.c',
]
clar_sources = [
'unit-tests/clar/clar.c',
'unit-tests/unit-test.c',
+ 'unit-tests/lib-oid.c',
+ 'unit-tests/lib-reftable.c'
]
clar_decls_h = custom_target(
@@ -35,50 +60,12 @@ clar_sources += custom_target(
clar_unit_tests = executable('unit-tests',
sources: clar_sources + clar_test_suites,
- dependencies: [libgit, common_main],
+ c_args: [
+ '-DGIT_CLAR_DECLS_H="' + clar_decls_h.full_path() + '"',
+ ],
+ dependencies: [libgit_commonmain],
)
-test('unit-tests', clar_unit_tests)
-
-unit_test_programs = [
- 'unit-tests/t-example-decorate.c',
- 'unit-tests/t-hash.c',
- 'unit-tests/t-hashmap.c',
- 'unit-tests/t-mem-pool.c',
- 'unit-tests/t-oid-array.c',
- 'unit-tests/t-oidmap.c',
- 'unit-tests/t-oidtree.c',
- 'unit-tests/t-prio-queue.c',
- 'unit-tests/t-reftable-basics.c',
- 'unit-tests/t-reftable-block.c',
- 'unit-tests/t-reftable-merged.c',
- 'unit-tests/t-reftable-pq.c',
- 'unit-tests/t-reftable-reader.c',
- 'unit-tests/t-reftable-readwrite.c',
- 'unit-tests/t-reftable-record.c',
- 'unit-tests/t-reftable-stack.c',
- 'unit-tests/t-reftable-tree.c',
- 'unit-tests/t-strbuf.c',
- 'unit-tests/t-strcmp-offset.c',
- 'unit-tests/t-trailer.c',
- 'unit-tests/t-urlmatch-normalization.c',
-]
-
-foreach unit_test_program : unit_test_programs
- unit_test_name = fs.stem(unit_test_program)
- unit_test = executable(unit_test_name,
- sources: [
- 'unit-tests/test-lib.c',
- 'unit-tests/lib-oid.c',
- 'unit-tests/lib-reftable.c',
- unit_test_program,
- ],
- dependencies: [libgit, common_main],
- )
- test(unit_test_name, unit_test,
- workdir: meson.current_source_dir(),
- timeout: 0,
- )
-endforeach
+test('unit-tests', clar_unit_tests, kwargs: test_kwargs)
subdir('helper')
@@ -123,7 +110,6 @@ integration_tests = [
't0060-path-utils.sh',
't0061-run-command.sh',
't0062-revision-walking.sh',
- 't0063-string-list.sh',
't0066-dir-iterator.sh',
't0067-parse_pathspec_file.sh',
't0068-for-each-repo.sh',
@@ -178,7 +164,6 @@ integration_tests = [
't1015-read-index-unmerged.sh',
't1016-compatObjectFormat.sh',
't1020-subdirectory.sh',
- 't1021-rerere-in-workdir.sh',
't1022-read-tree-partial-clone.sh',
't1050-large.sh',
't1051-large-conversion.sh',
@@ -220,10 +205,14 @@ integration_tests = [
't1418-reflog-exists.sh',
't1419-exclude-refs.sh',
't1420-lost-found.sh',
+ 't1421-reflog-write.sh',
+ 't1422-show-ref-exists.sh',
't1430-bad-ref-name.sh',
't1450-fsck.sh',
't1451-fsck-buffer.sh',
't1460-refs-migrate.sh',
+ 't1461-refs-list.sh',
+ 't1462-refs-exists.sh',
't1500-rev-parse.sh',
't1501-work-tree.sh',
't1502-rev-parse-parseopt.sh',
@@ -246,6 +235,7 @@ integration_tests = [
't1700-split-index.sh',
't1701-racy-split-index.sh',
't1800-hook.sh',
+ 't1900-repo.sh',
't2000-conflict-when-checking-files-out.sh',
't2002-checkout-cache-u.sh',
't2003-checkout-cache-mkdir.sh',
@@ -500,6 +490,9 @@ integration_tests = [
't4067-diff-partial-clone.sh',
't4068-diff-symmetric-merge-base.sh',
't4069-remerge-diff.sh',
+ 't4070-diff-pairs.sh',
+ 't4071-diff-minimal.sh',
+ 't4072-diff-max-depth.sh',
't4100-apply-stat.sh',
't4101-apply-nonl.sh',
't4102-apply-rename.sh',
@@ -627,7 +620,7 @@ integration_tests = [
't5407-post-rewrite-hook.sh',
't5408-send-pack-stdin.sh',
't5409-colorize-remote-messages.sh',
- 't5410-receive-pack-alternates.sh',
+ 't5410-receive-pack.sh',
't5411-proc-receive-hook.sh',
't5500-fetch-pack.sh',
't5501-fetch-push-alternates.sh',
@@ -721,12 +714,15 @@ integration_tests = [
't5617-clone-submodules-remote.sh',
't5618-alternate-refs.sh',
't5619-clone-local-ambiguous-transport.sh',
+ 't5620-backfill.sh',
+ 't5621-clone-revision.sh',
't5700-protocol-v1.sh',
't5701-git-serve.sh',
't5702-protocol-v2.sh',
't5703-upload-pack-ref-in-want.sh',
't5704-protocol-violations.sh',
't5705-session-id-in-capabilities.sh',
+ 't5710-promisor-remote-capability.sh',
't5730-protocol-v2-bundle-uri-file.sh',
't5731-protocol-v2-bundle-uri-git.sh',
't5732-protocol-v2-bundle-uri-http.sh',
@@ -784,6 +780,7 @@ integration_tests = [
't6134-pathspec-in-submodule.sh',
't6135-pathspec-with-attrs.sh',
't6136-pathspec-in-bare.sh',
+ 't6137-pathspec-wildcards-literal.sh',
't6200-fmt-merge-msg.sh',
't6300-for-each-ref.sh',
't6301-for-each-ref-errors.sh',
@@ -829,6 +826,7 @@ integration_tests = [
't6500-gc.sh',
't6501-freshen-objects.sh',
't6600-test-reach.sh',
+ 't6601-path-walk.sh',
't6700-tree-depth.sh',
't7001-mv.sh',
't7002-mv-sparse-checkout.sh',
@@ -955,6 +953,7 @@ integration_tests = [
't8012-blame-colors.sh',
't8013-blame-ignore-revs.sh',
't8014-blame-ignore-fuzzy.sh',
+ 't8020-last-modified.sh',
't9001-send-email.sh',
't9002-column.sh',
't9003-help-autocorrect.sh',
@@ -1092,12 +1091,72 @@ integration_tests = [
't9903-bash-prompt.sh',
]
+benchmarks = [
+ 'perf/p0000-perf-lib-sanity.sh',
+ 'perf/p0001-rev-list.sh',
+ 'perf/p0002-read-cache.sh',
+ 'perf/p0003-delta-base-cache.sh',
+ 'perf/p0004-lazy-init-name-hash.sh',
+ 'perf/p0005-status.sh',
+ 'perf/p0006-read-tree-checkout.sh',
+ 'perf/p0007-write-cache.sh',
+ 'perf/p0008-odb-fsync.sh',
+ 'perf/p0071-sort.sh',
+ 'perf/p0090-cache-tree.sh',
+ 'perf/p0100-globbing.sh',
+ 'perf/p1006-cat-file.sh',
+ 'perf/p1400-update-ref.sh',
+ 'perf/p1450-fsck.sh',
+ 'perf/p1451-fsck-skip-list.sh',
+ 'perf/p1500-graph-walks.sh',
+ 'perf/p1501-rev-parse-oneline.sh',
+ 'perf/p2000-sparse-operations.sh',
+ 'perf/p3400-rebase.sh',
+ 'perf/p3404-rebase-interactive.sh',
+ 'perf/p4000-diff-algorithms.sh',
+ 'perf/p4001-diff-no-index.sh',
+ 'perf/p4002-diff-color-moved.sh',
+ 'perf/p4205-log-pretty-formats.sh',
+ 'perf/p4209-pickaxe.sh',
+ 'perf/p4211-line-log.sh',
+ 'perf/p4220-log-grep-engines.sh',
+ 'perf/p4221-log-grep-engines-fixed.sh',
+ 'perf/p5302-pack-index.sh',
+ 'perf/p5303-many-packs.sh',
+ 'perf/p5304-prune.sh',
+ 'perf/p5310-pack-bitmaps.sh',
+ 'perf/p5311-pack-bitmaps-fetch.sh',
+ 'perf/p5312-pack-bitmaps-revs.sh',
+ 'perf/p5313-pack-objects.sh',
+ 'perf/p5314-name-hash.sh',
+ 'perf/p5326-multi-pack-bitmaps.sh',
+ 'perf/p5332-multi-pack-reuse.sh',
+ 'perf/p5333-pseudo-merge-bitmaps.sh',
+ 'perf/p5550-fetch-tags.sh',
+ 'perf/p5551-fetch-rescan.sh',
+ 'perf/p5600-partial-clone.sh',
+ 'perf/p5601-clone-reference.sh',
+ 'perf/p6100-describe.sh',
+ 'perf/p6300-for-each-ref.sh',
+ 'perf/p7000-filter-branch.sh',
+ 'perf/p7102-reset.sh',
+ 'perf/p7300-clean.sh',
+ 'perf/p7519-fsmonitor.sh',
+ 'perf/p7527-builtin-fsmonitor.sh',
+ 'perf/p7810-grep.sh',
+ 'perf/p7820-grep-engines.sh',
+ 'perf/p7821-grep-engines-fixed.sh',
+ 'perf/p7822-grep-perl-character.sh',
+ 'perf/p8020-last-modified.sh',
+ 'perf/p9210-scalar.sh',
+ 'perf/p9300-fast-import-export.sh',
+]
+
# Sanity check that we are not missing any tests present in 't/'. This check
# only runs once at configure time and is thus best-effort, only. It is
# sufficient to catch missing test suites in our CI though.
foreach glob, tests : {
't[0-9][0-9][0-9][0-9]-*.sh': integration_tests,
- 'unit-tests/t-*.c': unit_test_programs,
'unit-tests/u-*.c': clar_test_suites,
}
actual_tests = run_command(shell, '-c', 'ls ' + glob,
@@ -1145,6 +1204,23 @@ foreach integration_test : integration_tests
workdir: meson.current_source_dir(),
env: test_environment,
depends: test_dependencies + bin_wrappers,
- timeout: 0,
+ kwargs: test_kwargs,
)
endforeach
+
+if perl.found() and time.found()
+ benchmark_environment = test_environment
+ benchmark_environment.set('GTIME', time.full_path())
+
+ foreach benchmark : benchmarks
+ benchmark(fs.stem(benchmark), shell,
+ args: [
+ fs.name(benchmark),
+ ],
+ workdir: meson.current_source_dir() / 'perf',
+ env: benchmark_environment,
+ depends: test_dependencies + bin_wrappers,
+ timeout: 0,
+ )
+ endforeach
+endif
diff --git a/t/perf/Makefile b/t/perf/Makefile
index e4808aebed..9b3090c4ed 100644
--- a/t/perf/Makefile
+++ b/t/perf/Makefile
@@ -1,10 +1,13 @@
+# The default target of this Makefile is...
+all::
+
# Import tree-wide shared Makefile behavior and libraries
include ../../shared.mak
-include ../../config.mak
export GIT_TEST_OPTIONS
-all: test-lint perf
+all:: test-lint perf
perf: pre-clean
./run
diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl
index 575d2000cc..1791c7528a 100755
--- a/t/perf/aggregate.perl
+++ b/t/perf/aggregate.perl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
use lib '../../perl/build/lib';
use strict;
diff --git a/t/perf/p1501-rev-parse-oneline.sh b/t/perf/p1501-rev-parse-oneline.sh
new file mode 100755
index 0000000000..538fa9c404
--- /dev/null
+++ b/t/perf/p1501-rev-parse-oneline.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+test_description='Test :/ object name notation'
+
+. ./perf-lib.sh
+
+test_perf_fresh_repo
+
+#
+# Creates lots of merges to make history traversal costly. In
+# particular it creates 2^($max_level-1)-1 2-way merges on top of
+# 2^($max_level-1) root commits. E.g., the commit history looks like
+# this for a $max_level of 3:
+#
+# _1_
+# / \
+# 2 3
+# / \ / \
+# 4 5 6 7
+#
+# The numbers are the fast-import marks, which also are the commit
+# messages. 1 is the HEAD commit and a merge, 2 and 3 are also merges,
+# 4-7 are the root commits.
+#
+build_history () {
+ local max_level="$1" &&
+ local level="${2:-1}" &&
+ local mark="${3:-1}" &&
+ if test $level -eq $max_level
+ then
+ echo "reset refs/heads/master" &&
+ echo "from $ZERO_OID" &&
+ echo "commit refs/heads/master" &&
+ echo "mark :$mark" &&
+ echo "committer C <c@example.com> 1234567890 +0000" &&
+ echo "data <<EOF" &&
+ echo "$mark" &&
+ echo "EOF"
+ else
+ local level1=$((level+1)) &&
+ local mark1=$((2*mark)) &&
+ local mark2=$((2*mark+1)) &&
+ build_history $max_level $level1 $mark1 &&
+ build_history $max_level $level1 $mark2 &&
+ echo "commit refs/heads/master" &&
+ echo "mark :$mark" &&
+ echo "committer C <c@example.com> 1234567890 +0000" &&
+ echo "data <<EOF" &&
+ echo "$mark" &&
+ echo "EOF" &&
+ echo "from :$mark1" &&
+ echo "merge :$mark2"
+ fi
+}
+
+test_expect_success 'setup' '
+ build_history 16 | git fast-import &&
+ git log --format="%H %s" --reverse >commits &&
+ sed -n -e "s/ .*$//p" -e "q" <commits >expect &&
+ sed -n -e "s/^.* //p" -e "q" <commits >needle
+'
+
+test_perf "rev-parse :/$(cat needle)" '
+ git rev-parse :/$(cat needle) >actual
+'
+
+test_expect_success 'verify result' '
+ test_cmp expect actual
+'
+
+test_done
diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
index 39e92b0841..aadf22bc2f 100755
--- a/t/perf/p2000-sparse-operations.sh
+++ b/t/perf/p2000-sparse-operations.sh
@@ -135,5 +135,8 @@ test_perf_on_all git diff-tree HEAD
test_perf_on_all git diff-tree HEAD -- $SPARSE_CONE/a
test_perf_on_all "git worktree add ../temp && git worktree remove ../temp"
test_perf_on_all git check-attr -a -- $SPARSE_CONE/a
+test_perf_on_all 'echo >>a && test_write_lines y | git add -p'
+test_perf_on_all 'test_write_lines y y y | git checkout --patch -'
+test_perf_on_all 'echo >>a && git add a && test_write_lines y | git reset --patch'
test_done
diff --git a/t/perf/p5313-pack-objects.sh b/t/perf/p5313-pack-objects.sh
new file mode 100755
index 0000000000..46a6cd32d2
--- /dev/null
+++ b/t/perf/p5313-pack-objects.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+test_description='Tests pack performance using bitmaps'
+. ./perf-lib.sh
+
+test_perf_large_repo
+
+test_expect_success 'create rev input' '
+ cat >in-thin <<-EOF &&
+ $(git rev-parse HEAD)
+ ^$(git rev-parse HEAD~1)
+ EOF
+
+ cat >in-big <<-EOF &&
+ $(git rev-parse HEAD)
+ ^$(git rev-parse HEAD~1000)
+ EOF
+
+ cat >in-shallow <<-EOF
+ $(git rev-parse HEAD)
+ --shallow $(git rev-parse HEAD)
+ EOF
+'
+
+test_all_with_args () {
+ parameter=$1
+ export parameter
+
+ test_perf "thin pack with $parameter" '
+ git pack-objects --thin --stdout --revs --sparse \
+ $parameter <in-thin >out
+ '
+
+ test_size "thin pack size with $parameter" '
+ test_file_size out
+ '
+
+ test_perf "big pack with $parameter" '
+ git pack-objects --stdout --revs --sparse \
+ $parameter <in-big >out
+ '
+
+ test_size "big pack size with $parameter" '
+ test_file_size out
+ '
+
+ test_perf "shallow fetch pack with $parameter" '
+ git pack-objects --stdout --revs --sparse --shallow \
+ $parameter <in-shallow >out
+ '
+
+ test_size "shallow pack size with $parameter" '
+ test_file_size out
+ '
+
+ test_perf "repack with $parameter" '
+ git repack -adf $parameter
+ '
+
+ test_size "repack size with $parameter" '
+ gitdir=$(git rev-parse --git-dir) &&
+ pack=$(ls $gitdir/objects/pack/pack-*.pack) &&
+ test_file_size "$pack"
+ '
+}
+
+for version in 1 2
+do
+ test_all_with_args --name-hash-version=$version
+done
+
+test_all_with_args --path-walk
+
+test_done
diff --git a/t/perf/p5314-name-hash.sh b/t/perf/p5314-name-hash.sh
new file mode 100755
index 0000000000..235cdfc824
--- /dev/null
+++ b/t/perf/p5314-name-hash.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+test_description='Tests pack performance using bitmaps'
+. ./perf-lib.sh
+
+test_perf_large_repo
+
+test_size 'paths at head' '
+ git ls-tree -r --name-only HEAD >path-list &&
+ wc -l <path-list &&
+ test-tool name-hash <path-list >name-hashes
+'
+
+for version in 1 2
+do
+ test_size "distinct hash value: v$version" '
+ awk "{ print \$$version; }" <name-hashes | sort | \
+ uniq -c >name-hash-count &&
+ wc -l <name-hash-count
+ '
+
+ test_size "maximum multiplicity: v$version" '
+ sort -nr <name-hash-count | head -n 1 | \
+ awk "{ print \$1; }"
+ '
+done
+
+test_done
diff --git a/t/perf/p5332-multi-pack-reuse.sh b/t/perf/p5332-multi-pack-reuse.sh
index d1c89a8b7d..0a2525db44 100755
--- a/t/perf/p5332-multi-pack-reuse.sh
+++ b/t/perf/p5332-multi-pack-reuse.sh
@@ -58,7 +58,7 @@ do
'
test_expect_success "setup bitmaps for $nr_packs-pack scenario" '
- find $packdir -type f -name "*.idx" | sed -e "s/.*\/\(.*\)$/+\1/g" |
+ find $packdir -type f -name "*.idx" | sed -e "s/.*\///" |
git multi-pack-index write --stdin-packs --bitmap \
--preferred-pack="$(find_pack $(git rev-parse HEAD))"
'
diff --git a/t/perf/p7821-grep-engines-fixed.sh b/t/perf/p7821-grep-engines-fixed.sh
index 61e41b82cf..66bec284e3 100755
--- a/t/perf/p7821-grep-engines-fixed.sh
+++ b/t/perf/p7821-grep-engines-fixed.sh
@@ -7,7 +7,7 @@ git-grep. Make sure to include a leading space,
e.g. GIT_PERF_7821_GREP_OPTS=' -w'. See p7820-grep-engines.sh for more
options to try.
-If GIT_PERF_7821_THREADS is set to a list of threads (e.g. '1 4 8'
+If GIT_PERF_GREP_THREADS is set to a list of threads (e.g. '1 4 8'
etc.) we will test the patterns under those numbers of threads.
"
@@ -33,13 +33,13 @@ do
fi
if ! test_have_prereq PERF_GREP_ENGINES_THREADS
then
- test_perf $prereq "$engine grep$GIT_PERF_7821_GREP_OPTS $pattern" "
+ test_perf "$engine grep$GIT_PERF_7821_GREP_OPTS $pattern" --prereq "$prereq" "
git -c grep.patternType=$engine grep$GIT_PERF_7821_GREP_OPTS $pattern >'out.$engine' || :
"
else
for threads in $GIT_PERF_GREP_THREADS
do
- test_perf PTHREADS,$prereq "$engine grep$GIT_PERF_7821_GREP_OPTS $pattern with $threads threads" "
+ test_perf "$engine grep$GIT_PERF_7821_GREP_OPTS $pattern with $threads threads" --prereq "PTHREADS,$prereq" "
git -c grep.patternType=$engine -c grep.threads=$threads grep$GIT_PERF_7821_GREP_OPTS $pattern >'out.$engine.$threads' || :
"
done
diff --git a/t/perf/p8020-last-modified.sh b/t/perf/p8020-last-modified.sh
new file mode 100755
index 0000000000..cb1f98d3db
--- /dev/null
+++ b/t/perf/p8020-last-modified.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+test_description='last-modified perf tests'
+. ./perf-lib.sh
+
+test_perf_default_repo
+
+test_perf 'top-level last-modified' '
+ git last-modified HEAD
+'
+
+test_perf 'top-level recursive last-modified' '
+ git last-modified -r HEAD
+'
+
+test_perf 'subdir last-modified' '
+ git ls-tree -d HEAD >subtrees &&
+ path="$(head -n 1 subtrees | cut -f2)" &&
+ git last-modified -r HEAD -- "$path"
+'
+
+test_done
diff --git a/t/perf/p9210-scalar.sh b/t/perf/p9210-scalar.sh
index 265f7cd1fe..56b075e906 100755
--- a/t/perf/p9210-scalar.sh
+++ b/t/perf/p9210-scalar.sh
@@ -7,7 +7,8 @@ test_perf_large_repo "$TRASH_DIRECTORY/to-clone"
test_expect_success 'enable server-side partial clone' '
git -C to-clone config uploadpack.allowFilter true &&
- git -C to-clone config uploadpack.allowAnySHA1InWant true
+ git -C to-clone config uploadpack.allowAnySHA1InWant true &&
+ git -C to-clone checkout -B test-branch
'
test_perf 'scalar clone' '
diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh
index 8ab6d9c469..b15c74d6f1 100644
--- a/t/perf/perf-lib.sh
+++ b/t/perf/perf-lib.sh
@@ -25,7 +25,43 @@ TEST_OUTPUT_DIRECTORY=$(pwd)
TEST_NO_CREATE_REPO=t
TEST_NO_MALLOC_CHECK=t
-. ../test-lib.sh
+# GIT-BUILD-OPTIONS, sourced by test-lib.sh, overwrites the `GIT_PERF_*`
+# values that are set by the user (if any). Let's stash them away as
+# `eval`-able assignments.
+git_perf_settings="$(env |
+ sed -n "/^GIT_PERF_/{
+ # escape all single-quotes in the value
+ s/'/'\\\\''/g
+ # turn this into an eval-able assignment
+ s/^\\([^=]*=\\)\\(.*\\)/\\1'\\2'/p
+ }")"
+
+# While test-lib.sh computes the build directory for us, we also have to do the
+# same thing in order to locate the script via GIT-BUILD-OPTIONS in the first
+# place.
+GIT_BUILD_DIR="${GIT_BUILD_DIR:-$TEST_DIRECTORY/..}"
+if test -f "$GIT_BUILD_DIR/GIT-BUILD-DIR"
+then
+ GIT_BUILD_DIR="$(cat "$GIT_BUILD_DIR/GIT-BUILD-DIR")" || exit 1
+ # On Windows, we must convert Windows paths lest they contain a colon
+ case "$(uname -s)" in
+ *MINGW*)
+ GIT_BUILD_DIR="$(cygpath -au "$GIT_BUILD_DIR")"
+ ;;
+ esac
+fi
+
+if test ! -f "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
+then
+ echo >&2 'error: GIT-BUILD-OPTIONS missing (has Git been built?).'
+ exit 1
+fi
+
+. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
+. "$GIT_SOURCE_DIR"/t/test-lib.sh
+
+# Then restore GIT_PERF_* settings.
+eval "$git_perf_settings"
unset GIT_CONFIG_NOSYSTEM
GIT_CONFIG_SYSTEM="$TEST_DIRECTORY/perf/config"
@@ -98,6 +134,8 @@ test_perf_create_repo_from () {
source_git="$("$MODERN_GIT" -C "$source" rev-parse --git-dir)"
objects_dir="$("$MODERN_GIT" -C "$source" rev-parse --git-path objects)"
common_dir="$("$MODERN_GIT" -C "$source" rev-parse --git-common-dir)"
+ refformat="$("$MODERN_GIT" -C "$source" rev-parse --show-ref-format)"
+ objectformat="$("$MODERN_GIT" -C "$source" rev-parse --show-object-format)"
mkdir -p "$repo/.git"
(
cd "$source" &&
@@ -114,7 +152,7 @@ test_perf_create_repo_from () {
) &&
(
cd "$repo" &&
- "$MODERN_GIT" init -q &&
+ "$MODERN_GIT" init -q --ref-format="$refformat" --object-format="$objectformat" &&
test_perf_do_repo_symlink_config_ &&
mv .git/hooks .git/hooks-disabled 2>/dev/null &&
if test -f .git/index.lock
@@ -274,7 +312,7 @@ test_perf_ () {
else
test_ok_ "$1"
fi
- "$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".result
+ "$PERL_PATH" "$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".result
rm test_time.*
}
@@ -322,7 +360,7 @@ test_at_end_hook_ () {
if test -z "$GIT_PERF_AGGREGATING_LATER"; then
(
cd "$TEST_DIRECTORY"/perf &&
- ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" $(basename "$0")
+ "$PERL_PATH" "$GIT_SOURCE_DIR"/t/perf/aggregate.perl --results-dir="$TEST_RESULTS_DIR" $(basename "$0")
)
fi
}
diff --git a/t/perf/run b/t/perf/run
index 486ead2198..073bcb2aff 100755
--- a/t/perf/run
+++ b/t/perf/run
@@ -192,10 +192,10 @@ run_subsection () {
if test -z "$GIT_PERF_SEND_TO_CODESPEED"
then
- ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" $codespeed_opt "$@"
+ "$PERL_PATH" ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" $codespeed_opt "$@"
else
json_res_file=""$TEST_RESULTS_DIR"/$GIT_PERF_SUBSECTION/aggregate.json"
- ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" --codespeed "$@" | tee "$json_res_file"
+ "$PERL_PATH" ./aggregate.perl --results-dir="$TEST_RESULTS_DIR" --codespeed "$@" | tee "$json_res_file"
send_data_url="$GIT_PERF_SEND_TO_CODESPEED/result/add/json/"
curl -v --request POST --data-urlencode "json=$(cat "$json_res_file")" "$send_data_url"
fi
diff --git a/t/show-ref-exists-tests.sh b/t/show-ref-exists-tests.sh
new file mode 100644
index 0000000000..36e8e9df33
--- /dev/null
+++ b/t/show-ref-exists-tests.sh
@@ -0,0 +1,77 @@
+git_show_ref_exists=${git_show_ref_exists:-git show-ref --exists}
+
+test_expect_success setup '
+ test_commit --annotate A &&
+ git checkout -b side &&
+ test_commit --annotate B &&
+ git checkout main &&
+ test_commit C &&
+ git branch B A^0
+'
+
+test_expect_success '--exists with existing reference' '
+ ${git_show_ref_exists} refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+'
+
+test_expect_success '--exists with missing reference' '
+ test_expect_code 2 ${git_show_ref_exists} refs/heads/does-not-exist
+'
+
+test_expect_success '--exists does not use DWIM' '
+ test_expect_code 2 ${git_show_ref_exists} $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 2>err &&
+ grep "reference does not exist" err
+'
+
+test_expect_success '--exists with HEAD' '
+ ${git_show_ref_exists} HEAD
+'
+
+test_expect_success '--exists with bad reference name' '
+ test_when_finished "git update-ref -d refs/heads/bad...name" &&
+ new_oid=$(git rev-parse HEAD) &&
+ test-tool ref-store main update-ref msg refs/heads/bad...name $new_oid $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
+ ${git_show_ref_exists} refs/heads/bad...name
+'
+
+test_expect_success '--exists with arbitrary symref' '
+ test_when_finished "git symbolic-ref -d refs/symref" &&
+ git symbolic-ref refs/symref refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
+ ${git_show_ref_exists} refs/symref
+'
+
+test_expect_success '--exists with dangling symref' '
+ test_when_finished "git symbolic-ref -d refs/heads/dangling" &&
+ git symbolic-ref refs/heads/dangling refs/heads/does-not-exist &&
+ ${git_show_ref_exists} refs/heads/dangling
+'
+
+test_expect_success '--exists with nonexistent object ID' '
+ test-tool ref-store main update-ref msg refs/heads/missing-oid $(test_oid 001) $ZERO_OID REF_SKIP_OID_VERIFICATION &&
+ ${git_show_ref_exists} refs/heads/missing-oid
+'
+
+test_expect_success '--exists with non-commit object' '
+ tree_oid=$(git rev-parse HEAD^{tree}) &&
+ test-tool ref-store main update-ref msg refs/heads/tree ${tree_oid} $ZERO_OID REF_SKIP_OID_VERIFICATION &&
+ ${git_show_ref_exists} refs/heads/tree
+'
+
+test_expect_success '--exists with directory fails with generic error' '
+ cat >expect <<-EOF &&
+ error: reference does not exist
+ EOF
+ test_expect_code 2 ${git_show_ref_exists} refs/heads 2>err &&
+ test_cmp expect err
+'
+
+test_expect_success '--exists with non-existent special ref' '
+ test_expect_code 2 ${git_show_ref_exists} FETCH_HEAD
+'
+
+test_expect_success '--exists with existing special ref' '
+ test_when_finished "rm .git/FETCH_HEAD" &&
+ git rev-parse HEAD >.git/FETCH_HEAD &&
+ ${git_show_ref_exists} FETCH_HEAD
+'
+
+test_done
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 35c5c2b4f9..2b63e1c86c 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -130,7 +130,7 @@ test_expect_success 'subtest: a failing TODO test' '
'
test_expect_success 'subtest: a passing TODO test' '
- write_and_run_sub_test_lib_test passing-todo <<-\EOF &&
+ write_and_run_sub_test_lib_test_err passing-todo <<-\EOF &&
test_expect_failure "pretend we have fixed a known breakage" "true"
test_done
EOF
@@ -142,7 +142,7 @@ test_expect_success 'subtest: a passing TODO test' '
'
test_expect_success 'subtest: 2 TODO tests, one passin' '
- write_and_run_sub_test_lib_test partially-passing-todos <<-\EOF &&
+ write_and_run_sub_test_lib_test_err partially-passing-todos <<-\EOF &&
test_expect_failure "pretend we have a known breakage" "false"
test_expect_success "pretend we have a passing test" "true"
test_expect_failure "pretend we have fixed another known breakage" "true"
@@ -219,41 +219,44 @@ test_expect_success 'subtest: --verbose option' '
test_expect_success "failing test" false
test_done
EOF
- mv t1234-verbose/out t1234-verbose/out+ &&
- grep -v "^Initialized empty" t1234-verbose/out+ >t1234-verbose/out &&
- check_sub_test_lib_test t1234-verbose <<-\EOF
- > expecting success of 1234.1 '\''passing test'\'': true
+ mv t1234-verbose/err t1234-verbose/err+ &&
+ grep -v "^Initialized empty" t1234-verbose/err+ >t1234-verbose/err &&
+ check_sub_test_lib_test_err t1234-verbose \
+ <<-\EOF_OUT 3<<-\EOF_ERR
> ok 1 - passing test
+ > ok 2 - test with output
+ > not ok 3 - failing test
+ > # false
+ > # failed 1 among 3 test(s)
+ > 1..3
+ EOF_OUT
+ > expecting success of 1234.1 '\''passing test'\'': true
> Z
> expecting success of 1234.2 '\''test with output'\'': echo foo
> foo
- > ok 2 - test with output
> Z
> expecting success of 1234.3 '\''failing test'\'': false
- > not ok 3 - failing test
- > # false
> Z
- > # failed 1 among 3 test(s)
- > 1..3
- EOF
+ EOF_ERR
'
test_expect_success 'subtest: --verbose-only option' '
run_sub_test_lib_test_err \
t1234-verbose \
--verbose-only=2 &&
- check_sub_test_lib_test t1234-verbose <<-\EOF
+ check_sub_test_lib_test_err t1234-verbose <<-\EOF_OUT 3<<-\EOF_ERR
> ok 1 - passing test
- > Z
- > expecting success of 1234.2 '\''test with output'\'': echo foo
- > foo
> ok 2 - test with output
- > Z
> not ok 3 - failing test
> # false
> # failed 1 among 3 test(s)
> 1..3
- EOF
+ EOF_OUT
+ > Z
+ > expecting success of 1234.2 '\''test with output'\'': echo foo
+ > foo
+ > Z
+ EOF_ERR
'
test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' '
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 72a0c2e7d4..f593c53687 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -586,6 +586,18 @@ test_expect_success 'GIT_DEFAULT_HASH overrides init.defaultObjectFormat' '
echo sha256 >expected
'
+for hash in sha1 sha256
+do
+ test_expect_success "reinit repository with GIT_DEFAULT_HASH=$hash does not change format" '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ git -C repo rev-parse --show-object-format >expect &&
+ GIT_DEFAULT_HASH=$hash git init repo &&
+ git -C repo rev-parse --show-object-format >actual &&
+ test_cmp expect actual
+ '
+done
+
test_expect_success 'extensions.objectFormat is not allowed with repo version 0' '
test_when_finished "rm -rf explicit-v0" &&
git init --object-format=sha256 explicit-v0 &&
@@ -646,6 +658,17 @@ test_expect_success 'init warns about invalid init.defaultRefFormat' '
test_cmp expected actual
'
+test_expect_success 'default ref format' '
+ test_when_finished "rm -rf refformat" &&
+ (
+ sane_unset GIT_DEFAULT_REF_FORMAT &&
+ git init refformat
+ ) &&
+ git version --build-options | sed -ne "s/^default-ref-format: //p" >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+'
+
backends="files reftable"
for format in $backends
do
@@ -697,6 +720,15 @@ do
git -C refformat rev-parse --show-ref-format >actual &&
test_cmp expect actual
'
+
+ test_expect_success "reinit repository with GIT_DEFAULT_REF_FORMAT=$format does not change format" '
+ test_when_finished "rm -rf refformat" &&
+ git init refformat &&
+ git -C refformat rev-parse --show-ref-format >expect &&
+ GIT_DEFAULT_REF_FORMAT=$format git init refformat &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+ '
done
test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" '
@@ -717,6 +749,40 @@ test_expect_success "GIT_DEFAULT_REF_FORMAT= overrides init.defaultRefFormat" '
test_cmp expect actual
'
+test_expect_success "init with feature.experimental=true" '
+ test_when_finished "rm -rf refformat" &&
+ test_config_global feature.experimental true &&
+ (
+ sane_unset GIT_DEFAULT_REF_FORMAT &&
+ git init refformat
+ ) &&
+ echo reftable >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success "init.defaultRefFormat overrides feature.experimental=true" '
+ test_when_finished "rm -rf refformat" &&
+ test_config_global feature.experimental true &&
+ test_config_global init.defaultRefFormat files &&
+ (
+ sane_unset GIT_DEFAULT_REF_FORMAT &&
+ git init refformat
+ ) &&
+ echo files >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success "GIT_DEFAULT_REF_FORMAT= overrides feature.experimental=true" '
+ test_when_finished "rm -rf refformat" &&
+ test_config_global feature.experimental true &&
+ GIT_DEFAULT_REF_FORMAT=files git init refformat &&
+ echo files >expect &&
+ git -C refformat rev-parse --show-ref-format >actual &&
+ test_cmp expect actual
+'
+
for from_format in $backends
do
test_expect_success "re-init with same format ($from_format)" '
@@ -809,6 +875,14 @@ test_expect_success 'advice on unconfigured init.defaultBranch' '
test_grep "<YELLOW>hint: " decoded
'
+test_expect_success 'advice on unconfigured init.defaultBranch disabled' '
+ test_when_finished "rm -rf no-advice" &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c advice.defaultBranchName=false init no-advice 2>err &&
+ test_grep ! "hint: " err
+'
+
test_expect_success 'overridden default main branch name (env)' '
test_config_global init.defaultBranch nmb &&
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env &&
@@ -861,15 +935,6 @@ test_expect_success 're-init with includeIf.onbranch condition' '
test_cmp expect actual
'
-test_expect_success 're-init with includeIf.onbranch condition' '
- test_when_finished "rm -rf repo" &&
- git init repo &&
- git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo &&
- echo $GIT_DEFAULT_REF_FORMAT >expect &&
- git -C repo rev-parse --show-ref-format >actual &&
- test_cmp expect actual
-'
-
test_expect_success 're-init skips non-matching includeIf.onbranch' '
test_when_finished "rm -rf repo config" &&
cat >config <<-EOF &&
diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
index c9376dffb5..273d71411f 100755
--- a/t/t0008-ignores.sh
+++ b/t/t0008-ignores.sh
@@ -39,11 +39,11 @@ test_stderr () {
}
broken_c_unquote () {
- "$PERL_PATH" -pe 's/^"//; s/\\//; s/"$//; tr/\n/\0/' "$@"
+ sed -e 's/^"//' -e 's/\\//' -e 's/"$//' "$1" | tr '\n' '\0'
}
broken_c_unquote_verbose () {
- "$PERL_PATH" -pe 's/ "/ /; s/\\//; s/"$//; tr/:\t\n/\0/' "$@"
+ sed -e 's/ "/ /' -e 's/\\//' -e 's/"$//' "$1" | tr ':\t\n' '\000'
}
stderr_contains () {
diff --git a/t/t0012-help.sh b/t/t0012-help.sh
index 1d273d91c2..d3a0967e9d 100755
--- a/t/t0012-help.sh
+++ b/t/t0012-help.sh
@@ -255,8 +255,9 @@ do
(
GIT_CEILING_DIRECTORIES=$(pwd) &&
export GIT_CEILING_DIRECTORIES &&
- test_expect_code 129 git -C sub $builtin -h >output 2>&1
+ test_expect_code 129 git -C sub $builtin -h >output 2>err
) &&
+ test_must_be_empty err &&
test_grep usage output
'
done <builtins
diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
index 3f6433d304..f0d50d769e 100755
--- a/t/t0021-conversion.sh
+++ b/t/t0021-conversion.sh
@@ -20,8 +20,7 @@ EOF
generate_random_characters () {
LEN=$1
NAME=$2
- test-tool genrandom some-seed $LEN |
- perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
+ test-tool genrandom some-seed | tr -dc 'a-z' | test_copy_bytes "$LEN" >"$TEST_ROOT/$NAME"
}
filter_git () {
@@ -282,7 +281,7 @@ test_expect_success 'required filter with absent smudge field' '
test_expect_success 'filtering large input to small output should use little memory' '
test_config filter.devnull.clean "cat >/dev/null" &&
test_config filter.devnull.required true &&
- for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB &&
+ test_seq -f "%1048576d" 1 30 >30MB &&
echo "30MB filter=devnull" >.gitattributes &&
GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
'
@@ -300,7 +299,7 @@ test_expect_success 'filter that does not read is fine' '
test_expect_success EXPENSIVE 'filter large file' '
test_config filter.largefile.smudge cat &&
test_config filter.largefile.clean cat &&
- for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB &&
+ test_seq -f "%1048576d" 1 2048 >2GB &&
echo "2GB filter=largefile" >.gitattributes &&
git add 2GB 2>err &&
test_must_be_empty err &&
@@ -841,7 +840,7 @@ test_expect_success 'process filter abort stops processing of all further files'
)
'
-test_expect_success PERL 'invalid process filter must fail (and not hang!)' '
+test_expect_success 'invalid process filter must fail (and not hang!)' '
test_config_global filter.protocol.process cat &&
test_config_global filter.protocol.required true &&
rm -rf repo &&
@@ -1111,19 +1110,19 @@ do
branch) opt='-f HEAD' ;;
esac
- test_expect_success PERL,TTY "delayed checkout shows progress by default on tty ($mode checkout)" '
+ test_expect_success TTY "delayed checkout shows progress by default on tty ($mode checkout)" '
test_delayed_checkout_progress test_terminal git checkout $opt
'
- test_expect_success PERL "delayed checkout omits progress on non-tty ($mode checkout)" '
+ test_expect_success "delayed checkout omits progress on non-tty ($mode checkout)" '
test_delayed_checkout_progress ! git checkout $opt
'
- test_expect_success PERL,TTY "delayed checkout omits progress with --quiet ($mode checkout)" '
+ test_expect_success TTY "delayed checkout omits progress with --quiet ($mode checkout)" '
test_delayed_checkout_progress ! test_terminal git checkout --quiet $opt
'
- test_expect_success PERL,TTY "delayed checkout honors --[no]-progress ($mode checkout)" '
+ test_expect_success TTY "delayed checkout honors --[no]-progress ($mode checkout)" '
test_delayed_checkout_progress ! test_terminal git checkout --no-progress $opt &&
test_delayed_checkout_progress test_terminal git checkout --quiet --progress $opt
'
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 2fe3522305..ca55ea8228 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -22,8 +22,10 @@ usage: test-tool parse-options <options>
-i, --[no-]integer <n>
get a integer
+ --[no-]i16 <n> get a 16 bit integer
-j <n> get a integer, too
- -m, --magnitude <n> get a magnitude
+ -u, --unsigned <n> get an unsigned integer
+ --u16 <n> get a 16 bit unsigned integer
--[no-]set23 set integer to 23
--mode1 set integer to 1 (cmdmode option)
--mode2 set integer to 2 (cmdmode option)
@@ -111,32 +113,36 @@ test_expect_success 'OPT_BOOL() no negation #2' 'check_unknown_i18n --no-no-fear
test_expect_success 'OPT_BOOL() positivation' 'check boolean: 0 -D --doubt'
-test_expect_success 'OPT_INT() negative' 'check integer: -2345 -i -2345'
+test_expect_success 'OPT_INTEGER() negative' 'check integer: -2345 -i -2345'
+test_expect_success 'OPT_INTEGER() kilo' 'check integer: 239616 -i 234k'
+test_expect_success 'OPT_INTEGER() negative kilo' 'check integer: -239616 -i -234k'
-test_expect_success 'OPT_MAGNITUDE() simple' '
- check magnitude: 2345678 -m 2345678
+test_expect_success 'OPT_UNSIGNED() simple' '
+ check unsigned: 2345678 -u 2345678
'
-test_expect_success 'OPT_MAGNITUDE() kilo' '
- check magnitude: 239616 -m 234k
+test_expect_success 'OPT_UNSIGNED() kilo' '
+ check unsigned: 239616 -u 234k
'
-test_expect_success 'OPT_MAGNITUDE() mega' '
- check magnitude: 104857600 -m 100m
+test_expect_success 'OPT_UNSIGNED() mega' '
+ check unsigned: 104857600 -u 100m
'
-test_expect_success 'OPT_MAGNITUDE() giga' '
- check magnitude: 1073741824 -m 1g
+test_expect_success 'OPT_UNSIGNED() giga' '
+ check unsigned: 1073741824 -u 1g
'
-test_expect_success 'OPT_MAGNITUDE() 3giga' '
- check magnitude: 3221225472 -m 3g
+test_expect_success 'OPT_UNSIGNED() 3giga' '
+ check unsigned: 3221225472 -u 3g
'
cat >expect <<\EOF
boolean: 2
integer: 1729
-magnitude: 16384
+i16: 0
+unsigned: 16384
+u16: 0
timestamp: 0
string: 123
abbrev: 7
@@ -147,7 +153,7 @@ file: prefix/my.file
EOF
test_expect_success 'short options' '
- test-tool parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \
+ test-tool parse-options -s123 -b -i 1729 -u 16k -b -vv -n -F my.file \
>output 2>output.err &&
test_cmp expect output &&
test_must_be_empty output.err
@@ -156,7 +162,9 @@ test_expect_success 'short options' '
cat >expect <<\EOF
boolean: 2
integer: 1729
-magnitude: 16384
+i16: 9000
+unsigned: 16384
+u16: 32768
timestamp: 0
string: 321
abbrev: 10
@@ -167,8 +175,8 @@ file: prefix/fi.le
EOF
test_expect_success 'long options' '
- test-tool parse-options --boolean --integer 1729 --magnitude 16k \
- --boolean --string2=321 --verbose --verbose --no-dry-run \
+ test-tool parse-options --boolean --integer 1729 --i16 9000 --unsigned 16k \
+ --u16 32k --boolean --string2=321 --verbose --verbose --no-dry-run \
--abbrev=10 --file fi.le --obsolete \
>output 2>output.err &&
test_must_be_empty output.err &&
@@ -179,7 +187,9 @@ test_expect_success 'abbreviate to something longer than SHA1 length' '
cat >expect <<-EOF &&
boolean: 0
integer: 0
- magnitude: 0
+ i16: 0
+ unsigned: 0
+ u16: 0
timestamp: 0
string: (not set)
abbrev: 100
@@ -253,7 +263,9 @@ test_expect_success 'superfluous value provided: cmdmode' '
cat >expect <<\EOF
boolean: 1
integer: 13
-magnitude: 0
+i16: 0
+unsigned: 0
+u16: 0
timestamp: 0
string: 123
abbrev: 7
@@ -276,7 +288,9 @@ test_expect_success 'intermingled arguments' '
cat >expect <<\EOF
boolean: 0
integer: 2
-magnitude: 0
+i16: 0
+unsigned: 0
+u16: 0
timestamp: 0
string: (not set)
abbrev: 7
@@ -343,7 +357,9 @@ cat >expect <<\EOF
Callback: "four", 0
boolean: 5
integer: 4
-magnitude: 0
+i16: 0
+unsigned: 0
+u16: 0
timestamp: 0
string: (not set)
abbrev: 7
@@ -368,7 +384,9 @@ test_expect_success 'OPT_CALLBACK() and callback errors work' '
cat >expect <<\EOF
boolean: 1
integer: 23
-magnitude: 0
+i16: 0
+unsigned: 0
+u16: 0
timestamp: 0
string: (not set)
abbrev: 7
@@ -447,7 +465,9 @@ test_expect_success 'OPT_NUMBER_CALLBACK() works' '
cat >expect <<\EOF
boolean: 0
integer: 0
-magnitude: 0
+i16: 0
+unsigned: 0
+u16: 0
timestamp: 0
string: (not set)
abbrev: 7
@@ -771,16 +791,35 @@ test_expect_success 'subcommands are incompatible with KEEP_DASHDASH unless in c
grep ^BUG err
'
-test_expect_success 'negative magnitude' '
- test_must_fail test-tool parse-options --magnitude -1 >out 2>err &&
+test_expect_success 'negative unsigned' '
+ test_must_fail test-tool parse-options --unsigned -1 >out 2>err &&
grep "non-negative integer" err &&
test_must_be_empty out
'
-test_expect_success 'magnitude with units but no numbers' '
- test_must_fail test-tool parse-options --magnitude m >out 2>err &&
+test_expect_success 'unsigned with units but no numbers' '
+ test_must_fail test-tool parse-options --unsigned m >out 2>err &&
grep "non-negative integer" err &&
test_must_be_empty out
'
+test_expect_success 'i16 limits range' '
+ test-tool parse-options --i16 32767 >out &&
+ test_grep "i16: 32767" out &&
+ test_must_fail test-tool parse-options --i16 32768 2>err &&
+ test_grep "value 32768 for option .i16. not in range \[-32768,32767\]" err &&
+
+ test-tool parse-options --i16 -32768 >out &&
+ test_grep "i16: -32768" out &&
+ test_must_fail test-tool parse-options --i16 -32769 2>err &&
+ test_grep "value -32769 for option .i16. not in range \[-32768,32767\]" err
+'
+
+test_expect_success 'u16 limits range' '
+ test-tool parse-options --u16 65535 >out &&
+ test_grep "u16: 65535" out &&
+ test_must_fail test-tool parse-options --u16 65536 2>err &&
+ test_grep "value 65536 for option .u16. not in range \[0,65535\]" err
+'
+
test_done
diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh
index 5c9dc90d0b..ca8568067d 100755
--- a/t/t0050-filesystem.sh
+++ b/t/t0050-filesystem.sh
@@ -10,53 +10,35 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
auml=$(printf '\303\244')
aumlcdiar=$(printf '\141\314\210')
-if test_have_prereq CASE_INSENSITIVE_FS
-then
- say "will test on a case insensitive filesystem"
- test_case=test_expect_failure
-else
- test_case=test_expect_success
-fi
-
if test_have_prereq UTF8_NFD_TO_NFC
then
- say "will test on a unicode corrupting filesystem"
test_unicode=test_expect_failure
else
test_unicode=test_expect_success
fi
-test_have_prereq SYMLINKS ||
- say "will test on a filesystem lacking symbolic links"
-
-if test_have_prereq CASE_INSENSITIVE_FS
-then
-test_expect_success "detection of case insensitive filesystem during repo init" '
+test_expect_success CASE_INSENSITIVE_FS "detection of case insensitive filesystem during repo init" '
test $(git config --bool core.ignorecase) = true
'
-else
-test_expect_success "detection of case insensitive filesystem during repo init" '
+
+test_expect_success !CASE_INSENSITIVE_FS "detection of case insensitive filesystem during repo init" '
{
test_must_fail git config --bool core.ignorecase >/dev/null ||
test $(git config --bool core.ignorecase) = false
}
'
-fi
-if test_have_prereq SYMLINKS
-then
-test_expect_success "detection of filesystem w/o symlink support during repo init" '
+test_expect_success SYMLINKS "detection of filesystem w/o symlink support during repo init" '
{
test_must_fail git config --bool core.symlinks ||
test "$(git config --bool core.symlinks)" = true
}
'
-else
-test_expect_success "detection of filesystem w/o symlink support during repo init" '
+
+test_expect_success !SYMLINKS "detection of filesystem w/o symlink support during repo init" '
v=$(git config --bool core.symlinks) &&
test "$v" = false
'
-fi
test_expect_success "setup case tests" '
git config core.ignorecase true &&
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index dbb2e73bcd..8545cdfab5 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -592,17 +592,19 @@ test_lazy_prereq CAN_EXEC_IN_PWD '
./git rev-parse
'
+test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'setup runtime prefix' '
+ mkdir -p pretend/bin &&
+ cp "$GIT_EXEC_PATH"/git$X pretend/bin/
+'
+
test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' '
- mkdir -p pretend/bin pretend/libexec/git-core &&
+ mkdir -p pretend/libexec/git-core &&
echo "echo HERE" | write_script pretend/libexec/git-core/git-here &&
- cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
GIT_EXEC_PATH= ./pretend/bin/git here >actual &&
echo HERE >expect &&
test_cmp expect actual'
test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' '
- mkdir -p pretend/bin &&
- cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
git config yes.path "%(prefix)/yes" &&
GIT_EXEC_PATH= ./pretend/bin/git config --path yes.path >actual &&
echo "$(pwd)/pretend/yes" >expect &&
diff --git a/t/t0063-string-list.sh b/t/t0063-string-list.sh
deleted file mode 100755
index aac63ba506..0000000000
--- a/t/t0063-string-list.sh
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2012 Michael Haggerty
-#
-
-test_description='Test string list functionality'
-
-. ./test-lib.sh
-
-test_split () {
- cat >expected &&
- test_expect_success "split $1 at $2, max $3" "
- test-tool string-list split '$1' '$2' '$3' >actual &&
- test_cmp expected actual &&
- test-tool string-list split_in_place '$1' '$2' '$3' >actual &&
- test_cmp expected actual
- "
-}
-
-test_split_in_place() {
- cat >expected &&
- test_expect_success "split (in place) $1 at $2, max $3" "
- test-tool string-list split_in_place '$1' '$2' '$3' >actual &&
- test_cmp expected actual
- "
-}
-
-test_split "foo:bar:baz" ":" "-1" <<EOF
-3
-[0]: "foo"
-[1]: "bar"
-[2]: "baz"
-EOF
-
-test_split "foo:bar:baz" ":" "0" <<EOF
-1
-[0]: "foo:bar:baz"
-EOF
-
-test_split "foo:bar:baz" ":" "1" <<EOF
-2
-[0]: "foo"
-[1]: "bar:baz"
-EOF
-
-test_split "foo:bar:baz" ":" "2" <<EOF
-3
-[0]: "foo"
-[1]: "bar"
-[2]: "baz"
-EOF
-
-test_split "foo:bar:" ":" "-1" <<EOF
-3
-[0]: "foo"
-[1]: "bar"
-[2]: ""
-EOF
-
-test_split "" ":" "-1" <<EOF
-1
-[0]: ""
-EOF
-
-test_split ":" ":" "-1" <<EOF
-2
-[0]: ""
-[1]: ""
-EOF
-
-test_split_in_place "foo:;:bar:;:baz:;:" ":;" "-1" <<EOF
-10
-[0]: "foo"
-[1]: ""
-[2]: ""
-[3]: "bar"
-[4]: ""
-[5]: ""
-[6]: "baz"
-[7]: ""
-[8]: ""
-[9]: ""
-EOF
-
-test_split_in_place "foo:;:bar:;:baz" ":;" "0" <<EOF
-1
-[0]: "foo:;:bar:;:baz"
-EOF
-
-test_split_in_place "foo:;:bar:;:baz" ":;" "1" <<EOF
-2
-[0]: "foo"
-[1]: ";:bar:;:baz"
-EOF
-
-test_split_in_place "foo:;:bar:;:baz" ":;" "2" <<EOF
-3
-[0]: "foo"
-[1]: ""
-[2]: ":bar:;:baz"
-EOF
-
-test_split_in_place "foo:;:bar:;:" ":;" "-1" <<EOF
-7
-[0]: "foo"
-[1]: ""
-[2]: ""
-[3]: "bar"
-[4]: ""
-[5]: ""
-[6]: ""
-EOF
-
-test_expect_success "test filter_string_list" '
- test "x-" = "x$(test-tool string-list filter - y)" &&
- test "x-" = "x$(test-tool string-list filter no y)" &&
- test yes = "$(test-tool string-list filter yes y)" &&
- test yes = "$(test-tool string-list filter no:yes y)" &&
- test yes = "$(test-tool string-list filter yes:no y)" &&
- test y1:y2 = "$(test-tool string-list filter y1:y2 y)" &&
- test y2:y1 = "$(test-tool string-list filter y2:y1 y)" &&
- test "x-" = "x$(test-tool string-list filter x1:x2 y)"
-'
-
-test_expect_success "test remove_duplicates" '
- test "x-" = "x$(test-tool string-list remove_duplicates -)" &&
- test "x" = "x$(test-tool string-list remove_duplicates "")" &&
- test a = "$(test-tool string-list remove_duplicates a)" &&
- test a = "$(test-tool string-list remove_duplicates a:a)" &&
- test a = "$(test-tool string-list remove_duplicates a:a:a:a:a)" &&
- test a:b = "$(test-tool string-list remove_duplicates a:b)" &&
- test a:b = "$(test-tool string-list remove_duplicates a:a:b)" &&
- test a:b = "$(test-tool string-list remove_duplicates a:b:b)" &&
- test a:b:c = "$(test-tool string-list remove_duplicates a:b:c)" &&
- test a:b:c = "$(test-tool string-list remove_duplicates a:a:b:c)" &&
- test a:b:c = "$(test-tool string-list remove_duplicates a:b:b:c)" &&
- test a:b:c = "$(test-tool string-list remove_duplicates a:b:c:c)" &&
- test a:b:c = "$(test-tool string-list remove_duplicates a:a:b:b:c:c)" &&
- test a:b:c = "$(test-tool string-list remove_duplicates a:a:a:b:b:b:c:c:c)"
-'
-
-test_done
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index ab80c9ef13..d901588294 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -128,7 +128,7 @@ test_expect_success 'second commit has cache-tree' '
test_cache_tree
'
-test_expect_success PERL 'commit --interactive gives cache-tree on partial commit' '
+test_expect_success 'commit --interactive gives cache-tree on partial commit' '
test_when_finished "git reset --hard" &&
cat <<-\EOT >foo.c &&
int foo()
@@ -162,7 +162,7 @@ test_expect_success PERL 'commit --interactive gives cache-tree on partial commi
test_cache_tree expected.status
'
-test_expect_success PERL 'commit -p with shrinking cache-tree' '
+test_expect_success 'commit -p with shrinking cache-tree' '
mkdir -p deep/very-long-subdir &&
echo content >deep/very-long-subdir/file &&
git add deep &&
diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh
index e11d819b62..e38ca7a901 100755
--- a/t/t0091-bugreport.sh
+++ b/t/t0091-bugreport.sh
@@ -47,7 +47,8 @@ test_expect_success 'sanity check "System Info" section' '
# This is bound to differ from environment to environment,
# so we just do some rather high-level checks.
grep "uname: ." system &&
- grep "compiler info: ." system
+ grep "compiler info: ." system &&
+ grep "zlib." system
'
test_expect_success 'dies if file with same name as report already exists' '
diff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh
index eff9a59dbd..96c68f65df 100755
--- a/t/t0210-trace2-normal.sh
+++ b/t/t0210-trace2-normal.sh
@@ -53,10 +53,41 @@ GIT_TRACE2_BRIEF=1 && export GIT_TRACE2_BRIEF
#
# Implicit return from cmd_<verb> function propagates <code>.
+scrub_normal () {
+ # Scrub the variable fields from the normal trace2 output to make
+ # testing easier:
+ #
+ # 1. Various messages include an elapsed time in the middle of the
+ # message. Replace the time with a placeholder to simplify our
+ # HEREDOC in the test script.
+ #
+ # 2. We expect:
+ #
+ # start <argv0> [<argv1> [<argv2> [...]]]
+ #
+ # where argv0 might be a relative or absolute path, with or
+ # without quotes, and platform dependent. Replace argv0 with a
+ # token for HEREDOC matching in the test script.
+ #
+ # 3. Likewise, the 'cmd_path' message breaks out argv[0].
+ #
+ # This line is only emitted when RUNTIME_PREFIX is defined,
+ # so just omit it for testing purposes.
+ #
+ # 4. 'cmd_ancestry' is not implemented everywhere, so for portability's
+ # sake, skip it when parsing normal.
+ sed \
+ -e 's/elapsed:[0-9]*\.[0-9][0-9]*\([eE][-+]\{0,1\}[0-9][0-9]*\)\{0,1\}/elapsed:_TIME_/g' \
+ -e "s/^start '[^']*' \(.*\)/start _EXE_ \1/" \
+ -e 's/^start [^ ][^ ]* \(.*\)/start _EXE_ \1/' \
+ -e '/^cmd_path/d' \
+ -e '/^cmd_ancestry/d'
+}
+
test_expect_success 'normal stream, return code 0' '
test_when_finished "rm trace.normal actual expect" &&
GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 0 &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 001return 0
@@ -70,7 +101,7 @@ test_expect_success 'normal stream, return code 0' '
test_expect_success 'normal stream, return code 1' '
test_when_finished "rm trace.normal actual expect" &&
test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 1 &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 001return 1
@@ -85,7 +116,7 @@ test_expect_success 'automatic filename' '
test_when_finished "rm -r traces actual expect" &&
mkdir traces &&
GIT_TRACE2="$(pwd)/traces" test-tool trace2 001return 0 &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <"$(ls traces/*)" >actual &&
+ scrub_normal <"$(ls traces/*)" >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 001return 0
@@ -103,7 +134,7 @@ test_expect_success 'automatic filename' '
test_expect_success 'normal stream, exit code 0' '
test_when_finished "rm trace.normal actual expect" &&
GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 0 &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 002exit 0
@@ -117,7 +148,7 @@ test_expect_success 'normal stream, exit code 0' '
test_expect_success 'normal stream, exit code 1' '
test_when_finished "rm trace.normal actual expect" &&
test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 1 &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 002exit 1
@@ -135,7 +166,7 @@ test_expect_success 'normal stream, exit code 1' '
test_expect_success 'normal stream, error event' '
test_when_finished "rm trace.normal actual expect" &&
GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 003error "hello world" "this is a test" &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\''
@@ -155,7 +186,7 @@ test_expect_success 'normal stream, error event' '
test_expect_success 'BUG messages are written to trace2' '
test_when_finished "rm trace.normal actual expect" &&
test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 007bug &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 007bug
@@ -179,7 +210,7 @@ test_expect_success 'bug messages with BUG_if_bug() are written to trace2' '
sed "s/^.*: //" <err >actual &&
test_cmp expect actual &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 008bug
@@ -205,7 +236,7 @@ test_expect_success 'bug messages without explicit BUG_if_bug() are written to t
sed "s/^.*: //" <err >actual &&
test_cmp expect actual &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 009bug_BUG
@@ -230,7 +261,7 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' '
sed "s/^.*: //" <err >actual &&
test_cmp expect actual &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 010bug_BUG
@@ -243,6 +274,15 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' '
test_cmp expect actual
'
+test_expect_success 'a valueless true configuration variable is handled' '
+ test_when_finished "rm -f trace2.normal actual expect" &&
+ echo >expect &&
+ GIT_TRACE2="$(pwd)/trace2.normal" \
+ GIT_TRACE2_CONFIG_PARAMS=foo.true \
+ git -c foo.true config foo.true >actual &&
+ test_cmp expect actual
+'
+
sane_unset GIT_TRACE2_BRIEF
# Now test without environment variables and get all Trace2 settings
@@ -253,7 +293,7 @@ test_expect_success 'using global config, normal stream, return code 0' '
test_config_global trace2.normalBrief 1 &&
test_config_global trace2.normalTarget "$(pwd)/trace.normal" &&
test-tool trace2 001return 0 &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 001return 0
@@ -271,7 +311,7 @@ test_expect_success 'using global config with include' '
mv "$(pwd)/.gitconfig" "$(pwd)/real.gitconfig" &&
test_config_global include.path "$(pwd)/real.gitconfig" &&
test-tool trace2 001return 0 &&
- perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
+ scrub_normal <trace.normal >actual &&
cat >expect <<-EOF &&
version $V
start _EXE_ trace2 001return 0
diff --git a/t/t0210/scrub_normal.perl b/t/t0210/scrub_normal.perl
deleted file mode 100644
index 7cc4de392a..0000000000
--- a/t/t0210/scrub_normal.perl
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/perl
-#
-# Scrub the variable fields from the normal trace2 output to
-# make testing easier.
-
-use strict;
-use warnings;
-
-my $float = '[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?';
-
-# This code assumes that the trace2 data was written with bare
-# turned on (which omits the "<clock> <file>:<line>" prefix.
-
-while (<>) {
- # Various messages include an elapsed time in the middle
- # of the message. Replace the time with a placeholder to
- # simplify our HEREDOC in the test script.
- s/elapsed:$float/elapsed:_TIME_/g;
-
- my $line = $_;
-
- # we expect:
- # start <argv0> [<argv1> [<argv2> [...]]]
- #
- # where argv0 might be a relative or absolute path, with
- # or without quotes, and platform dependent. Replace argv0
- # with a token for HEREDOC matching in the test script.
-
- if ($line =~ m/^start/) {
- $line =~ /^start\s+(.*)/;
- my $argv = $1;
- $argv =~ m/(\'[^\']*\'|[^ ]+)\s+(.*)/;
- my $argv_0 = $1;
- my $argv_rest = $2;
-
- print "start _EXE_ $argv_rest\n";
- }
- elsif ($line =~ m/^cmd_path/) {
- # Likewise, the 'cmd_path' message breaks out argv[0].
- #
- # This line is only emitted when RUNTIME_PREFIX is defined,
- # so just omit it for testing purposes.
- # print "cmd_path _EXE_\n";
- }
- elsif ($line =~ m/^cmd_ancestry/) {
- # 'cmd_ancestry' is not implemented everywhere, so for portability's
- # sake, skip it when parsing normal.
- #
- # print "$line";
- }
- else {
- print "$line";
- }
-}
diff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh
index bac9046540..760cf69087 100755
--- a/t/t0211-trace2-perf.sh
+++ b/t/t0211-trace2-perf.sh
@@ -4,6 +4,12 @@ test_description='test trace2 facility (perf target)'
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping trace2 tests; Perl not available'
+ test_done
+fi
+
# Turn off any inherited trace2 settings for this test.
sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT
sane_unset GIT_TRACE2_PERF_BRIEF
diff --git a/t/t0411-clone-from-partial.sh b/t/t0411-clone-from-partial.sh
index 196fc61784..9e6bca5625 100755
--- a/t/t0411-clone-from-partial.sh
+++ b/t/t0411-clone-from-partial.sh
@@ -59,6 +59,12 @@ test_expect_success 'pack-objects should fetch from promisor remote and execute
test_expect_success 'clone from promisor remote does not lazy-fetch by default' '
rm -f script-executed &&
+
+ # The --path-walk feature of "git pack-objects" is not
+ # compatible with this kind of fetch from an incomplete repo.
+ GIT_TEST_PACK_PATH_WALK=0 &&
+ export GIT_TEST_PACK_PATH_WALK &&
+
test_must_fail git clone evil no-lazy 2>err &&
test_grep "lazy fetching disabled" err &&
test_path_is_missing script-executed
diff --git a/t/t0450-txt-doc-vs-help.sh b/t/t0450-txt-doc-vs-help.sh
index 853101b86e..e12e18f97f 100755
--- a/t/t0450-txt-doc-vs-help.sh
+++ b/t/t0450-txt-doc-vs-help.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-test_description='assert (unbuilt) Documentation/*.txt and -h output
+test_description='assert (unbuilt) Documentation/*.adoc and -h output
Run this with --debug to see a summary of where we still fail to make
the two versions consistent with one another.'
@@ -11,11 +11,11 @@ test_expect_success 'setup: list of builtins' '
git --list-cmds=builtins >builtins
'
-test_expect_success 'list of txt and help mismatches is sorted' '
- sort -u "$TEST_DIRECTORY"/t0450/txt-help-mismatches >expect &&
- if ! test_cmp expect "$TEST_DIRECTORY"/t0450/txt-help-mismatches
+test_expect_success 'list of adoc and help mismatches is sorted' '
+ sort -u "$TEST_DIRECTORY"/t0450/adoc-help-mismatches >expect &&
+ if ! test_cmp expect "$TEST_DIRECTORY"/t0450/adoc-help-mismatches
then
- BUG "please keep the list of txt and help mismatches sorted"
+ BUG "please keep the list of adoc and help mismatches sorted"
fi
'
@@ -40,20 +40,20 @@ help_to_synopsis () {
echo "$out"
}
-builtin_to_txt () {
- echo "$GIT_BUILD_DIR/Documentation/git-$1.txt"
+builtin_to_adoc () {
+ echo "$GIT_SOURCE_DIR/Documentation/git-$1.adoc"
}
-txt_to_synopsis () {
+adoc_to_synopsis () {
builtin="$1" &&
out_dir="out/$builtin" &&
- out="$out_dir/txt.synopsis" &&
+ out="$out_dir/adoc.synopsis" &&
if test -f "$out"
then
echo "$out" &&
return 0
fi &&
- b2t="$(builtin_to_txt "$builtin")" &&
+ b2t="$(builtin_to_adoc "$builtin")" &&
sed -n \
-E '/^\[(verse|synopsis)\]$/,/^$/ {
/^$/d;
@@ -109,29 +109,38 @@ do
fi
'
- txt="$(builtin_to_txt "$builtin")" &&
- preq="$(echo BUILTIN_TXT_$builtin | tr '[:lower:]-' '[:upper:]_')" &&
+ adoc="$(builtin_to_adoc "$builtin")" &&
+ preq="$(echo BUILTIN_ADOC_$builtin | tr '[:lower:]-' '[:upper:]_')" &&
- if test -f "$txt"
+ # If and only if *.adoc is missing, builtin shall be listed in t0450/adoc-missing.
+ if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/adoc-missing
then
+ test_expect_success "$builtin appropriately marked as not having .adoc" '
+ ! test -f "$adoc"
+ '
+ else
test_set_prereq "$preq"
- fi &&
- # *.txt output assertions
- test_expect_success "$preq" "$builtin *.txt SYNOPSIS has dashed labels" '
- check_dashed_labels "$(txt_to_synopsis "$builtin")"
+ test_expect_success "$builtin appropriately marked as having .adoc" '
+ test -f "$adoc"
+ '
+ fi
+
+ # *.adoc output assertions
+ test_expect_success "$preq" "$builtin *.adoc SYNOPSIS has dashed labels" '
+ check_dashed_labels "$(adoc_to_synopsis "$builtin")"
'
- # *.txt output consistency assertions
+ # *.adoc output consistency assertions
result=
- if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/txt-help-mismatches
+ if grep -q "^$builtin$" "$TEST_DIRECTORY"/t0450/adoc-help-mismatches
then
result=failure
else
result=success
fi &&
test_expect_$result "$preq" "$builtin -h output and SYNOPSIS agree" '
- t2s="$(txt_to_synopsis "$builtin")" &&
+ t2s="$(adoc_to_synopsis "$builtin")" &&
if test "$builtin" = "merge-tree"
then
test_when_finished "rm -f t2s.new" &&
@@ -140,17 +149,17 @@ do
fi &&
h2s="$(help_to_synopsis "$builtin")" &&
- # The *.txt and -h use different spacing for the
+ # The *.adoc and -h use different spacing for the
# alignment of continued usage output, normalize it.
- align_after_nl "$builtin" <"$t2s" >txt &&
+ align_after_nl "$builtin" <"$t2s" >adoc &&
align_after_nl "$builtin" <"$h2s" >help &&
- test_cmp txt help
+ test_cmp adoc help
'
- if test_have_prereq "$preq" && test -e txt && test -e help
+ if test_have_prereq "$preq" && test -e adoc && test -e help
then
test_debug '
- if test_cmp txt help >cmp 2>/dev/null
+ if test_cmp adoc help >cmp 2>/dev/null
then
echo "=== DONE: $builtin ==="
else
@@ -161,7 +170,7 @@ do
# Not in test_expect_success in case --run is being
# used with --debug
- rm -f txt help tmp 2>/dev/null
+ rm -f adoc help tmp 2>/dev/null
fi
done <builtins
diff --git a/t/t0450/txt-help-mismatches b/t/t0450/adoc-help-mismatches
index 28003f18c9..2c6ecd5fc8 100644
--- a/t/t0450/txt-help-mismatches
+++ b/t/t0450/adoc-help-mismatches
@@ -17,7 +17,6 @@ fast-export
fast-import
fetch-pack
fmt-merge-msg
-for-each-ref
format-patch
fsck-objects
fsmonitor--daemon
@@ -38,14 +37,12 @@ merge-one-file
multi-pack-index
name-rev
notes
-pack-objects
push
range-diff
rebase
remote
remote-ext
remote-fd
-repack
reset
restore
rev-parse
diff --git a/t/t0450/adoc-missing b/t/t0450/adoc-missing
new file mode 100644
index 0000000000..1ec9f8dcf3
--- /dev/null
+++ b/t/t0450/adoc-missing
@@ -0,0 +1,9 @@
+checkout--worker
+merge-ours
+merge-recursive
+merge-recursive-ours
+merge-recursive-theirs
+merge-subtree
+pickaxe
+submodule--helper
+upload-archive--writer
diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh
index d4a08b823b..0ef483659d 100755
--- a/t/t0602-reffiles-fsck.sh
+++ b/t/t0602-reffiles-fsck.sh
@@ -14,222 +14,248 @@ test_expect_success 'ref name should be checked' '
git init repo &&
branch_dir_prefix=.git/refs/heads &&
tag_dir_prefix=.git/refs/tags &&
- cd repo &&
-
- git commit --allow-empty -m initial &&
- git checkout -b default-branch &&
- git tag default-tag &&
- git tag multi_hierarchy/default-tag &&
-
- cp $branch_dir_prefix/default-branch $branch_dir_prefix/@ &&
- git refs verify 2>err &&
- test_must_be_empty err &&
- rm $branch_dir_prefix/@ &&
-
- cp $tag_dir_prefix/default-tag $tag_dir_prefix/tag-1.lock &&
- git refs verify 2>err &&
- rm $tag_dir_prefix/tag-1.lock &&
- test_must_be_empty err &&
-
- cp $tag_dir_prefix/default-tag $tag_dir_prefix/.lock &&
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: refs/tags/.lock: badRefName: invalid refname format
- EOF
- rm $tag_dir_prefix/.lock &&
- test_cmp expect err &&
-
- for refname in ".refname-starts-with-dot" "~refname-has-stride"
- do
- cp $branch_dir_prefix/default-branch "$branch_dir_prefix/$refname" &&
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: refs/heads/$refname: badRefName: invalid refname format
- EOF
- rm "$branch_dir_prefix/$refname" &&
- test_cmp expect err || return 1
- done &&
+ (
+ cd repo &&
- for refname in ".refname-starts-with-dot" "~refname-has-stride"
- do
- cp $tag_dir_prefix/default-tag "$tag_dir_prefix/$refname" &&
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: refs/tags/$refname: badRefName: invalid refname format
- EOF
- rm "$tag_dir_prefix/$refname" &&
- test_cmp expect err || return 1
- done &&
+ git commit --allow-empty -m initial &&
+ git checkout -b default-branch &&
+ git tag default-tag &&
+ git tag multi_hierarchy/default-tag &&
- for refname in ".refname-starts-with-dot" "~refname-has-stride"
- do
- cp $tag_dir_prefix/multi_hierarchy/default-tag "$tag_dir_prefix/multi_hierarchy/$refname" &&
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: refs/tags/multi_hierarchy/$refname: badRefName: invalid refname format
- EOF
- rm "$tag_dir_prefix/multi_hierarchy/$refname" &&
- test_cmp expect err || return 1
- done &&
+ cp $branch_dir_prefix/default-branch $branch_dir_prefix/@ &&
+ git refs verify 2>err &&
+ test_must_be_empty err &&
+ rm $branch_dir_prefix/@ &&
- for refname in ".refname-starts-with-dot" "~refname-has-stride"
- do
- mkdir "$branch_dir_prefix/$refname" &&
- cp $branch_dir_prefix/default-branch "$branch_dir_prefix/$refname/default-branch" &&
+ cp $tag_dir_prefix/default-tag $tag_dir_prefix/tag-1.lock &&
+ git refs verify 2>err &&
+ rm $tag_dir_prefix/tag-1.lock &&
+ test_must_be_empty err &&
+
+ cp $tag_dir_prefix/default-tag $tag_dir_prefix/.lock &&
test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
- error: refs/heads/$refname/default-branch: badRefName: invalid refname format
+ error: refs/tags/.lock: badRefName: invalid refname format
EOF
- rm -r "$branch_dir_prefix/$refname" &&
- test_cmp expect err || return 1
- done
+ rm $tag_dir_prefix/.lock &&
+ test_cmp expect err &&
+
+ for refname in ".refname-starts-with-dot" "~refname-has-stride"
+ do
+ cp $branch_dir_prefix/default-branch "$branch_dir_prefix/$refname" &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/heads/$refname: badRefName: invalid refname format
+ EOF
+ rm "$branch_dir_prefix/$refname" &&
+ test_cmp expect err || return 1
+ done &&
+
+ for refname in ".refname-starts-with-dot" "~refname-has-stride"
+ do
+ cp $tag_dir_prefix/default-tag "$tag_dir_prefix/$refname" &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/tags/$refname: badRefName: invalid refname format
+ EOF
+ rm "$tag_dir_prefix/$refname" &&
+ test_cmp expect err || return 1
+ done &&
+
+ for refname in ".refname-starts-with-dot" "~refname-has-stride"
+ do
+ cp $tag_dir_prefix/multi_hierarchy/default-tag "$tag_dir_prefix/multi_hierarchy/$refname" &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/tags/multi_hierarchy/$refname: badRefName: invalid refname format
+ EOF
+ rm "$tag_dir_prefix/multi_hierarchy/$refname" &&
+ test_cmp expect err || return 1
+ done &&
+
+ for refname in ".refname-starts-with-dot" "~refname-has-stride"
+ do
+ mkdir "$branch_dir_prefix/$refname" &&
+ cp $branch_dir_prefix/default-branch "$branch_dir_prefix/$refname/default-branch" &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/heads/$refname/default-branch: badRefName: invalid refname format
+ EOF
+ rm -r "$branch_dir_prefix/$refname" &&
+ test_cmp expect err || return 1
+ done
+ )
'
test_expect_success 'ref name check should be adapted into fsck messages' '
test_when_finished "rm -rf repo" &&
git init repo &&
branch_dir_prefix=.git/refs/heads &&
- cd repo &&
- git commit --allow-empty -m initial &&
- git checkout -b branch-1 &&
-
- cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 &&
- git -c fsck.badRefName=warn refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/.branch-1: badRefName: invalid refname format
- EOF
- rm $branch_dir_prefix/.branch-1 &&
- test_cmp expect err &&
-
- cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 &&
- git -c fsck.badRefName=ignore refs verify 2>err &&
- test_must_be_empty err
+ (
+ cd repo &&
+ git commit --allow-empty -m initial &&
+ git checkout -b branch-1 &&
+
+ cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 &&
+ git -c fsck.badRefName=warn refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/.branch-1: badRefName: invalid refname format
+ EOF
+ rm $branch_dir_prefix/.branch-1 &&
+ test_cmp expect err &&
+
+ cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 &&
+ git -c fsck.badRefName=ignore refs verify 2>err &&
+ test_must_be_empty err
+ )
'
-test_expect_success 'ref name check should work for multiple worktrees' '
+test_expect_success 'no refs directory of worktree should not cause problems' '
test_when_finished "rm -rf repo" &&
git init repo &&
-
- cd repo &&
- test_commit initial &&
- git checkout -b branch-1 &&
- test_commit second &&
- git checkout -b branch-2 &&
- test_commit third &&
- git checkout -b branch-3 &&
- git worktree add ./worktree-1 branch-1 &&
- git worktree add ./worktree-2 branch-2 &&
- worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree &&
- worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree &&
-
(
- cd worktree-1 &&
- git update-ref refs/worktree/branch-4 refs/heads/branch-3
- ) &&
- (
- cd worktree-2 &&
- git update-ref refs/worktree/branch-4 refs/heads/branch-3
- ) &&
-
- cp $worktree1_refdir_prefix/branch-4 $worktree1_refdir_prefix/'\'' branch-5'\'' &&
- cp $worktree2_refdir_prefix/branch-4 $worktree2_refdir_prefix/'\''~branch-6'\'' &&
-
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format
- error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format
- EOF
- sort err >sorted_err &&
- test_cmp expect sorted_err &&
-
- for worktree in "worktree-1" "worktree-2"
- do
+ cd repo &&
+ test_commit initial &&
+ git worktree add --detach ./worktree &&
+
(
- cd $worktree &&
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format
- error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format
- EOF
- sort err >sorted_err &&
- test_cmp expect sorted_err || return 1
+ cd worktree &&
+ worktree_refdir="$(git rev-parse --git-dir)/refs" &&
+ # Simulate old directory layout
+ rmdir "$worktree_refdir" &&
+ git refs verify 2>err &&
+ test_must_be_empty err
)
- done
+ )
'
-test_expect_success 'regular ref content should be checked (individual)' '
+test_expect_success 'ref name check should work for multiple worktrees' '
test_when_finished "rm -rf repo" &&
git init repo &&
- branch_dir_prefix=.git/refs/heads &&
- cd repo &&
- test_commit default &&
- mkdir -p "$branch_dir_prefix/a/b" &&
+ (
+ cd repo &&
+ test_commit initial &&
+ git checkout -b branch-1 &&
+ test_commit second &&
+ git checkout -b branch-2 &&
+ test_commit third &&
+ git checkout -b branch-3 &&
+ git worktree add ./worktree-1 branch-1 &&
+ git worktree add ./worktree-2 branch-2 &&
+ worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree &&
+ worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree &&
+
+ (
+ cd worktree-1 &&
+ git update-ref refs/worktree/branch-4 refs/heads/branch-3
+ ) &&
+ (
+ cd worktree-2 &&
+ git update-ref refs/worktree/branch-4 refs/heads/branch-3
+ ) &&
- git refs verify 2>err &&
- test_must_be_empty err &&
+ cp $worktree1_refdir_prefix/branch-4 $worktree1_refdir_prefix/'\'' branch-5'\'' &&
+ cp $worktree2_refdir_prefix/branch-4 $worktree2_refdir_prefix/'\''~branch-6'\'' &&
- for bad_content in "$(git rev-parse main)x" "xfsazqfxcadas" "Xfsazqfxcadas"
- do
- printf "%s" $bad_content >$branch_dir_prefix/branch-bad &&
test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
- error: refs/heads/branch-bad: badRefContent: $bad_content
+ error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format
+ error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format
EOF
- rm $branch_dir_prefix/branch-bad &&
- test_cmp expect err || return 1
- done &&
+ sort err >sorted_err &&
+ test_cmp expect sorted_err &&
+
+ for worktree in "worktree-1" "worktree-2"
+ do
+ (
+ cd $worktree &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format
+ error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format
+ EOF
+ sort err >sorted_err &&
+ test_cmp expect sorted_err || return 1
+ )
+ done
+ )
+'
- for bad_content in "$(git rev-parse main)x" "xfsazqfxcadas" "Xfsazqfxcadas"
- do
- printf "%s" $bad_content >$branch_dir_prefix/a/b/branch-bad &&
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: refs/heads/a/b/branch-bad: badRefContent: $bad_content
- EOF
- rm $branch_dir_prefix/a/b/branch-bad &&
- test_cmp expect err || return 1
- done &&
-
- printf "%s" "$(git rev-parse main)" >$branch_dir_prefix/branch-no-newline &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end
- EOF
- rm $branch_dir_prefix/branch-no-newline &&
- test_cmp expect err &&
-
- for trailing_content in " garbage" " more garbage"
- do
- printf "%s" "$(git rev-parse main)$trailing_content" >$branch_dir_prefix/branch-garbage &&
+test_expect_success 'regular ref content should be checked (individual)' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ branch_dir_prefix=.git/refs/heads &&
+ (
+ cd repo &&
+ test_commit default &&
+ mkdir -p "$branch_dir_prefix/a/b" &&
+
+ git refs verify 2>err &&
+ test_must_be_empty err &&
+
+ for bad_content in "$(git rev-parse main)x" "xfsazqfxcadas" "Xfsazqfxcadas"
+ do
+ printf "%s" $bad_content >$branch_dir_prefix/branch-bad &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/heads/branch-bad: badRefContent: $bad_content
+ EOF
+ rm $branch_dir_prefix/branch-bad &&
+ test_cmp expect err || return 1
+ done &&
+
+ for bad_content in "$(git rev-parse main)x" "xfsazqfxcadas" "Xfsazqfxcadas"
+ do
+ printf "%s" $bad_content >$branch_dir_prefix/a/b/branch-bad &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/heads/a/b/branch-bad: badRefContent: $bad_content
+ EOF
+ rm $branch_dir_prefix/a/b/branch-bad &&
+ test_cmp expect err || return 1
+ done &&
+
+ printf "%s" "$(git rev-parse main)" >$branch_dir_prefix/branch-no-newline &&
git refs verify 2>err &&
cat >expect <<-EOF &&
- warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\''$trailing_content'\''
+ warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end
EOF
- rm $branch_dir_prefix/branch-garbage &&
- test_cmp expect err || return 1
- done &&
+ rm $branch_dir_prefix/branch-no-newline &&
+ test_cmp expect err &&
- printf "%s\n\n\n" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage-special &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/branch-garbage-special: trailingRefContent: has trailing garbage: '\''
+ for trailing_content in " garbage" " more garbage"
+ do
+ printf "%s" "$(git rev-parse main)$trailing_content" >$branch_dir_prefix/branch-garbage &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\''$trailing_content'\''
+ EOF
+ rm $branch_dir_prefix/branch-garbage &&
+ test_cmp expect err || return 1
+ done &&
+ printf "%s\n\n\n" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage-special &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-garbage-special: trailingRefContent: has trailing garbage: '\''
- '\''
- EOF
- rm $branch_dir_prefix/branch-garbage-special &&
- test_cmp expect err &&
- printf "%s\n\n\n garbage" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage-special &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/branch-garbage-special: trailingRefContent: has trailing garbage: '\''
+ '\''
+ EOF
+ rm $branch_dir_prefix/branch-garbage-special &&
+ test_cmp expect err &&
+ printf "%s\n\n\n garbage" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage-special &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-garbage-special: trailingRefContent: has trailing garbage: '\''
- garbage'\''
- EOF
- rm $branch_dir_prefix/branch-garbage-special &&
- test_cmp expect err
+
+ garbage'\''
+ EOF
+ rm $branch_dir_prefix/branch-garbage-special &&
+ test_cmp expect err
+ )
'
test_expect_success 'regular ref content should be checked (aggregate)' '
@@ -237,99 +263,103 @@ test_expect_success 'regular ref content should be checked (aggregate)' '
git init repo &&
branch_dir_prefix=.git/refs/heads &&
tag_dir_prefix=.git/refs/tags &&
- cd repo &&
- test_commit default &&
- mkdir -p "$branch_dir_prefix/a/b" &&
-
- bad_content_1=$(git rev-parse main)x &&
- bad_content_2=xfsazqfxcadas &&
- bad_content_3=Xfsazqfxcadas &&
- printf "%s" $bad_content_1 >$tag_dir_prefix/tag-bad-1 &&
- printf "%s" $bad_content_2 >$tag_dir_prefix/tag-bad-2 &&
- printf "%s" $bad_content_3 >$branch_dir_prefix/a/b/branch-bad &&
- printf "%s" "$(git rev-parse main)" >$branch_dir_prefix/branch-no-newline &&
- printf "%s garbage" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage &&
-
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: refs/heads/a/b/branch-bad: badRefContent: $bad_content_3
- error: refs/tags/tag-bad-1: badRefContent: $bad_content_1
- error: refs/tags/tag-bad-2: badRefContent: $bad_content_2
- warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\''
- warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end
- EOF
- sort err >sorted_err &&
- test_cmp expect sorted_err
+ (
+ cd repo &&
+ test_commit default &&
+ mkdir -p "$branch_dir_prefix/a/b" &&
+
+ bad_content_1=$(git rev-parse main)x &&
+ bad_content_2=xfsazqfxcadas &&
+ bad_content_3=Xfsazqfxcadas &&
+ printf "%s" $bad_content_1 >$tag_dir_prefix/tag-bad-1 &&
+ printf "%s" $bad_content_2 >$tag_dir_prefix/tag-bad-2 &&
+ printf "%s" $bad_content_3 >$branch_dir_prefix/a/b/branch-bad &&
+ printf "%s" "$(git rev-parse main)" >$branch_dir_prefix/branch-no-newline &&
+ printf "%s garbage" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage &&
+
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/heads/a/b/branch-bad: badRefContent: $bad_content_3
+ error: refs/tags/tag-bad-1: badRefContent: $bad_content_1
+ error: refs/tags/tag-bad-2: badRefContent: $bad_content_2
+ warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\''
+ warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end
+ EOF
+ sort err >sorted_err &&
+ test_cmp expect sorted_err
+ )
'
test_expect_success 'textual symref content should be checked (individual)' '
test_when_finished "rm -rf repo" &&
git init repo &&
branch_dir_prefix=.git/refs/heads &&
- cd repo &&
- test_commit default &&
- mkdir -p "$branch_dir_prefix/a/b" &&
+ (
+ cd repo &&
+ test_commit default &&
+ mkdir -p "$branch_dir_prefix/a/b" &&
+
+ for good_referent in "refs/heads/branch" "HEAD"
+ do
+ printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good &&
+ git refs verify 2>err &&
+ rm $branch_dir_prefix/branch-good &&
+ test_must_be_empty err || return 1
+ done &&
+
+ for bad_referent in "refs/heads/.branch" "refs/heads/~branch" "refs/heads/?branch"
+ do
+ printf "ref: %s\n" $bad_referent >$branch_dir_prefix/branch-bad &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/heads/branch-bad: badReferentName: points to invalid refname '\''$bad_referent'\''
+ EOF
+ rm $branch_dir_prefix/branch-bad &&
+ test_cmp expect err || return 1
+ done &&
- for good_referent in "refs/heads/branch" "HEAD"
- do
- printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good &&
+ printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline &&
git refs verify 2>err &&
- rm $branch_dir_prefix/branch-good &&
- test_must_be_empty err || return 1
- done &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end
+ EOF
+ rm $branch_dir_prefix/branch-no-newline &&
+ test_cmp expect err &&
- for bad_referent in "refs/heads/.branch" "refs/heads/~branch" "refs/heads/?branch"
- do
- printf "ref: %s\n" $bad_referent >$branch_dir_prefix/branch-bad &&
- test_must_fail git refs verify 2>err &&
+ printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end
+ warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines
+ EOF
+ rm $branch_dir_prefix/a/b/branch-trailing-1 &&
+ test_cmp expect err &&
+
+ printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines
+ EOF
+ rm $branch_dir_prefix/a/b/branch-trailing-2 &&
+ test_cmp expect err &&
+
+ printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 &&
+ git refs verify 2>err &&
cat >expect <<-EOF &&
- error: refs/heads/branch-bad: badReferentName: points to invalid refname '\''$bad_referent'\''
- EOF
- rm $branch_dir_prefix/branch-bad &&
- test_cmp expect err || return 1
- done &&
-
- printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end
- EOF
- rm $branch_dir_prefix/branch-no-newline &&
- test_cmp expect err &&
-
- printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end
- warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines
- EOF
- rm $branch_dir_prefix/a/b/branch-trailing-1 &&
- test_cmp expect err &&
-
- printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines
- EOF
- rm $branch_dir_prefix/a/b/branch-trailing-2 &&
- test_cmp expect err &&
-
- printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines
- EOF
- rm $branch_dir_prefix/a/b/branch-trailing-3 &&
- test_cmp expect err &&
-
- printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end
- warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines
- EOF
- rm $branch_dir_prefix/a/b/branch-complicated &&
- test_cmp expect err
+ warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines
+ EOF
+ rm $branch_dir_prefix/a/b/branch-trailing-3 &&
+ test_cmp expect err &&
+
+ printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end
+ warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines
+ EOF
+ rm $branch_dir_prefix/a/b/branch-complicated &&
+ test_cmp expect err
+ )
'
test_expect_success 'textual symref content should be checked (aggregate)' '
@@ -337,32 +367,34 @@ test_expect_success 'textual symref content should be checked (aggregate)' '
git init repo &&
branch_dir_prefix=.git/refs/heads &&
tag_dir_prefix=.git/refs/tags &&
- cd repo &&
- test_commit default &&
- mkdir -p "$branch_dir_prefix/a/b" &&
-
- printf "ref: refs/heads/branch\n" >$branch_dir_prefix/branch-good &&
- printf "ref: HEAD\n" >$branch_dir_prefix/branch-head &&
- printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline-1 &&
- printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 &&
- printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 &&
- printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 &&
- printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated &&
- printf "ref: refs/heads/.branch\n" >$branch_dir_prefix/branch-bad-1 &&
-
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- error: refs/heads/branch-bad-1: badReferentName: points to invalid refname '\''refs/heads/.branch'\''
- warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end
- warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines
- warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end
- warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines
- warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines
- warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines
- warning: refs/heads/branch-no-newline-1: refMissingNewline: misses LF at the end
- EOF
- sort err >sorted_err &&
- test_cmp expect sorted_err
+ (
+ cd repo &&
+ test_commit default &&
+ mkdir -p "$branch_dir_prefix/a/b" &&
+
+ printf "ref: refs/heads/branch\n" >$branch_dir_prefix/branch-good &&
+ printf "ref: HEAD\n" >$branch_dir_prefix/branch-head &&
+ printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline-1 &&
+ printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 &&
+ printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 &&
+ printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 &&
+ printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated &&
+ printf "ref: refs/heads/.branch\n" >$branch_dir_prefix/branch-bad-1 &&
+
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: refs/heads/branch-bad-1: badReferentName: points to invalid refname '\''refs/heads/.branch'\''
+ warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end
+ warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines
+ warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end
+ warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines
+ warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines
+ warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines
+ warning: refs/heads/branch-no-newline-1: refMissingNewline: misses LF at the end
+ EOF
+ sort err >sorted_err &&
+ test_cmp expect sorted_err
+ )
'
test_expect_success 'the target of the textual symref should be checked' '
@@ -370,230 +402,507 @@ test_expect_success 'the target of the textual symref should be checked' '
git init repo &&
branch_dir_prefix=.git/refs/heads &&
tag_dir_prefix=.git/refs/tags &&
- cd repo &&
- test_commit default &&
- mkdir -p "$branch_dir_prefix/a/b" &&
+ (
+ cd repo &&
+ test_commit default &&
+ mkdir -p "$branch_dir_prefix/a/b" &&
+
+ for good_referent in "refs/heads/branch" "HEAD" "refs/tags/tag"
+ do
+ printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good &&
+ git refs verify 2>err &&
+ rm $branch_dir_prefix/branch-good &&
+ test_must_be_empty err || return 1
+ done &&
+
+ for nonref_referent in "refs-back/heads/branch" "refs-back/tags/tag" "reflogs/refs/heads/branch"
+ do
+ printf "ref: %s\n" $nonref_referent >$branch_dir_prefix/branch-bad-1 &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-bad-1: symrefTargetIsNotARef: points to non-ref target '\''$nonref_referent'\''
+ EOF
+ rm $branch_dir_prefix/branch-bad-1 &&
+ test_cmp expect err || return 1
+ done
+ )
+'
+
+test_expect_success SYMLINKS 'symlink symref content should be checked' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ branch_dir_prefix=.git/refs/heads &&
+ tag_dir_prefix=.git/refs/tags &&
+ (
+ cd repo &&
+ test_commit default &&
+ mkdir -p "$branch_dir_prefix/a/b" &&
- for good_referent in "refs/heads/branch" "HEAD" "refs/tags/tag"
- do
- printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good &&
+ ln -sf ./main $branch_dir_prefix/branch-symbolic-good &&
git refs verify 2>err &&
- rm $branch_dir_prefix/branch-good &&
- test_must_be_empty err || return 1
- done &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref
+ EOF
+ rm $branch_dir_prefix/branch-symbolic-good &&
+ test_cmp expect err &&
- for nonref_referent in "refs-back/heads/branch" "refs-back/tags/tag" "reflogs/refs/heads/branch"
- do
- printf "ref: %s\n" $nonref_referent >$branch_dir_prefix/branch-bad-1 &&
+ ln -sf ../../logs/branch-escape $branch_dir_prefix/branch-symbolic &&
git refs verify 2>err &&
cat >expect <<-EOF &&
- warning: refs/heads/branch-bad-1: symrefTargetIsNotARef: points to non-ref target '\''$nonref_referent'\''
+ warning: refs/heads/branch-symbolic: symlinkRef: use deprecated symbolic link for symref
+ warning: refs/heads/branch-symbolic: symrefTargetIsNotARef: points to non-ref target '\''logs/branch-escape'\''
+ EOF
+ rm $branch_dir_prefix/branch-symbolic &&
+ test_cmp expect err &&
+
+ ln -sf ./"branch " $branch_dir_prefix/branch-symbolic-bad &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-symbolic-bad: symlinkRef: use deprecated symbolic link for symref
+ error: refs/heads/branch-symbolic-bad: badReferentName: points to invalid refname '\''refs/heads/branch '\''
+ EOF
+ rm $branch_dir_prefix/branch-symbolic-bad &&
+ test_cmp expect err &&
+
+ ln -sf ./".tag" $tag_dir_prefix/tag-symbolic-1 &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/tags/tag-symbolic-1: symlinkRef: use deprecated symbolic link for symref
+ error: refs/tags/tag-symbolic-1: badReferentName: points to invalid refname '\''refs/tags/.tag'\''
EOF
- rm $branch_dir_prefix/branch-bad-1 &&
- test_cmp expect err || return 1
- done
+ rm $tag_dir_prefix/tag-symbolic-1 &&
+ test_cmp expect err
+ )
'
-test_expect_success SYMLINKS 'symlink symref content should be checked' '
+test_expect_success SYMLINKS 'symlink symref content should be checked (worktree)' '
test_when_finished "rm -rf repo" &&
git init repo &&
- branch_dir_prefix=.git/refs/heads &&
- tag_dir_prefix=.git/refs/tags &&
- cd repo &&
- test_commit default &&
- mkdir -p "$branch_dir_prefix/a/b" &&
-
- ln -sf ./main $branch_dir_prefix/branch-symbolic-good &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref
- EOF
- rm $branch_dir_prefix/branch-symbolic-good &&
- test_cmp expect err &&
-
- ln -sf ../../logs/branch-escape $branch_dir_prefix/branch-symbolic &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/branch-symbolic: symlinkRef: use deprecated symbolic link for symref
- warning: refs/heads/branch-symbolic: symrefTargetIsNotARef: points to non-ref target '\''logs/branch-escape'\''
- EOF
- rm $branch_dir_prefix/branch-symbolic &&
- test_cmp expect err &&
-
- ln -sf ./"branch " $branch_dir_prefix/branch-symbolic-bad &&
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/branch-symbolic-bad: symlinkRef: use deprecated symbolic link for symref
- error: refs/heads/branch-symbolic-bad: badReferentName: points to invalid refname '\''refs/heads/branch '\''
- EOF
- rm $branch_dir_prefix/branch-symbolic-bad &&
- test_cmp expect err &&
-
- ln -sf ./".tag" $tag_dir_prefix/tag-symbolic-1 &&
- test_must_fail git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/tags/tag-symbolic-1: symlinkRef: use deprecated symbolic link for symref
- error: refs/tags/tag-symbolic-1: badReferentName: points to invalid refname '\''refs/tags/.tag'\''
- EOF
- rm $tag_dir_prefix/tag-symbolic-1 &&
- test_cmp expect err
+ (
+ cd repo &&
+ test_commit default &&
+ git branch branch-1 &&
+ git branch branch-2 &&
+ git branch branch-3 &&
+ git worktree add ./worktree-1 branch-2 &&
+ git worktree add ./worktree-2 branch-3 &&
+ main_worktree_refdir_prefix=.git/refs/heads &&
+ worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree &&
+ worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree &&
+
+ (
+ cd worktree-1 &&
+ git update-ref refs/worktree/branch-4 refs/heads/branch-1
+ ) &&
+ (
+ cd worktree-2 &&
+ git update-ref refs/worktree/branch-4 refs/heads/branch-1
+ ) &&
+
+ ln -sf ../../../../refs/heads/good-branch $worktree1_refdir_prefix/branch-symbolic-good &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: worktrees/worktree-1/refs/worktree/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref
+ EOF
+ rm $worktree1_refdir_prefix/branch-symbolic-good &&
+ test_cmp expect err &&
+
+ ln -sf ../../../../worktrees/worktree-1/good-branch $worktree2_refdir_prefix/branch-symbolic-good &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: worktrees/worktree-2/refs/worktree/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref
+ EOF
+ rm $worktree2_refdir_prefix/branch-symbolic-good &&
+ test_cmp expect err &&
+
+ ln -sf ../../worktrees/worktree-2/good-branch $main_worktree_refdir_prefix/branch-symbolic-good &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref
+ EOF
+ rm $main_worktree_refdir_prefix/branch-symbolic-good &&
+ test_cmp expect err &&
+
+ ln -sf ../../../../logs/branch-escape $worktree1_refdir_prefix/branch-symbolic &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: worktrees/worktree-1/refs/worktree/branch-symbolic: symlinkRef: use deprecated symbolic link for symref
+ warning: worktrees/worktree-1/refs/worktree/branch-symbolic: symrefTargetIsNotARef: points to non-ref target '\''logs/branch-escape'\''
+ EOF
+ rm $worktree1_refdir_prefix/branch-symbolic &&
+ test_cmp expect err &&
+
+ for bad_referent_name in ".tag" "branch "
+ do
+ ln -sf ./"$bad_referent_name" $worktree1_refdir_prefix/bad-symbolic &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: worktrees/worktree-1/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref
+ error: worktrees/worktree-1/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''worktrees/worktree-1/refs/worktree/$bad_referent_name'\''
+ EOF
+ rm $worktree1_refdir_prefix/bad-symbolic &&
+ test_cmp expect err &&
+
+ ln -sf ../../../../refs/heads/"$bad_referent_name" $worktree1_refdir_prefix/bad-symbolic &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: worktrees/worktree-1/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref
+ error: worktrees/worktree-1/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''refs/heads/$bad_referent_name'\''
+ EOF
+ rm $worktree1_refdir_prefix/bad-symbolic &&
+ test_cmp expect err &&
+
+ ln -sf ./"$bad_referent_name" $worktree2_refdir_prefix/bad-symbolic &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: worktrees/worktree-2/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref
+ error: worktrees/worktree-2/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''worktrees/worktree-2/refs/worktree/$bad_referent_name'\''
+ EOF
+ rm $worktree2_refdir_prefix/bad-symbolic &&
+ test_cmp expect err &&
+
+ ln -sf ../../../../refs/heads/"$bad_referent_name" $worktree2_refdir_prefix/bad-symbolic &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: worktrees/worktree-2/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref
+ error: worktrees/worktree-2/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''refs/heads/$bad_referent_name'\''
+ EOF
+ rm $worktree2_refdir_prefix/bad-symbolic &&
+ test_cmp expect err || return 1
+ done
+ )
'
-test_expect_success SYMLINKS 'symlink symref content should be checked (worktree)' '
+test_expect_success 'ref content checks should work with worktrees' '
test_when_finished "rm -rf repo" &&
git init repo &&
- cd repo &&
- test_commit default &&
- git branch branch-1 &&
- git branch branch-2 &&
- git branch branch-3 &&
- git worktree add ./worktree-1 branch-2 &&
- git worktree add ./worktree-2 branch-3 &&
- main_worktree_refdir_prefix=.git/refs/heads &&
- worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree &&
- worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree &&
-
- (
- cd worktree-1 &&
- git update-ref refs/worktree/branch-4 refs/heads/branch-1
- ) &&
(
- cd worktree-2 &&
- git update-ref refs/worktree/branch-4 refs/heads/branch-1
- ) &&
-
- ln -sf ../../../../refs/heads/good-branch $worktree1_refdir_prefix/branch-symbolic-good &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: worktrees/worktree-1/refs/worktree/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref
- EOF
- rm $worktree1_refdir_prefix/branch-symbolic-good &&
- test_cmp expect err &&
-
- ln -sf ../../../../worktrees/worktree-1/good-branch $worktree2_refdir_prefix/branch-symbolic-good &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: worktrees/worktree-2/refs/worktree/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref
- EOF
- rm $worktree2_refdir_prefix/branch-symbolic-good &&
- test_cmp expect err &&
-
- ln -sf ../../worktrees/worktree-2/good-branch $main_worktree_refdir_prefix/branch-symbolic-good &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: refs/heads/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref
- EOF
- rm $main_worktree_refdir_prefix/branch-symbolic-good &&
- test_cmp expect err &&
-
- ln -sf ../../../../logs/branch-escape $worktree1_refdir_prefix/branch-symbolic &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: worktrees/worktree-1/refs/worktree/branch-symbolic: symlinkRef: use deprecated symbolic link for symref
- warning: worktrees/worktree-1/refs/worktree/branch-symbolic: symrefTargetIsNotARef: points to non-ref target '\''logs/branch-escape'\''
- EOF
- rm $worktree1_refdir_prefix/branch-symbolic &&
- test_cmp expect err &&
-
- for bad_referent_name in ".tag" "branch "
- do
- ln -sf ./"$bad_referent_name" $worktree1_refdir_prefix/bad-symbolic &&
- test_must_fail git refs verify 2>err &&
+ cd repo &&
+ test_commit default &&
+ git branch branch-1 &&
+ git branch branch-2 &&
+ git branch branch-3 &&
+ git worktree add ./worktree-1 branch-2 &&
+ git worktree add ./worktree-2 branch-3 &&
+ worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree &&
+ worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree &&
+
+ (
+ cd worktree-1 &&
+ git update-ref refs/worktree/branch-4 refs/heads/branch-1
+ ) &&
+ (
+ cd worktree-2 &&
+ git update-ref refs/worktree/branch-4 refs/heads/branch-1
+ ) &&
+
+ for bad_content in "$(git rev-parse HEAD)x" "xfsazqfxcadas" "Xfsazqfxcadas"
+ do
+ printf "%s" $bad_content >$worktree1_refdir_prefix/bad-branch-1 &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: worktrees/worktree-1/refs/worktree/bad-branch-1: badRefContent: $bad_content
+ EOF
+ rm $worktree1_refdir_prefix/bad-branch-1 &&
+ test_cmp expect err || return 1
+ done &&
+
+ for bad_content in "$(git rev-parse HEAD)x" "xfsazqfxcadas" "Xfsazqfxcadas"
+ do
+ printf "%s" $bad_content >$worktree2_refdir_prefix/bad-branch-2 &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: worktrees/worktree-2/refs/worktree/bad-branch-2: badRefContent: $bad_content
+ EOF
+ rm $worktree2_refdir_prefix/bad-branch-2 &&
+ test_cmp expect err || return 1
+ done &&
+
+ printf "%s" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-no-newline &&
+ git refs verify 2>err &&
cat >expect <<-EOF &&
- warning: worktrees/worktree-1/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref
- error: worktrees/worktree-1/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''worktrees/worktree-1/refs/worktree/$bad_referent_name'\''
+ warning: worktrees/worktree-1/refs/worktree/branch-no-newline: refMissingNewline: misses LF at the end
EOF
- rm $worktree1_refdir_prefix/bad-symbolic &&
+ rm $worktree1_refdir_prefix/branch-no-newline &&
test_cmp expect err &&
- ln -sf ../../../../refs/heads/"$bad_referent_name" $worktree1_refdir_prefix/bad-symbolic &&
- test_must_fail git refs verify 2>err &&
+ printf "%s garbage" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-garbage &&
+ git refs verify 2>err &&
cat >expect <<-EOF &&
- warning: worktrees/worktree-1/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref
- error: worktrees/worktree-1/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''refs/heads/$bad_referent_name'\''
+ warning: worktrees/worktree-1/refs/worktree/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\''
EOF
- rm $worktree1_refdir_prefix/bad-symbolic &&
- test_cmp expect err &&
+ rm $worktree1_refdir_prefix/branch-garbage &&
+ test_cmp expect err
+ )
+'
- ln -sf ./"$bad_referent_name" $worktree2_refdir_prefix/bad-symbolic &&
+test_expect_success SYMLINKS 'the filetype of packed-refs should be checked' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit default &&
+ git branch branch-1 &&
+ git branch branch-2 &&
+ git branch branch-3 &&
+ git pack-refs --all &&
+
+ mv .git/packed-refs .git/packed-refs-back &&
+ ln -sf packed-refs-back .git/packed-refs &&
test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
- warning: worktrees/worktree-2/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref
- error: worktrees/worktree-2/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''worktrees/worktree-2/refs/worktree/$bad_referent_name'\''
+ error: packed-refs: badRefFiletype: not a regular file but a symlink
EOF
- rm $worktree2_refdir_prefix/bad-symbolic &&
+ rm .git/packed-refs &&
test_cmp expect err &&
- ln -sf ../../../../refs/heads/"$bad_referent_name" $worktree2_refdir_prefix/bad-symbolic &&
+ mkdir .git/packed-refs &&
test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
- warning: worktrees/worktree-2/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref
- error: worktrees/worktree-2/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''refs/heads/$bad_referent_name'\''
+ error: packed-refs: badRefFiletype: not a regular file
EOF
- rm $worktree2_refdir_prefix/bad-symbolic &&
- test_cmp expect err || return 1
- done
+ rm -r .git/packed-refs &&
+ test_cmp expect err
+ )
'
-test_expect_success 'ref content checks should work with worktrees' '
+test_expect_success 'empty packed-refs should be reported' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit default &&
+
+ >.git/packed-refs &&
+ git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ warning: packed-refs: emptyPackedRefsFile: file is empty
+ EOF
+ rm .git/packed-refs &&
+ test_cmp expect err
+ )
+'
+
+test_expect_success 'packed-refs header should be checked' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit default &&
+
+ git refs verify 2>err &&
+ test_must_be_empty err &&
+
+ for bad_header in "# pack-refs wit: peeled fully-peeled sorted " \
+ "# pack-refs with traits: peeled fully-peeled sorted " \
+ "# pack-refs with a: peeled fully-peeled" \
+ "# pack-refs with:peeled fully-peeled sorted"
+ do
+ printf "%s\n" "$bad_header" >.git/packed-refs &&
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: packed-refs.header: badPackedRefHeader: '\''$bad_header'\'' does not start with '\''# pack-refs with: '\''
+ EOF
+ rm .git/packed-refs &&
+ test_cmp expect err || return 1
+ done
+ )
+'
+
+test_expect_success 'packed-refs missing header should not be reported' '
test_when_finished "rm -rf repo" &&
git init repo &&
- cd repo &&
- test_commit default &&
- git branch branch-1 &&
- git branch branch-2 &&
- git branch branch-3 &&
- git worktree add ./worktree-1 branch-2 &&
- git worktree add ./worktree-2 branch-3 &&
- worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree &&
- worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree &&
+ (
+ cd repo &&
+ test_commit default &&
+
+ printf "$(git rev-parse HEAD) refs/heads/main\n" >.git/packed-refs &&
+ git refs verify 2>err &&
+ test_must_be_empty err
+ )
+'
+test_expect_success 'packed-refs unknown traits should not be reported' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit default &&
+
+ printf "# pack-refs with: peeled fully-peeled sorted foo\n" >.git/packed-refs &&
+ git refs verify 2>err &&
+ test_must_be_empty err
+ )
+'
+
+test_expect_success 'packed-refs content should be checked' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
(
- cd worktree-1 &&
- git update-ref refs/worktree/branch-4 refs/heads/branch-1
- ) &&
+ cd repo &&
+ test_commit default &&
+ git branch branch-1 &&
+ git branch branch-2 &&
+ git tag -a annotated-tag-1 -m tag-1 &&
+ git tag -a annotated-tag-2 -m tag-2 &&
+
+ branch_1_oid=$(git rev-parse branch-1) &&
+ branch_2_oid=$(git rev-parse branch-2) &&
+ tag_1_oid=$(git rev-parse annotated-tag-1) &&
+ tag_2_oid=$(git rev-parse annotated-tag-2) &&
+ tag_1_peeled_oid=$(git rev-parse annotated-tag-1^{}) &&
+ tag_2_peeled_oid=$(git rev-parse annotated-tag-2^{}) &&
+ short_oid=$(printf "%s" $tag_1_peeled_oid | cut -c 1-4) &&
+
+ cat >.git/packed-refs <<-EOF &&
+ # pack-refs with: peeled fully-peeled sorted
+ $short_oid refs/heads/branch-1
+ ${branch_1_oid}x
+ $branch_2_oid refs/heads/bad-branch
+ $branch_2_oid refs/heads/branch.
+ $tag_1_oid refs/tags/annotated-tag-3
+ ^$short_oid
+ $tag_2_oid refs/tags/annotated-tag-4.
+ ^$tag_2_peeled_oid garbage
+ EOF
+ test_must_fail git refs verify 2>err &&
+ cat >expect <<-EOF &&
+ error: packed-refs line 2: badPackedRefEntry: '\''$short_oid refs/heads/branch-1'\'' has invalid oid
+ error: packed-refs line 3: badPackedRefEntry: has no space after oid '\''$branch_1_oid'\'' but with '\''x'\''
+ error: packed-refs line 4: badRefName: has bad refname '\'' refs/heads/bad-branch'\''
+ error: packed-refs line 5: badRefName: has bad refname '\''refs/heads/branch.'\''
+ error: packed-refs line 7: badPackedRefEntry: '\''$short_oid'\'' has invalid peeled oid
+ error: packed-refs line 8: badRefName: has bad refname '\''refs/tags/annotated-tag-4.'\''
+ error: packed-refs line 9: badPackedRefEntry: has trailing garbage after peeled oid '\'' garbage'\''
+ EOF
+ test_cmp expect err
+ )
+'
+
+test_expect_success 'packed-ref with sorted trait should be checked' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
(
- cd worktree-2 &&
- git update-ref refs/worktree/branch-4 refs/heads/branch-1
- ) &&
+ cd repo &&
+ test_commit default &&
+ git branch branch-1 &&
+ git branch branch-2 &&
+ git tag -a annotated-tag-1 -m tag-1 &&
+ branch_1_oid=$(git rev-parse branch-1) &&
+ branch_2_oid=$(git rev-parse branch-2) &&
+ tag_1_oid=$(git rev-parse annotated-tag-1) &&
+ tag_1_peeled_oid=$(git rev-parse annotated-tag-1^{}) &&
+ refname1="refs/heads/main" &&
+ refname2="refs/heads/foo" &&
+ refname3="refs/tags/foo" &&
+
+ cat >.git/packed-refs <<-EOF &&
+ # pack-refs with: peeled fully-peeled sorted
+ EOF
+ git refs verify 2>err &&
+ rm .git/packed-refs &&
+ test_must_be_empty err &&
- for bad_content in "$(git rev-parse HEAD)x" "xfsazqfxcadas" "Xfsazqfxcadas"
- do
- printf "%s" $bad_content >$worktree1_refdir_prefix/bad-branch-1 &&
+ cat >.git/packed-refs <<-EOF &&
+ # pack-refs with: peeled fully-peeled sorted
+ $branch_2_oid $refname1
+ EOF
+ git refs verify 2>err &&
+ rm .git/packed-refs &&
+ test_must_be_empty err &&
+
+ cat >.git/packed-refs <<-EOF &&
+ # pack-refs with: peeled fully-peeled sorted
+ $branch_2_oid $refname1
+ $branch_1_oid $refname2
+ $tag_1_oid $refname3
+ EOF
test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
- error: worktrees/worktree-1/refs/worktree/bad-branch-1: badRefContent: $bad_content
+ error: packed-refs line 3: packedRefUnsorted: refname '\''$refname2'\'' is less than previous refname '\''$refname1'\''
EOF
- rm $worktree1_refdir_prefix/bad-branch-1 &&
- test_cmp expect err || return 1
- done &&
+ rm .git/packed-refs &&
+ test_cmp expect err &&
- for bad_content in "$(git rev-parse HEAD)x" "xfsazqfxcadas" "Xfsazqfxcadas"
- do
- printf "%s" $bad_content >$worktree2_refdir_prefix/bad-branch-2 &&
+ cat >.git/packed-refs <<-EOF &&
+ # pack-refs with: peeled fully-peeled sorted
+ $tag_1_oid $refname3
+ ^$tag_1_peeled_oid
+ $branch_2_oid $refname2
+ EOF
test_must_fail git refs verify 2>err &&
cat >expect <<-EOF &&
- error: worktrees/worktree-2/refs/worktree/bad-branch-2: badRefContent: $bad_content
- EOF
- rm $worktree2_refdir_prefix/bad-branch-2 &&
- test_cmp expect err || return 1
- done &&
-
- printf "%s" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-no-newline &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: worktrees/worktree-1/refs/worktree/branch-no-newline: refMissingNewline: misses LF at the end
- EOF
- rm $worktree1_refdir_prefix/branch-no-newline &&
- test_cmp expect err &&
-
- printf "%s garbage" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-garbage &&
- git refs verify 2>err &&
- cat >expect <<-EOF &&
- warning: worktrees/worktree-1/refs/worktree/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\''
- EOF
- rm $worktree1_refdir_prefix/branch-garbage &&
- test_cmp expect err
+ error: packed-refs line 4: packedRefUnsorted: refname '\''$refname2'\'' is less than previous refname '\''$refname3'\''
+ EOF
+ rm .git/packed-refs &&
+ test_cmp expect err
+ )
+'
+
+test_expect_success 'packed-ref without sorted trait should not be checked' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit default &&
+ git branch branch-1 &&
+ git branch branch-2 &&
+ git tag -a annotated-tag-1 -m tag-1 &&
+ branch_1_oid=$(git rev-parse branch-1) &&
+ branch_2_oid=$(git rev-parse branch-2) &&
+ tag_1_oid=$(git rev-parse annotated-tag-1) &&
+ tag_1_peeled_oid=$(git rev-parse annotated-tag-1^{}) &&
+ refname1="refs/heads/main" &&
+ refname2="refs/heads/foo" &&
+ refname3="refs/tags/foo" &&
+
+ cat >.git/packed-refs <<-EOF &&
+ # pack-refs with: peeled fully-peeled
+ $branch_2_oid $refname1
+ $branch_1_oid $refname2
+ EOF
+ git refs verify 2>err &&
+ test_must_be_empty err
+ )
+'
+
+test_expect_success '--[no-]references option should apply to fsck' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ branch_dir_prefix=.git/refs/heads &&
+ (
+ cd repo &&
+ test_commit default &&
+ for trailing_content in " garbage" " more garbage"
+ do
+ printf "%s" "$(git rev-parse HEAD)$trailing_content" >$branch_dir_prefix/branch-garbage &&
+ git fsck 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\''$trailing_content'\''
+ EOF
+ rm $branch_dir_prefix/branch-garbage &&
+ test_cmp expect err || return 1
+ done &&
+
+ for trailing_content in " garbage" " more garbage"
+ do
+ printf "%s" "$(git rev-parse HEAD)$trailing_content" >$branch_dir_prefix/branch-garbage &&
+ git fsck --references 2>err &&
+ cat >expect <<-EOF &&
+ warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\''$trailing_content'\''
+ EOF
+ rm $branch_dir_prefix/branch-garbage &&
+ test_cmp expect err || return 1
+ done &&
+
+ for trailing_content in " garbage" " more garbage"
+ do
+ printf "%s" "$(git rev-parse HEAD)$trailing_content" >$branch_dir_prefix/branch-garbage &&
+ git fsck --no-references 2>err &&
+ rm $branch_dir_prefix/branch-garbage &&
+ test_must_be_empty err || return 1
+ done
+ )
'
test_done
diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh
index 4618ffc108..3ea5d51532 100755
--- a/t/t0610-reftable-basics.sh
+++ b/t/t0610-reftable-basics.sh
@@ -14,6 +14,13 @@ export GIT_TEST_DEFAULT_REF_FORMAT
INVALID_OID=$(test_oid 001)
+test_expect_success 'pack-refs does not crash with -h' '
+ test_expect_code 129 git pack-refs -h >usage &&
+ test_grep "[Uu]sage: git pack-refs " usage &&
+ test_expect_code 129 nongit git pack-refs -h >usage &&
+ test_grep "[Uu]sage: git pack-refs " usage
+'
+
test_expect_success 'init: creates basic reftable structures' '
test_when_finished "rm -rf repo" &&
git init repo &&
@@ -470,11 +477,7 @@ test_expect_success !CYGWIN 'ref transaction: many concurrent writers' '
test_commit --no-tag initial &&
head=$(git rev-parse HEAD) &&
- for i in $(test_seq 100)
- do
- printf "%s commit\trefs/heads/branch-%s\n" "$head" "$i" ||
- return 1
- done >expect &&
+ test_seq -f "$head commit\trefs/heads/branch-%d" 100 >expect &&
printf "%s commit\trefs/heads/main\n" "$head" >>expect &&
for i in $(test_seq 100)
@@ -646,9 +649,8 @@ test_expect_success 'basic: commit and list refs' '
test_expect_success 'basic: can write large commit message' '
test_when_finished "rm -rf repo" &&
git init repo &&
- perl -e "
- print \"this is a long commit message\" x 50000
- " >commit-msg &&
+
+ awk "BEGIN { for (i = 0; i < 50000; i++) printf \"%s\", \"this is a long commit message\" }" >commit-msg &&
git -C repo commit --allow-empty --file=../commit-msg
'
diff --git a/t/t0612-reftable-jgit-compatibility.sh b/t/t0612-reftable-jgit-compatibility.sh
index d0d7e80b49..7df2ad5817 100755
--- a/t/t0612-reftable-jgit-compatibility.sh
+++ b/t/t0612-reftable-jgit-compatibility.sh
@@ -112,14 +112,11 @@ test_expect_success 'JGit can read multi-level index' '
cd repo &&
test_commit A &&
- awk "
- BEGIN {
- print \"start\";
- for (i = 0; i < 10000; i++)
- printf \"create refs/heads/branch-%d HEAD\n\", i;
- print \"commit\";
- }
- " >input &&
+ {
+ echo start &&
+ test_seq -f "create refs/heads/branch-%d HEAD" 10000 &&
+ echo commit
+ } >input &&
git update-ref --stdin <input &&
test_same_refs &&
diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh
index e2708e11d5..d77e601111 100755
--- a/t/t0613-reftable-write-options.sh
+++ b/t/t0613-reftable-write-options.sh
@@ -66,11 +66,7 @@ test_expect_success 'many refs results in multiple blocks' '
(
cd repo &&
test_commit initial &&
- for i in $(test_seq 200)
- do
- printf "update refs/heads/branch-%d HEAD\n" "$i" ||
- return 1
- done >input &&
+ test_seq -f "update refs/heads/branch-%d HEAD" 200 >input &&
git update-ref --stdin <input &&
git pack-refs &&
@@ -93,6 +89,9 @@ test_expect_success 'many refs results in multiple blocks' '
restarts: 3
- length: 3289
restarts: 3
+ idx:
+ - length: 103
+ restarts: 1
EOF
test-tool dump-reftable -b .git/reftable/*.ref >actual &&
test_cmp expect actual
@@ -145,7 +144,7 @@ test_expect_success 'small block size fails with large reflog message' '
(
cd repo &&
test_commit A &&
- perl -e "print \"a\" x 500" >logmsg &&
+ test-tool genzeros 500 | tr "\000" "a" >logmsg &&
cat >expect <<-EOF &&
fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
EOF
@@ -177,11 +176,7 @@ test_expect_success 'restart interval at every single record' '
(
cd repo &&
test_commit initial &&
- for i in $(test_seq 10)
- do
- printf "update refs/heads/branch-%d HEAD\n" "$i" ||
- return 1
- done >input &&
+ test_seq -f "update refs/heads/branch-%d HEAD" 10 >input &&
git update-ref --stdin <input &&
git -c reftable.restartInterval=1 pack-refs &&
@@ -221,11 +216,7 @@ test_expect_success 'object index gets written by default with ref index' '
(
cd repo &&
test_commit initial &&
- for i in $(test_seq 5)
- do
- printf "update refs/heads/branch-%d HEAD\n" "$i" ||
- return 1
- done >input &&
+ test_seq -f "update refs/heads/branch-%d HEAD" 5 >input &&
git update-ref --stdin <input &&
git -c reftable.blockSize=100 pack-refs &&
@@ -241,6 +232,9 @@ test_expect_success 'object index gets written by default with ref index' '
restarts: 1
- length: 80
restarts: 1
+ idx:
+ - length: 55
+ restarts: 2
obj:
- length: 11
restarts: 1
@@ -257,11 +251,7 @@ test_expect_success 'object index can be disabled' '
(
cd repo &&
test_commit initial &&
- for i in $(test_seq 5)
- do
- printf "update refs/heads/branch-%d HEAD\n" "$i" ||
- return 1
- done >input &&
+ test_seq -f "update refs/heads/branch-%d HEAD" 5 >input &&
git update-ref --stdin <input &&
git -c reftable.blockSize=100 -c reftable.indexObjects=false pack-refs &&
@@ -277,6 +267,9 @@ test_expect_success 'object index can be disabled' '
restarts: 1
- length: 80
restarts: 1
+ idx:
+ - length: 55
+ restarts: 2
EOF
test-tool dump-reftable -b .git/reftable/*.ref >actual &&
test_cmp expect actual
diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh
index 4a88bb9ef0..2e8d9384e1 100755
--- a/t/t1001-read-tree-m-2way.sh
+++ b/t/t1001-read-tree-m-2way.sh
@@ -362,7 +362,7 @@ test_expect_success 'a/b (untracked) vs a case setup.' '
test_expect_success 'a/b (untracked) vs a, plus c/d case test.' '
read_tree_u_must_fail -u -m "$treeH" "$treeM" &&
git ls-files --stage &&
- test -f a/b
+ test_path_is_file a/b
'
test_expect_success 'read-tree supports the super-prefix' '
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index ff9bf213aa..1f61b666a7 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -3,6 +3,7 @@
test_description='git cat-file'
. ./test-lib.sh
+. "$TEST_DIRECTORY/lib-loose.sh"
test_cmdmode_usage () {
test_expect_code 129 "$@" 2>err &&
@@ -112,65 +113,55 @@ strlen () {
run_tests () {
type=$1
- oid=$2
- size=$3
- content=$4
- pretty_content=$5
+ object_name="$2"
+ mode=$3
+ size=$4
+ content=$5
+ pretty_content=$6
+ oid=${7:-"$object_name"}
batch_output="$oid $type $size
$content"
test_expect_success "$type exists" '
- git cat-file -e $oid
+ git cat-file -e "$object_name"
'
test_expect_success "Type of $type is correct" '
echo $type >expect &&
- git cat-file -t $oid >actual &&
+ git cat-file -t "$object_name" >actual &&
test_cmp expect actual
'
test_expect_success "Size of $type is correct" '
echo $size >expect &&
- git cat-file -s $oid >actual &&
- test_cmp expect actual
- '
-
- test_expect_success "Type of $type is correct using --allow-unknown-type" '
- echo $type >expect &&
- git cat-file -t --allow-unknown-type $oid >actual &&
- test_cmp expect actual
- '
-
- test_expect_success "Size of $type is correct using --allow-unknown-type" '
- echo $size >expect &&
- git cat-file -s --allow-unknown-type $oid >actual &&
+ git cat-file -s "$object_name" >actual &&
test_cmp expect actual
'
test -z "$content" ||
test_expect_success "Content of $type is correct" '
echo_without_newline "$content" >expect &&
- git cat-file $type $oid >actual &&
+ git cat-file $type "$object_name" >actual &&
test_cmp expect actual
'
test_expect_success "Pretty content of $type is correct" '
echo_without_newline "$pretty_content" >expect &&
- git cat-file -p $oid >actual &&
+ git cat-file -p "$object_name" >actual &&
test_cmp expect actual
'
test -z "$content" ||
test_expect_success "--batch output of $type is correct" '
echo "$batch_output" >expect &&
- echo $oid | git cat-file --batch >actual &&
+ echo "$object_name" | git cat-file --batch >actual &&
test_cmp expect actual
'
test_expect_success "--batch-check output of $type is correct" '
echo "$oid $type $size" >expect &&
- echo_without_newline $oid | git cat-file --batch-check >actual &&
+ echo_without_newline "$object_name" | git cat-file --batch-check >actual &&
test_cmp expect actual
'
@@ -179,13 +170,13 @@ $content"
test -z "$content" ||
test_expect_success "--batch-command $opt output of $type content is correct" '
echo "$batch_output" >expect &&
- test_write_lines "contents $oid" | git cat-file --batch-command $opt >actual &&
+ test_write_lines "contents $object_name" | git cat-file --batch-command $opt >actual &&
test_cmp expect actual
'
test_expect_success "--batch-command $opt output of $type info is correct" '
echo "$oid $type $size" >expect &&
- test_write_lines "info $oid" |
+ test_write_lines "info $object_name" |
git cat-file --batch-command $opt >actual &&
test_cmp expect actual
'
@@ -193,30 +184,45 @@ $content"
test_expect_success "custom --batch-check format" '
echo "$type $oid" >expect &&
- echo $oid | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
+ echo "$object_name" | git cat-file --batch-check="%(objecttype) %(objectname)" >actual &&
test_cmp expect actual
'
test_expect_success "custom --batch-command format" '
echo "$type $oid" >expect &&
- echo "info $oid" | git cat-file --batch-command="%(objecttype) %(objectname)" >actual &&
+ echo "info $object_name" | git cat-file --batch-command="%(objecttype) %(objectname)" >actual &&
test_cmp expect actual
'
- test_expect_success '--batch-check with %(rest)' '
+ # FIXME: %(rest) is incompatible with object names that include whitespace,
+ # e.g. HEAD:path/to/a/file with spaces. Use the resolved OID as input to
+ # test this instead of the raw object name.
+ if echo "$object_name" | grep -q " "; then
+ test_rest=test_expect_failure
+ else
+ test_rest=test_expect_success
+ fi
+
+ $test_rest '--batch-check with %(rest)' '
echo "$type this is some extra content" >expect &&
- echo "$oid this is some extra content" |
+ echo "$object_name this is some extra content" |
git cat-file --batch-check="%(objecttype) %(rest)" >actual &&
test_cmp expect actual
'
+ test_expect_success '--batch-check with %(objectmode)' '
+ echo "$mode $oid" >expect &&
+ echo $object_name | git cat-file --batch-check="%(objectmode) %(objectname)" >actual &&
+ test_cmp expect actual
+ '
+
test -z "$content" ||
test_expect_success "--batch without type ($type)" '
{
echo "$size" &&
echo "$content"
} >expect &&
- echo $oid | git cat-file --batch="%(objectsize)" >actual &&
+ echo "$object_name" | git cat-file --batch="%(objectsize)" >actual &&
test_cmp expect actual
'
@@ -226,7 +232,7 @@ $content"
echo "$type" &&
echo "$content"
} >expect &&
- echo $oid | git cat-file --batch="%(objecttype)" >actual &&
+ echo "$object_name" | git cat-file --batch="%(objecttype)" >actual &&
test_cmp expect actual
'
}
@@ -240,13 +246,15 @@ test_expect_success "setup" '
git config extensions.objectformat $test_hash_algo &&
git config extensions.compatobjectformat $test_compat_hash_algo &&
echo_without_newline "$hello_content" > hello &&
- git update-index --add hello
+ git update-index --add hello &&
+ echo_without_newline "$hello_content" > "path with spaces" &&
+ git update-index --add --chmod=+x "path with spaces" &&
+ git commit -m "add hello file"
'
run_blob_tests () {
oid=$1
-
- run_tests 'blob' $oid $hello_size "$hello_content" "$hello_content"
+ run_tests 'blob' $oid "" $hello_size "$hello_content" "$hello_content"
test_expect_success '--batch-command --buffer with flush for blob info' '
echo "$oid blob $hello_size" >expect &&
@@ -279,13 +287,17 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
tree_oid=$(git write-tree)
tree_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $tree_oid)
-tree_size=$(($(test_oid rawsz) + 13))
-tree_compat_size=$(($(test_oid --hash=compat rawsz) + 13))
-tree_pretty_content="100644 blob $hello_oid hello${LF}"
-tree_compat_pretty_content="100644 blob $hello_compat_oid hello${LF}"
-
-run_tests 'tree' $tree_oid $tree_size "" "$tree_pretty_content"
-run_tests 'tree' $tree_compat_oid $tree_compat_size "" "$tree_compat_pretty_content"
+tree_size=$((2 * $(test_oid rawsz) + 13 + 24))
+tree_compat_size=$((2 * $(test_oid --hash=compat rawsz) + 13 + 24))
+tree_pretty_content="100644 blob $hello_oid hello${LF}100755 blob $hello_oid path with spaces${LF}"
+tree_compat_pretty_content="100644 blob $hello_compat_oid hello${LF}100755 blob $hello_compat_oid path with spaces${LF}"
+
+run_tests 'tree' $tree_oid "" $tree_size "" "$tree_pretty_content"
+run_tests 'tree' $tree_compat_oid "" $tree_compat_size "" "$tree_compat_pretty_content"
+run_tests 'blob' "$tree_oid:hello" "100644" $hello_size "" "$hello_content" $hello_oid
+run_tests 'blob' "$tree_compat_oid:hello" "100644" $hello_size "" "$hello_content" $hello_compat_oid
+run_tests 'blob' "$tree_oid:path with spaces" "100755" $hello_size "" "$hello_content" $hello_oid
+run_tests 'blob' "$tree_compat_oid:path with spaces" "100755" $hello_size "" "$hello_content" $hello_compat_oid
commit_message="Initial commit"
commit_oid=$(echo_without_newline "$commit_message" | git commit-tree $tree_oid)
@@ -304,8 +316,8 @@ committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
$commit_message"
-run_tests 'commit' $commit_oid $commit_size "$commit_content" "$commit_content"
-run_tests 'commit' $commit_compat_oid $commit_compat_size "$commit_compat_content" "$commit_compat_content"
+run_tests 'commit' $commit_oid "" $commit_size "$commit_content" "$commit_content"
+run_tests 'commit' $commit_compat_oid "" $commit_compat_size "$commit_compat_content" "$commit_compat_content"
tag_header_without_oid="type blob
tag hellotag
@@ -328,8 +340,8 @@ tag_size=$(strlen "$tag_content")
tag_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $tag_oid)
tag_compat_size=$(strlen "$tag_compat_content")
-run_tests 'tag' $tag_oid $tag_size "$tag_content" "$tag_content"
-run_tests 'tag' $tag_compat_oid $tag_compat_size "$tag_compat_content" "$tag_compat_content"
+run_tests 'tag' $tag_oid "" $tag_size "$tag_content" "$tag_content"
+run_tests 'tag' $tag_compat_oid "" $tag_compat_size "$tag_compat_content" "$tag_compat_content"
test_expect_success "Reach a blob from a tag pointing to it" '
echo_without_newline "$hello_content" >expect &&
@@ -602,6 +614,34 @@ test_expect_success FUNNYNAMES '--batch-check, -Z with newline in input' '
test_cmp expect actual
'
+test_expect_success 'setup with curly braches in input' '
+ git branch "foo{bar" HEAD &&
+ git branch "foo@" HEAD
+'
+
+test_expect_success 'object reference with curly brace' '
+ git cat-file -p "foo{bar:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'object reference with at-sign' '
+ git cat-file -p "foo@@{0}:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'setup with commit with colon' '
+ git commit-tree -m "testing: just a bunch of junk" HEAD^{tree} >out &&
+ git branch other $(cat out)
+'
+
+test_expect_success 'object reference via commit text search' '
+ git cat-file -p "other^{/testing:}:hello" >actual &&
+ git cat-file -p HEAD:hello >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'setup blobs which are likely to delta' '
test-tool genrandom foo 10240 >foo &&
{ cat foo && echo plus; } >foo-plus &&
@@ -640,103 +680,75 @@ test_expect_success 'setup bogus data' '
bogus_short_type="bogus" &&
bogus_short_content="bogus" &&
bogus_short_size=$(strlen "$bogus_short_content") &&
- bogus_short_oid=$(echo_without_newline "$bogus_short_content" | git hash-object -t $bogus_short_type --literally -w --stdin) &&
+ bogus_short_oid=$(echo_without_newline "$bogus_short_content" | loose_obj .git/objects $bogus_short_type) &&
bogus_long_type="abcdefghijklmnopqrstuvwxyz1234679" &&
bogus_long_content="bogus" &&
bogus_long_size=$(strlen "$bogus_long_content") &&
- bogus_long_oid=$(echo_without_newline "$bogus_long_content" | git hash-object -t $bogus_long_type --literally -w --stdin)
+ bogus_long_oid=$(echo_without_newline "$bogus_long_content" | loose_obj .git/objects $bogus_long_type)
'
-for arg1 in '' --allow-unknown-type
+for arg1 in -s -t -p
do
- for arg2 in -s -t -p
- do
- if test "$arg1" = "--allow-unknown-type" && test "$arg2" = "-p"
- then
- continue
- fi
+ test_expect_success "cat-file $arg1 error on bogus short OID" '
+ cat >expect <<-\EOF &&
+ fatal: invalid object type
+ EOF
+ test_must_fail git cat-file $arg1 $bogus_short_oid >out 2>actual &&
+ test_must_be_empty out &&
+ test_cmp expect actual
+ '
- test_expect_success "cat-file $arg1 $arg2 error on bogus short OID" '
- cat >expect <<-\EOF &&
- fatal: invalid object type
+ test_expect_success "cat-file $arg1 error on bogus full OID" '
+ if test "$arg1" = "-p"
+ then
+ cat >expect <<-EOF
+ error: header for $bogus_long_oid too long, exceeds 32 bytes
+ fatal: Not a valid object name $bogus_long_oid
EOF
+ else
+ cat >expect <<-EOF
+ error: header for $bogus_long_oid too long, exceeds 32 bytes
+ fatal: git cat-file: could not get object info
+ EOF
+ fi &&
- if test "$arg1" = "--allow-unknown-type"
- then
- git cat-file $arg1 $arg2 $bogus_short_oid
- else
- test_must_fail git cat-file $arg1 $arg2 $bogus_short_oid >out 2>actual &&
- test_must_be_empty out &&
- test_cmp expect actual
- fi
- '
+ test_must_fail git cat-file $arg1 $bogus_long_oid >out 2>actual &&
+ test_must_be_empty out &&
+ test_cmp expect actual
+ '
- test_expect_success "cat-file $arg1 $arg2 error on bogus full OID" '
- if test "$arg2" = "-p"
- then
- cat >expect <<-EOF
- error: header for $bogus_long_oid too long, exceeds 32 bytes
- fatal: Not a valid object name $bogus_long_oid
- EOF
- else
- cat >expect <<-EOF
- error: header for $bogus_long_oid too long, exceeds 32 bytes
- fatal: git cat-file: could not get object info
- EOF
- fi &&
-
- if test "$arg1" = "--allow-unknown-type"
- then
- git cat-file $arg1 $arg2 $bogus_short_oid
- else
- test_must_fail git cat-file $arg1 $arg2 $bogus_long_oid >out 2>actual &&
- test_must_be_empty out &&
- test_cmp expect actual
- fi
- '
+ test_expect_success "cat-file $arg1 error on missing short OID" '
+ cat >expect.err <<-EOF &&
+ fatal: Not a valid object name $(test_oid deadbeef_short)
+ EOF
+ test_must_fail git cat-file $arg1 $(test_oid deadbeef_short) >out 2>err.actual &&
+ test_must_be_empty out &&
+ test_cmp expect.err err.actual
+ '
- test_expect_success "cat-file $arg1 $arg2 error on missing short OID" '
- cat >expect.err <<-EOF &&
- fatal: Not a valid object name $(test_oid deadbeef_short)
+ test_expect_success "cat-file $arg1 error on missing full OID" '
+ if test "$arg1" = "-p"
+ then
+ cat >expect.err <<-EOF
+ fatal: Not a valid object name $(test_oid deadbeef)
EOF
- test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef_short) >out 2>err.actual &&
- test_must_be_empty out &&
- test_cmp expect.err err.actual
- '
-
- test_expect_success "cat-file $arg1 $arg2 error on missing full OID" '
- if test "$arg2" = "-p"
- then
- cat >expect.err <<-EOF
- fatal: Not a valid object name $(test_oid deadbeef)
- EOF
- else
- cat >expect.err <<-\EOF
- fatal: git cat-file: could not get object info
- EOF
- fi &&
- test_must_fail git cat-file $arg1 $arg2 $(test_oid deadbeef) >out 2>err.actual &&
- test_must_be_empty out &&
- test_cmp expect.err err.actual
- '
- done
+ else
+ cat >expect.err <<-\EOF
+ fatal: git cat-file: could not get object info
+ EOF
+ fi &&
+ test_must_fail git cat-file $arg1 $(test_oid deadbeef) >out 2>err.actual &&
+ test_must_be_empty out &&
+ test_cmp expect.err err.actual
+ '
done
-test_expect_success '-e is OK with a broken object without --allow-unknown-type' '
+test_expect_success '-e is OK with a broken object' '
git cat-file -e $bogus_short_oid
'
-test_expect_success '-e can not be combined with --allow-unknown-type' '
- test_expect_code 128 git cat-file -e --allow-unknown-type $bogus_short_oid
-'
-
-test_expect_success '-p cannot print a broken object even with --allow-unknown-type' '
- test_must_fail git cat-file -p $bogus_short_oid &&
- test_expect_code 128 git cat-file -p --allow-unknown-type $bogus_short_oid
-'
-
test_expect_success '<type> <hash> does not work with objects of broken types' '
cat >err.expect <<-\EOF &&
fatal: invalid object type "bogus"
@@ -759,60 +771,8 @@ test_expect_success 'broken types combined with --batch and --batch-check' '
test_cmp err.expect err.actual
'
-test_expect_success 'the --batch and --batch-check options do not combine with --allow-unknown-type' '
- test_expect_code 128 git cat-file --batch --allow-unknown-type <bogus-oid &&
- test_expect_code 128 git cat-file --batch-check --allow-unknown-type <bogus-oid
-'
-
-test_expect_success 'the --allow-unknown-type option does not consider replacement refs' '
- cat >expect <<-EOF &&
- $bogus_short_type
- EOF
- git cat-file -t --allow-unknown-type $bogus_short_oid >actual &&
- test_cmp expect actual &&
-
- # Create it manually, as "git replace" will die on bogus
- # types.
- head=$(git rev-parse --verify HEAD) &&
- test_when_finished "test-tool ref-store main delete-refs 0 msg refs/replace/$bogus_short_oid" &&
- test-tool ref-store main update-ref msg "refs/replace/$bogus_short_oid" $head $ZERO_OID REF_SKIP_OID_VERIFICATION &&
-
- cat >expect <<-EOF &&
- commit
- EOF
- git cat-file -t --allow-unknown-type $bogus_short_oid >actual &&
- test_cmp expect actual
-'
-
-test_expect_success "Type of broken object is correct" '
- echo $bogus_short_type >expect &&
- git cat-file -t --allow-unknown-type $bogus_short_oid >actual &&
- test_cmp expect actual
-'
-
-test_expect_success "Size of broken object is correct" '
- echo $bogus_short_size >expect &&
- git cat-file -s --allow-unknown-type $bogus_short_oid >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'clean up broken object' '
- rm .git/objects/$(test_oid_to_path $bogus_short_oid)
-'
-
-test_expect_success "Type of broken object is correct when type is large" '
- echo $bogus_long_type >expect &&
- git cat-file -t --allow-unknown-type $bogus_long_oid >actual &&
- test_cmp expect actual
-'
-
-test_expect_success "Size of large broken object is correct when type is large" '
- echo $bogus_long_size >expect &&
- git cat-file -s --allow-unknown-type $bogus_long_oid >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'clean up broken object' '
+test_expect_success 'clean up broken objects' '
+ rm .git/objects/$(test_oid_to_path $bogus_short_oid) &&
rm .git/objects/$(test_oid_to_path $bogus_long_oid)
'
@@ -874,6 +834,40 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' '
)
'
+test_expect_success 'object reading handles zlib dictionary' - <<\EOT
+ echo 'content that will be recompressed' >file &&
+ blob=$(git hash-object -w file) &&
+ objpath=.git/objects/$(test_oid_to_path "$blob") &&
+
+ # Recompress a loose object using a precomputed zlib dictionary.
+ # This was originally done with:
+ #
+ # perl -MCompress::Raw::Zlib -e '
+ # binmode STDIN;
+ # binmode STDOUT;
+ # my $data = do { local $/; <STDIN> };
+ # my $in = new Compress::Raw::Zlib::Inflate;
+ # my $de = new Compress::Raw::Zlib::Deflate(
+ # -Dictionary => "anything"
+ # );
+ # $in->inflate($data, $raw);
+ # $de->deflate($raw, $out);
+ # print $out;
+ # ' <obj.bak >$objpath
+ #
+ # but we do not want to require the perl module for all test runs (nor
+ # carry a custom t/helper program that uses zlib features we don't
+ # otherwise care about).
+ mv "$objpath" obj.bak &&
+ test_when_finished 'mv obj.bak "$objpath"' &&
+ printf '\170\273\017\112\003\143' >$objpath &&
+
+ test_must_fail git cat-file blob $blob 2>err &&
+ test_grep ! 'too long' err &&
+ test_grep 'error: unable to unpack' err &&
+ test_grep 'error: inflate: needs dictionary' err
+EOT
+
# Tests for git cat-file --follow-symlinks
test_expect_success 'prep for symlink tests' '
echo_without_newline "$hello_content" >morx &&
@@ -1226,6 +1220,31 @@ test_expect_success 'cat-file --batch-check respects replace objects' '
test_cmp expect actual
'
+test_expect_success 'batch-check with a submodule' '
+ # FIXME: this call to mktree is incompatible with compatObjectFormat
+ # because the submodule OID cannot be mapped to the compat hash algo.
+ test_unconfig extensions.compatobjectformat &&
+ printf "160000 commit $(test_oid deadbeef)\tsub\n" >tree-with-sub &&
+ tree=$(git mktree <tree-with-sub) &&
+ test_config extensions.compatobjectformat $test_compat_hash_algo &&
+
+ git cat-file --batch-check >actual <<-EOF &&
+ $tree:sub
+ EOF
+ printf "$(test_oid deadbeef) submodule\n" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'batch-check with a submodule, object exists' '
+ printf "160000 commit $commit_oid\tsub\n" >tree-with-sub &&
+ tree=$(git mktree <tree-with-sub) &&
+ git cat-file --batch-check >actual <<-EOF &&
+ $tree:sub
+ EOF
+ printf "$commit_oid commit $commit_size\n" >expect &&
+ test_cmp expect actual
+'
+
# Pull the entry for object with oid "$1" out of the output of
# "cat-file --batch", including its object content (which requires
# parsing and reading a set amount of bytes, hence perl).
@@ -1241,7 +1260,7 @@ extract_batch_output () {
' "$@"
}
-test_expect_success 'cat-file --batch-all-objects --batch ignores replace' '
+test_expect_success PERL_TEST_HELPERS 'cat-file --batch-all-objects --batch ignores replace' '
git cat-file --batch-all-objects --batch >actual.raw &&
extract_batch_output $orig <actual.raw >actual &&
{
@@ -1294,7 +1313,7 @@ test_expect_success 'batch-command flush without --buffer' '
grep "^fatal:.*flush is only for --buffer mode.*" err
'
-script='
+perl_script='
use warnings;
use strict;
use IPC::Open2;
@@ -1316,12 +1335,115 @@ $? == 0 or die "\$?=$?";
expect="$hello_oid blob $hello_size"
-test_expect_success PERL '--batch-check is unbuffered by default' '
- perl -e "$script" -- --batch-check $hello_oid "$expect"
+test_lazy_prereq PERL_IPC_OPEN2 '
+ perl -MIPC::Open2 -e "exit 0"
+'
+
+test_expect_success PERL_IPC_OPEN2 '--batch-check is unbuffered by default' '
+ perl -e "$perl_script" -- --batch-check $hello_oid "$expect"
+'
+
+test_expect_success PERL_IPC_OPEN2 '--batch-command info is unbuffered by default' '
+ perl -e "$perl_script" -- --batch-command $hello_oid "$expect" "info "
+'
+
+test_expect_success 'setup for objects filter' '
+ git init repo &&
+ (
+ # Seed the repository with four different sets of objects:
+ #
+ # - The first set is fully packed and has a bitmap.
+ # - The second set is packed, but has no bitmap.
+ # - The third set is loose.
+ # - The fourth set is loose and contains big objects.
+ #
+ # This ensures that we cover all these types as expected.
+ cd repo &&
+ test_commit first &&
+ git repack -Adb &&
+ test_commit second &&
+ git repack -d &&
+ test_commit third &&
+
+ for n in 1000 10000
+ do
+ printf "%"$n"s" X >large.$n || return 1
+ done &&
+ git add large.* &&
+ git commit -m fourth
+ )
+'
+
+test_expect_success 'objects filter with unknown option' '
+ cat >expect <<-EOF &&
+ fatal: invalid filter-spec ${SQ}unknown${SQ}
+ EOF
+ test_must_fail git -C repo cat-file --filter=unknown 2>err &&
+ test_cmp expect err
'
-test_expect_success PERL '--batch-command info is unbuffered by default' '
- perl -e "$script" -- --batch-command $hello_oid "$expect" "info "
+for option in sparse:oid=1234 tree:1 sparse:path=x
+do
+ test_expect_success "objects filter with unsupported option $option" '
+ case "$option" in
+ tree:1)
+ echo "usage: objects filter not supported: ${SQ}tree${SQ}" >expect
+ ;;
+ sparse:path=x)
+ echo "fatal: sparse:path filters support has been dropped" >expect
+ ;;
+ *)
+ option_name=$(echo "$option" | cut -d= -f1) &&
+ printf "usage: objects filter not supported: ${SQ}%s${SQ}\n" "$option_name" >expect
+ ;;
+ esac &&
+ test_must_fail git -C repo cat-file --filter=$option 2>err &&
+ test_cmp expect err
+ '
+done
+
+test_expect_success 'objects filter: disabled' '
+ git -C repo cat-file --batch-check="%(objectname)" --batch-all-objects --no-filter >actual &&
+ sort actual >actual.sorted &&
+ git -C repo rev-list --objects --no-object-names --all >expect &&
+ sort expect >expect.sorted &&
+ test_cmp expect.sorted actual.sorted
'
+test_objects_filter () {
+ filter="$1"
+
+ test_expect_success "objects filter: $filter" '
+ git -C repo cat-file --batch-check="%(objectname)" --batch-all-objects --filter="$filter" >actual &&
+ sort actual >actual.sorted &&
+ git -C repo rev-list --objects --no-object-names --all --filter="$filter" --filter-provided-objects >expect &&
+ sort expect >expect.sorted &&
+ test_cmp expect.sorted actual.sorted
+ '
+
+ test_expect_success "objects filter prints excluded objects: $filter" '
+ # Find all objects that would be excluded by the current filter.
+ git -C repo rev-list --objects --no-object-names --all >all &&
+ git -C repo rev-list --objects --no-object-names --all --filter="$filter" --filter-provided-objects >filtered &&
+ sort all >all.sorted &&
+ sort filtered >filtered.sorted &&
+ comm -23 all.sorted filtered.sorted >expected.excluded &&
+ test_line_count -gt 0 expected.excluded &&
+
+ git -C repo cat-file --batch-check="%(objectname)" --filter="$filter" <expected.excluded >actual &&
+ awk "/excluded/{ print \$1 }" actual | sort >actual.excluded &&
+ test_cmp expected.excluded actual.excluded
+ '
+}
+
+test_objects_filter "blob:none"
+test_objects_filter "blob:limit=1"
+test_objects_filter "blob:limit=500"
+test_objects_filter "blob:limit=1000"
+test_objects_filter "blob:limit=1k"
+test_objects_filter "object:type=blob"
+test_objects_filter "object:type=commit"
+test_objects_filter "object:type=tag"
+test_objects_filter "object:type=tree"
+
test_done
diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh
index a0481139de..de076293b6 100755
--- a/t/t1007-hash-object.sh
+++ b/t/t1007-hash-object.sh
@@ -30,7 +30,7 @@ setup_repo() {
test_repo=test
push_repo() {
- test_create_repo $test_repo
+ git init --quiet $test_repo
cd $test_repo
setup_repo
@@ -205,7 +205,7 @@ test_expect_success 'too-short tree' '
grep "too-short tree object" err
'
-test_expect_success 'malformed mode in tree' '
+test_expect_success PERL_TEST_HELPERS 'malformed mode in tree' '
hex_oid=$(echo foo | git hash-object --stdin -w) &&
bin_oid=$(echo $hex_oid | hex2oct) &&
printf "9100644 \0$bin_oid" >tree-with-malformed-mode &&
@@ -213,7 +213,7 @@ test_expect_success 'malformed mode in tree' '
grep "malformed mode in tree entry" err
'
-test_expect_success 'empty filename in tree' '
+test_expect_success PERL_TEST_HELPERS 'empty filename in tree' '
hex_oid=$(echo foo | git hash-object --stdin -w) &&
bin_oid=$(echo $hex_oid | hex2oct) &&
printf "100644 \0$bin_oid" >tree-with-empty-filename &&
@@ -221,7 +221,7 @@ test_expect_success 'empty filename in tree' '
grep "empty filename in tree entry" err
'
-test_expect_success 'duplicate filename in tree' '
+test_expect_success PERL_TEST_HELPERS 'duplicate filename in tree' '
hex_oid=$(echo foo | git hash-object --stdin -w) &&
bin_oid=$(echo $hex_oid | hex2oct) &&
{
@@ -248,20 +248,13 @@ test_expect_success 'hash-object complains about truncated type name' '
test_must_fail git hash-object -t bl --stdin </dev/null
'
-test_expect_success '--literally' '
- t=1234567890 &&
- echo example | git hash-object -t $t --literally --stdin
+test_expect_success '--literally complains about non-standard types' '
+ test_must_fail git hash-object -t bogus --literally --stdin
'
-test_expect_success '--literally with extra-long type' '
- t=12345678901234567890123456789012345678901234567890 &&
- t="$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t" &&
- echo example | git hash-object -t $t --literally --stdin
-'
-
-test_expect_success '--stdin outside of repository (uses SHA-1)' '
+test_expect_success '--stdin outside of repository (uses default hash)' '
nongit git hash-object --stdin <hello >actual &&
- echo "$(test_oid --hash=sha1 hello)" >expect &&
+ echo "$(test_oid --hash=builtin hello)" >expect &&
test_cmp expect actual
'
diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh
index c291a2b33d..e9973f7494 100755
--- a/t/t1010-mktree.sh
+++ b/t/t1010-mktree.sh
@@ -42,13 +42,13 @@ test_expect_success 'ls-tree piped to mktree (2)' '
'
test_expect_success 'ls-tree output in wrong order given to mktree (1)' '
- perl -e "print reverse <>" <top |
+ sort -r <top |
git mktree >actual &&
test_cmp tree actual
'
test_expect_success 'ls-tree output in wrong order given to mktree (2)' '
- perl -e "print reverse <>" <top.withsub |
+ sort -r <top.withsub |
git mktree >actual &&
test_cmp tree.withsub actual
'
diff --git a/t/t1021-rerere-in-workdir.sh b/t/t1021-rerere-in-workdir.sh
deleted file mode 100755
index 0b892894eb..0000000000
--- a/t/t1021-rerere-in-workdir.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/bin/sh
-
-test_description='rerere run in a workdir'
-GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
-export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
-
-. ./test-lib.sh
-
-test_expect_success SYMLINKS setup '
- git config rerere.enabled true &&
- >world &&
- git add world &&
- test_tick &&
- git commit -m initial &&
-
- echo hello >world &&
- test_tick &&
- git commit -a -m hello &&
-
- git checkout -b side HEAD^ &&
- echo goodbye >world &&
- test_tick &&
- git commit -a -m goodbye &&
-
- git checkout main
-'
-
-test_expect_success SYMLINKS 'rerere in workdir' '
- rm -rf .git/rr-cache &&
- "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" . work &&
- (
- cd work &&
- test_must_fail git merge side &&
- git rerere status >actual &&
- echo world >expect &&
- test_cmp expect actual
- )
-'
-
-# This fails because we don't resolve relative symlink in mkdir_in_gitdir()
-# For the purpose of helping contrib/workdir/git-new-workdir users, we do not
-# have to support relative symlinks, but it might be nicer to make this work
-# with a relative symbolic link someday.
-test_expect_failure SYMLINKS 'rerere in workdir (relative)' '
- rm -rf .git/rr-cache &&
- "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" . krow &&
- (
- cd krow &&
- rm -f .git/rr-cache &&
- ln -s ../.git/rr-cache .git/rr-cache &&
- test_must_fail git merge side &&
- git rerere status >actual &&
- echo world >expect &&
- test_cmp expect actual
- )
-'
-
-test_done
diff --git a/t/t1050-large.sh b/t/t1050-large.sh
index c71932b024..5be273611a 100755
--- a/t/t1050-large.sh
+++ b/t/t1050-large.sh
@@ -6,7 +6,8 @@ test_description='adding and checking out large blobs'
. ./test-lib.sh
test_expect_success 'core.bigFileThreshold must be non-negative' '
- test_must_fail git -c core.bigFileThreshold=-1 rev-parse >out 2>err &&
+ : >input &&
+ test_must_fail git -c core.bigFileThreshold=-1 hash-object input >out 2>err &&
grep "bad numeric config value" err &&
test_must_be_empty out
'
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index a4c7c41fc0..b0f691c151 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -384,6 +384,44 @@ test_expect_success 'add, commit, checkout' '
test_all_match git checkout -
'
+test_expect_success 'git add, checkout, and reset with -p' '
+ init_repos &&
+
+ write_script edit-contents <<-\EOF &&
+ echo text >>$1
+ EOF
+
+ # Does not expand when edits are within sparse checkout.
+ run_on_all ../edit-contents deep/a &&
+ run_on_all ../edit-contents deep/deeper1/a &&
+
+ test_write_lines y n >in &&
+ run_on_all git add -p <in &&
+ test_all_match git status --porcelain=v2 &&
+ test_all_match git reset -p <in &&
+
+ test_write_lines u 1 "" q >in &&
+ run_on_all git add -i <in &&
+ test_all_match git status --porcelain=v2 &&
+ test_all_match git reset --hard &&
+
+ run_on_sparse mkdir -p folder1 &&
+ run_on_all ../edit-contents folder1/a &&
+ test_write_lines y n y >in &&
+ run_on_all git add -p <in &&
+ test_sparse_match git status --porcelain=v2 &&
+ test_sparse_match git reset &&
+ test_write_lines u 2 3 "" q >in &&
+ run_on_all git add -i <in &&
+ test_sparse_match git status --porcelain=v2 &&
+
+ run_on_all git add --sparse folder1 &&
+ run_on_all git commit -m "take changes" &&
+ test_write_lines y n y >in &&
+ test_sparse_match git checkout HEAD~1 --patch <in &&
+ test_sparse_match git status --porcelain=v2
+'
+
test_expect_success 'deep changes during checkout' '
init_repos &&
@@ -1340,6 +1378,30 @@ test_expect_success 'submodule handling' '
grep "160000 $(git -C initial-repo rev-parse HEAD) 0 modules/sub" cache
'
+test_expect_success 'git apply functionality' '
+ init_repos &&
+
+ test_all_match git checkout base &&
+
+ git -C full-checkout diff base..merge-right -- deep >patch-in-sparse &&
+ git -C full-checkout diff base..merge-right -- folder2 >patch-outside &&
+
+ # Apply a patch to a file inside the sparse definition
+ test_all_match git apply --index --stat ../patch-in-sparse &&
+ test_all_match git status --porcelain=v2 &&
+
+ # Apply a patch to a file outside the sparse definition
+ test_sparse_match test_must_fail git apply ../patch-outside &&
+ grep "No such file or directory" sparse-checkout-err &&
+
+ # But it works with --index and --cached
+ test_all_match git apply --index --stat ../patch-outside &&
+ test_all_match git status --porcelain=v2 &&
+ test_all_match git reset --hard &&
+ test_all_match git apply --cached --stat ../patch-outside &&
+ test_all_match git status --porcelain=v2
+'
+
# When working with a sparse index, some commands will need to expand the
# index to operate properly. If those commands also write the index back
# to disk, they need to convert the index to sparse before writing.
@@ -1444,6 +1506,8 @@ test_expect_success 'sparse-index is not expanded' '
ensure_not_expanded reset --hard &&
ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
+ ensure_not_expanded ls-files deep/deeper1 &&
+
echo >>sparse-index/README.md &&
ensure_not_expanded add -A &&
echo >>sparse-index/extra.txt &&
@@ -1486,7 +1550,6 @@ test_expect_success 'sparse-index is not expanded' '
ensure_not_expanded checkout -f update-deep &&
test_config -C sparse-index pull.twohead ort &&
(
- sane_unset GIT_TEST_MERGE_ALGORITHM &&
for OPERATION in "merge -m merge" cherry-pick rebase
do
ensure_not_expanded merge -m merge update-folder1 &&
@@ -1506,7 +1569,6 @@ test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
done &&
(
- sane_unset GIT_TEST_MERGE_ALGORITHM &&
git -C sparse-index config pull.twohead ort &&
ensure_not_expanded ! merge -m merged expand-right
)
@@ -1547,6 +1609,17 @@ test_expect_success 'describe tested on all' '
test_all_match git describe --dirty
'
+test_expect_success 'ls-files filtering and expansion' '
+ init_repos &&
+
+ # This filtering will hit a sparse directory midway
+ # through the iteration.
+ test_all_match git ls-files deep &&
+
+ # This pathspec will filter the index to only a sparse
+ # directory.
+ test_all_match git ls-files folder1
+'
test_expect_success 'sparse-index is not expanded: describe' '
init_repos &&
@@ -2347,6 +2420,95 @@ test_expect_success 'sparse-index is not expanded: check-attr' '
ensure_not_expanded check-attr -a --cached -- folder1/a
'
+test_expect_success 'sparse-index is not expanded: git apply' '
+ init_repos &&
+
+ git -C sparse-index checkout base &&
+ git -C full-checkout diff base..merge-right -- deep >patch-in-sparse &&
+ git -C full-checkout diff base..merge-right -- folder2 >patch-outside &&
+
+ # Apply a patch to a file inside the sparse definition
+ ensure_not_expanded apply --index --stat ../patch-in-sparse &&
+
+ # Apply a patch to a file outside the sparse definition
+ # Fails when caring about the worktree.
+ ensure_not_expanded ! apply ../patch-outside &&
+
+ # Expands when using --index.
+ ensure_expanded apply --index ../patch-outside &&
+
+ # Does not when index is partially expanded.
+ git -C sparse-index reset --hard &&
+ ensure_not_expanded apply --cached ../patch-outside &&
+
+ # Try again with a reset and collapsed index.
+ git -C sparse-index reset --hard &&
+ git -C sparse-index sparse-checkout reapply &&
+
+ # Expands when index is collapsed.
+ ensure_expanded apply --cached ../patch-outside
+'
+
+test_expect_success 'sparse-index is not expanded: git add -p' '
+ init_repos &&
+
+ # Does not expand when edits are within sparse checkout.
+ echo "new content" >sparse-index/deep/a &&
+ echo "new content" >sparse-index/deep/deeper1/a &&
+ test_write_lines y n >in &&
+ ensure_not_expanded add -p <in &&
+ git -C sparse-index reset &&
+ ensure_not_expanded add -i <in &&
+
+ # -p does expand when edits are outside sparse checkout.
+ mkdir -p sparse-index/folder1 &&
+ echo "new content" >sparse-index/folder1/a &&
+ test_write_lines y n y >in &&
+ ensure_expanded add -p <in &&
+
+ # Fully reset the index.
+ git -C sparse-index reset --hard &&
+ git -C sparse-index sparse-checkout reapply &&
+
+ # -i does expand when edits are outside sparse checkout.
+ mkdir -p sparse-index/folder1 &&
+ echo "new content" >sparse-index/folder1/a &&
+ test_write_lines u 2 3 "" q >in &&
+ ensure_expanded add -i <in
+'
+
+test_expect_success 'sparse-index is not expanded: checkout -p, reset -p' '
+ init_repos &&
+
+ # Does not expand when edits are within sparse checkout.
+ echo "new content" >sparse-index/deep/a &&
+ echo "new content" >sparse-index/deep/deeper1/a &&
+ git -C sparse-index commit -a -m "inside-changes" &&
+
+ test_write_lines y y >in &&
+ ensure_not_expanded checkout HEAD~1 --patch <in &&
+
+ echo "new content" >sparse-index/deep/a &&
+ echo "new content" >sparse-index/deep/deeper1/a &&
+ git -C sparse-index add . &&
+ ensure_not_expanded reset --patch <in &&
+
+ # -p does expand when edits are outside sparse checkout.
+ mkdir -p sparse-index/folder1 &&
+ echo "new content" >sparse-index/folder1/a &&
+ git -C sparse-index add --sparse folder1 &&
+ git -C sparse-index sparse-checkout reapply &&
+ ensure_expanded reset --patch <in &&
+
+ # Fully reset the index.
+ mkdir -p sparse-index/folder1 &&
+ echo "new content" >sparse-index/folder1/a &&
+ git -C sparse-index add --sparse folder1 &&
+ git -C sparse-index commit -m "folder1 change" &&
+ git -C sparse-index sparse-checkout reapply &&
+ ensure_expanded checkout HEAD~1 --patch <in
+'
+
test_expect_success 'advice.sparseIndexExpanded' '
init_repos &&
diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh
index e2316f1dd4..b7415ec9d5 100755
--- a/t/t1400-update-ref.sh
+++ b/t/t1400-update-ref.sh
@@ -1380,10 +1380,7 @@ test_expect_success 'fails with duplicate ref update via symref' '
test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
(
- for i in $(test_seq 33)
- do
- echo "create refs/heads/$i HEAD" || exit 1
- done >large_input &&
+ test_seq -f "create refs/heads/%d HEAD" 33 >large_input &&
run_with_limited_open_files git update-ref --stdin <large_input &&
git rev-parse --verify -q refs/heads/33
)
@@ -1391,10 +1388,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches
test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
(
- for i in $(test_seq 33)
- do
- echo "delete refs/heads/$i HEAD" || exit 1
- done >large_input &&
+ test_seq -f "delete refs/heads/%d HEAD" 33 >large_input &&
run_with_limited_open_files git update-ref --stdin <large_input &&
test_must_fail git rev-parse --verify -q refs/heads/33
)
@@ -2066,6 +2060,333 @@ do
grep "$(git rev-parse $a) $(git rev-parse $a)" actual
'
+ test_expect_success "stdin $type batch-updates" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit commit &&
+ head=$(git rev-parse HEAD) &&
+
+ format_command $type "update refs/heads/ref1" "$head" "$Z" >stdin &&
+ format_command $type "update refs/heads/ref2" "$head" "$Z" >>stdin &&
+ git update-ref $type --stdin --batch-updates <stdin &&
+ echo $head >expect &&
+ git rev-parse refs/heads/ref1 >actual &&
+ test_cmp expect actual &&
+ git rev-parse refs/heads/ref2 >actual &&
+ test_cmp expect actual
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates with invalid new_oid" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ git update-ref refs/heads/ref1 $head &&
+ git update-ref refs/heads/ref2 $head &&
+
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
+ format_command $type "update refs/heads/ref2" "$(test_oid 001)" "$head" >>stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/ref1 >actual &&
+ test_cmp expect actual &&
+ echo $head >expect &&
+ git rev-parse refs/heads/ref2 >actual &&
+ test_cmp expect actual &&
+ test_grep -q "invalid new value provided" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates with non-commit new_oid" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ head_tree=$(git rev-parse HEAD^{tree}) &&
+ git update-ref refs/heads/ref1 $head &&
+ git update-ref refs/heads/ref2 $head &&
+
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
+ format_command $type "update refs/heads/ref2" "$head_tree" "$head" >>stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/ref1 >actual &&
+ test_cmp expect actual &&
+ echo $head >expect &&
+ git rev-parse refs/heads/ref2 >actual &&
+ test_cmp expect actual &&
+ test_grep -q "invalid new value provided" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates with non-existent ref" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ git update-ref refs/heads/ref1 $head &&
+
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
+ format_command $type "update refs/heads/ref2" "$old_head" "$head" >>stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/ref1 >actual &&
+ test_cmp expect actual &&
+ test_must_fail git rev-parse refs/heads/ref2 &&
+ test_grep -q "reference does not exist" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates with dangling symref" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ git update-ref refs/heads/ref1 $head &&
+ git symbolic-ref refs/heads/ref2 refs/heads/nonexistent &&
+
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
+ format_command $type "update refs/heads/ref2" "$old_head" "$head" >>stdin &&
+ git update-ref $type --no-deref --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/ref1 >actual &&
+ test_cmp expect actual &&
+ echo $head >expect &&
+ test_must_fail git rev-parse refs/heads/ref2 &&
+ test_grep -q "reference does not exist" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates with regular ref as symref" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ git update-ref refs/heads/ref1 $head &&
+ git update-ref refs/heads/ref2 $head &&
+
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
+ format_command $type "symref-update refs/heads/ref2" "$old_head" "ref" "refs/heads/nonexistent" >>stdin &&
+ git update-ref $type --no-deref --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/ref1 >actual &&
+ test_cmp expect actual &&
+ echo $head >expect &&
+ echo $head >expect &&
+ git rev-parse refs/heads/ref2 >actual &&
+ test_cmp expect actual &&
+ test_grep -q "expected symref but found regular ref" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates with invalid old_oid" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ git update-ref refs/heads/ref1 $head &&
+ git update-ref refs/heads/ref2 $head &&
+
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
+ format_command $type "update refs/heads/ref2" "$old_head" "$Z" >>stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/ref1 >actual &&
+ test_cmp expect actual &&
+ echo $head >expect &&
+ git rev-parse refs/heads/ref2 >actual &&
+ test_cmp expect actual &&
+ test_grep -q "reference already exists" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates with incorrect old oid" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ git update-ref refs/heads/ref1 $head &&
+ git update-ref refs/heads/ref2 $head &&
+
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
+ format_command $type "update refs/heads/ref2" "$head" "$old_head" >>stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/ref1 >actual &&
+ test_cmp expect actual &&
+ echo $head >expect &&
+ git rev-parse refs/heads/ref2 >actual &&
+ test_cmp expect actual &&
+ test_grep -q "incorrect old value provided" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates refname conflict" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ git update-ref refs/heads/ref/foo $head &&
+
+ format_command $type "update refs/heads/ref/foo" "$old_head" "$head" >stdin &&
+ format_command $type "update refs/heads/ref" "$old_head" "" >>stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/ref/foo >actual &&
+ test_cmp expect actual &&
+ test_grep -q "refname conflict" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates refname conflict new ref" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit one &&
+ old_head=$(git rev-parse HEAD) &&
+ test_commit two &&
+ head=$(git rev-parse HEAD) &&
+ git update-ref refs/heads/ref/foo $head &&
+
+ format_command $type "update refs/heads/foo" "$old_head" "" >stdin &&
+ format_command $type "update refs/heads/ref" "$old_head" "" >>stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ echo $old_head >expect &&
+ git rev-parse refs/heads/foo >actual &&
+ test_cmp expect actual &&
+ test_grep -q "refname conflict" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates delete incorrect symbolic ref" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit c1 &&
+ head=$(git rev-parse HEAD) &&
+ git symbolic-ref refs/heads/symbolic refs/heads/non-existent &&
+
+ format_command $type "delete refs/heads/symbolic" "$head" >stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ test_grep "reference does not exist" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates delete with incorrect old_oid" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit c1 &&
+ git branch new-branch &&
+ test_commit c2 &&
+ head=$(git rev-parse HEAD) &&
+
+ format_command $type "delete refs/heads/new-branch" "$head" >stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ test_grep "incorrect old value provided" stdout
+ )
+ '
+
+ test_expect_success "stdin $type batch-updates delete non-existent ref" '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ test_commit commit &&
+ head=$(git rev-parse HEAD) &&
+
+ format_command $type "delete refs/heads/non-existent" "$head" >stdin &&
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
+ test_grep "reference does not exist" stdout
+ )
+ '
done
+test_expect_success 'update-ref should also create reflog for HEAD' '
+ test_commit to-rewind &&
+ git rev-parse HEAD >expect &&
+ head=$(git symbolic-ref HEAD) &&
+ git update-ref --create-reflog "$head" HEAD~ &&
+ git rev-parse HEAD@{1} >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success REFFILES 'empty directories are pruned when aborting a transaction' '
+ test_path_is_missing .git/refs/heads/nested &&
+ git update-ref --stdin <<-EOF &&
+ create refs/heads/nested/something HEAD
+ prepare
+ abort
+ EOF
+ test_path_is_missing .git/refs/heads/nested
+'
+
+test_expect_success REFFILES 'empty directories are pruned when not committing' '
+ test_path_is_missing .git/refs/heads/nested &&
+ git update-ref --stdin <<-EOF &&
+ create refs/heads/nested/something HEAD
+ prepare
+ EOF
+ test_path_is_missing .git/refs/heads/nested
+'
+
+test_expect_success 'dangling symref not overwritten by creation' '
+ test_when_finished "git update-ref -d refs/heads/dangling" &&
+ git symbolic-ref refs/heads/dangling refs/heads/does-not-exist &&
+ test_must_fail git update-ref --no-deref --stdin 2>err <<-\EOF &&
+ create refs/heads/dangling HEAD
+ EOF
+ test_grep "cannot lock.*dangling symref already exists" err &&
+ test_must_fail git rev-parse --verify refs/heads/dangling &&
+ test_must_fail git rev-parse --verify refs/heads/does-not-exist
+'
+
+test_expect_success 'dangling symref overwritten without old oid' '
+ test_when_finished "git update-ref -d refs/heads/dangling" &&
+ git symbolic-ref refs/heads/dangling refs/heads/does-not-exist &&
+ git update-ref --no-deref --stdin <<-\EOF &&
+ update refs/heads/dangling HEAD
+ EOF
+ git rev-parse --verify refs/heads/dangling &&
+ test_must_fail git rev-parse --verify refs/heads/does-not-exist
+'
+
test_done
diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 9d698b3cc3..36c903ca19 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -196,7 +196,7 @@ test_expect_success 'show-ref --verify with dangling ref' '
remove_object() {
file=$(sha1_file "$*") &&
- test -e "$file" &&
+ test_path_is_file "$file" &&
rm -f "$file"
} &&
@@ -228,69 +228,4 @@ test_expect_success 'show-ref sub-modes are mutually exclusive' '
grep "cannot be used together" err
'
-test_expect_success '--exists with existing reference' '
- git show-ref --exists refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
-'
-
-test_expect_success '--exists with missing reference' '
- test_expect_code 2 git show-ref --exists refs/heads/does-not-exist
-'
-
-test_expect_success '--exists does not use DWIM' '
- test_expect_code 2 git show-ref --exists $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 2>err &&
- grep "reference does not exist" err
-'
-
-test_expect_success '--exists with HEAD' '
- git show-ref --exists HEAD
-'
-
-test_expect_success '--exists with bad reference name' '
- test_when_finished "git update-ref -d refs/heads/bad...name" &&
- new_oid=$(git rev-parse HEAD) &&
- test-tool ref-store main update-ref msg refs/heads/bad...name $new_oid $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
- git show-ref --exists refs/heads/bad...name
-'
-
-test_expect_success '--exists with arbitrary symref' '
- test_when_finished "git symbolic-ref -d refs/symref" &&
- git symbolic-ref refs/symref refs/heads/$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
- git show-ref --exists refs/symref
-'
-
-test_expect_success '--exists with dangling symref' '
- test_when_finished "git symbolic-ref -d refs/heads/dangling" &&
- git symbolic-ref refs/heads/dangling refs/heads/does-not-exist &&
- git show-ref --exists refs/heads/dangling
-'
-
-test_expect_success '--exists with nonexistent object ID' '
- test-tool ref-store main update-ref msg refs/heads/missing-oid $(test_oid 001) $ZERO_OID REF_SKIP_OID_VERIFICATION &&
- git show-ref --exists refs/heads/missing-oid
-'
-
-test_expect_success '--exists with non-commit object' '
- tree_oid=$(git rev-parse HEAD^{tree}) &&
- test-tool ref-store main update-ref msg refs/heads/tree ${tree_oid} $ZERO_OID REF_SKIP_OID_VERIFICATION &&
- git show-ref --exists refs/heads/tree
-'
-
-test_expect_success '--exists with directory fails with generic error' '
- cat >expect <<-EOF &&
- error: reference does not exist
- EOF
- test_expect_code 2 git show-ref --exists refs/heads 2>err &&
- test_cmp expect err
-'
-
-test_expect_success '--exists with non-existent special ref' '
- test_expect_code 2 git show-ref --exists FETCH_HEAD
-'
-
-test_expect_success '--exists with existing special ref' '
- test_when_finished "rm .git/FETCH_HEAD" &&
- git rev-parse HEAD >.git/FETCH_HEAD &&
- git show-ref --exists FETCH_HEAD
-'
-
test_done
diff --git a/t/t1408-packed-refs.sh b/t/t1408-packed-refs.sh
index 41ba1f1d7f..833477f0fa 100755
--- a/t/t1408-packed-refs.sh
+++ b/t/t1408-packed-refs.sh
@@ -42,4 +42,19 @@ test_expect_success 'no error from stale entry in packed-refs' '
test_cmp expect actual
'
+test_expect_success 'list packed refs with unicode characters' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit --no-tag A &&
+ git update-ref refs/heads/ HEAD &&
+ git update-ref refs/heads/z HEAD &&
+ git pack-refs --all &&
+ printf "%s commit\trefs/heads/z\n" $(git rev-parse HEAD) >expect &&
+ git for-each-ref refs/heads/z >actual &&
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index 388fdf9ae5..e30f87a358 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -315,9 +315,9 @@ test_expect_success 'git reflog expire unknown reference' '
test_config gc.reflogexpireunreachable never &&
test_must_fail git reflog expire main@{123} 2>stderr &&
- test_grep "points nowhere" stderr &&
+ test_grep "error: reflog could not be found: ${SQ}main@{123}${SQ}" stderr &&
test_must_fail git reflog expire does-not-exist 2>stderr &&
- test_grep "points nowhere" stderr
+ test_grep "error: reflog could not be found: ${SQ}does-not-exist${SQ}" stderr
'
test_expect_success 'checkout should not delete log for packed ref' '
@@ -551,4 +551,154 @@ test_expect_success 'reflog with invalid object ID can be listed' '
)
'
+test_expect_success 'reflog drop non-existent ref' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_must_fail git reflog exists refs/heads/non-existent &&
+ test_must_fail git reflog drop refs/heads/non-existent 2>stderr &&
+ test_grep "error: reflog could not be found: ${SQ}refs/heads/non-existent${SQ}" stderr
+ )
+'
+
+test_expect_success 'reflog drop' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit A &&
+ test_commit_bulk --ref=refs/heads/branch 1 &&
+ git reflog exists refs/heads/main &&
+ git reflog exists refs/heads/branch &&
+ git reflog drop refs/heads/main &&
+ test_must_fail git reflog exists refs/heads/main &&
+ git reflog exists refs/heads/branch
+ )
+'
+
+test_expect_success 'reflog drop multiple references' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit A &&
+ test_commit_bulk --ref=refs/heads/branch 1 &&
+ git reflog exists refs/heads/main &&
+ git reflog exists refs/heads/branch &&
+ git reflog drop refs/heads/main refs/heads/branch &&
+ test_must_fail git reflog exists refs/heads/main &&
+ test_must_fail git reflog exists refs/heads/branch
+ )
+'
+
+test_expect_success 'reflog drop multiple references some non-existent' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit A &&
+ test_commit_bulk --ref=refs/heads/branch 1 &&
+ git reflog exists refs/heads/main &&
+ git reflog exists refs/heads/branch &&
+ test_must_fail git reflog exists refs/heads/non-existent &&
+ test_must_fail git reflog drop refs/heads/main refs/heads/non-existent refs/heads/branch 2>stderr &&
+ test_must_fail git reflog exists refs/heads/main &&
+ test_must_fail git reflog exists refs/heads/branch &&
+ test_must_fail git reflog exists refs/heads/non-existent &&
+ test_grep "error: reflog could not be found: ${SQ}refs/heads/non-existent${SQ}" stderr
+ )
+'
+
+test_expect_success 'reflog drop --all' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit A &&
+ test_commit_bulk --ref=refs/heads/branch 1 &&
+ git reflog exists refs/heads/main &&
+ git reflog exists refs/heads/branch &&
+ git reflog drop --all &&
+ test_must_fail git reflog exists refs/heads/main &&
+ test_must_fail git reflog exists refs/heads/branch
+ )
+'
+
+test_expect_success 'reflog drop --all multiple worktrees' '
+ test_when_finished "rm -rf repo" &&
+ test_when_finished "rm -rf wt" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit A &&
+ git worktree add ../wt &&
+ test_commit_bulk -C ../wt --ref=refs/heads/branch 1 &&
+ git reflog exists refs/heads/main &&
+ git reflog exists refs/heads/branch &&
+ git reflog drop --all &&
+ test_must_fail git reflog exists refs/heads/main &&
+ test_must_fail git reflog exists refs/heads/branch
+ )
+'
+
+test_expect_success 'reflog drop --all --single-worktree' '
+ test_when_finished "rm -rf repo" &&
+ test_when_finished "rm -rf wt" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit A &&
+ git worktree add ../wt &&
+ test_commit -C ../wt foobar &&
+ git reflog exists refs/heads/main &&
+ git reflog exists refs/heads/wt &&
+ test-tool ref-store worktree:wt reflog-exists HEAD &&
+ git reflog drop --all --single-worktree &&
+ test_must_fail git reflog exists refs/heads/main &&
+ test_must_fail git reflog exists refs/heads/wt &&
+ test_must_fail test-tool ref-store worktree:main reflog-exists HEAD &&
+ test-tool ref-store worktree:wt reflog-exists HEAD
+ )
+'
+
+test_expect_success 'reflog drop --all with reference' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit A &&
+ test_must_fail git reflog drop --all refs/heads/main 2>stderr &&
+ test_grep "usage: references specified along with --all" stderr
+ )
+'
+
+test_expect_success 'expire with pattern config' '
+ # Split refs/heads/ into two roots so we can apply config to each. Make
+ # two branches per root to verify that config is applied correctly
+ # multiple times.
+ git branch root1/branch1 &&
+ git branch root1/branch2 &&
+ git branch root2/branch1 &&
+ git branch root2/branch2 &&
+
+ test_config "gc.reflogexpire" "never" &&
+ test_config "gc.refs/heads/root2/*.reflogExpire" "now" &&
+ git reflog expire \
+ root1/branch1 root1/branch2 \
+ root2/branch1 root2/branch2 &&
+
+ cat >expect <<-\EOF &&
+ root1/branch1@{0}
+ root1/branch2@{0}
+ EOF
+ git log -g --branches="root*" --format=%gD >actual.raw &&
+ # The sole reflog entry of each branch points to the same commit, so
+ # the order in which they are shown is nondeterministic. We just care
+ # about the what was expired (and what was not), so sort to get a known
+ # order.
+ sort <actual.raw >actual.sorted &&
+ test_cmp expect actual.sorted
+'
+
test_done
diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh
index 8c777f7cf8..d91dd3a3b5 100755
--- a/t/t1416-ref-transaction-hooks.sh
+++ b/t/t1416-ref-transaction-hooks.sh
@@ -120,8 +120,6 @@ test_expect_success 'interleaving hook calls succeed' '
cat >expect <<-EOF &&
hooks/update refs/tags/PRE $ZERO_OID $PRE_OID
- hooks/reference-transaction prepared
- hooks/reference-transaction committed
hooks/update refs/tags/POST $ZERO_OID $POST_OID
hooks/reference-transaction prepared
hooks/reference-transaction committed
diff --git a/t/t1419-exclude-refs.sh b/t/t1419-exclude-refs.sh
index c04eeb7211..04797aee59 100755
--- a/t/t1419-exclude-refs.sh
+++ b/t/t1419-exclude-refs.sh
@@ -46,6 +46,10 @@ test_expect_success 'setup' '
echo "create refs/heads/$name/$i $base" || return 1
done || return 1
done >in &&
+ for i in 5 6 7
+ do
+ echo "create refs/heads/bar/4/$i $base" || return 1
+ done >>in &&
echo "delete refs/heads/main" >>in &&
git update-ref --stdin <in &&
@@ -99,9 +103,17 @@ test_expect_success 'adjacent, non-overlapping excluded regions' '
esac
'
-test_expect_success 'overlapping excluded regions' '
+test_expect_success 'non-directory excluded regions' '
for_each_ref__exclude refs/heads refs/heads/ba refs/heads/baz >actual 2>perf &&
- for_each_ref refs/heads/foo refs/heads/quux >expect &&
+ for_each_ref refs/heads/bar refs/heads/foo refs/heads/quux >expect &&
+
+ test_cmp expect actual &&
+ assert_jumps 1 perf
+'
+
+test_expect_success 'overlapping excluded regions' '
+ for_each_ref__exclude refs/heads refs/heads/bar refs/heads/bar/4 >actual 2>perf &&
+ for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect &&
test_cmp expect actual &&
assert_jumps 1 perf
@@ -155,4 +167,14 @@ test_expect_success 'meta-characters are discarded' '
assert_no_jumps perf
'
+test_expect_success 'empty string exclude pattern is ignored' '
+ git update-ref refs/heads/loose $(git rev-parse refs/heads/foo/1) &&
+
+ for_each_ref__exclude refs/heads "" >actual 2>perf &&
+ for_each_ref >expect &&
+
+ test_cmp expect actual &&
+ assert_no_jumps perf
+'
+
test_done
diff --git a/t/t1421-reflog-write.sh b/t/t1421-reflog-write.sh
new file mode 100755
index 0000000000..46df64c176
--- /dev/null
+++ b/t/t1421-reflog-write.sh
@@ -0,0 +1,126 @@
+#!/bin/sh
+
+test_description='Manually write reflog entries'
+
+. ./test-lib.sh
+
+SIGNATURE="C O Mitter <committer@example.com> 1112911993 -0700"
+
+test_reflog_matches () {
+ repo="$1" &&
+ refname="$2" &&
+ cat >actual &&
+ test-tool -C "$repo" ref-store main for-each-reflog-ent "$refname" >expected &&
+ test_cmp expected actual
+}
+
+test_expect_success 'invalid number of arguments' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ for args in "" "1" "1 2" "1 2 3" "1 2 3 4 5"
+ do
+ test_must_fail git reflog write $args 2>err &&
+ test_grep "usage: git reflog write" err || return 1
+ done
+ )
+'
+
+test_expect_success 'invalid refname' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_must_fail git reflog write "refs/heads/ invalid" $ZERO_OID $ZERO_OID first 2>err &&
+ test_grep "invalid reference name: " err
+ )
+'
+
+test_expect_success 'unqualified refname is rejected' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_must_fail git reflog write unqualified $ZERO_OID $ZERO_OID first 2>err &&
+ test_grep "invalid reference name: " err
+ )
+'
+
+test_expect_success 'nonexistent object IDs' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_must_fail git reflog write refs/heads/something $(test_oid deadbeef) $ZERO_OID old-object-id 2>err &&
+ test_grep "old object .* does not exist" err &&
+ test_must_fail git reflog write refs/heads/something $ZERO_OID $(test_oid deadbeef) new-object-id 2>err &&
+ test_grep "new object .* does not exist" err
+ )
+'
+
+test_expect_success 'abbreviated object IDs' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit initial &&
+ abbreviated_oid=$(git rev-parse HEAD | test_copy_bytes 8) &&
+ test_must_fail git reflog write refs/heads/something $abbreviated_oid $ZERO_OID old-object-id 2>err &&
+ test_grep "invalid old object ID" err &&
+ test_must_fail git reflog write refs/heads/something $ZERO_OID $abbreviated_oid new-object-id 2>err &&
+ test_grep "invalid new object ID" err
+ )
+'
+
+test_expect_success 'reflog message gets normalized' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit initial &&
+ COMMIT_OID=$(git rev-parse HEAD) &&
+ git reflog write HEAD $COMMIT_OID $COMMIT_OID "$(printf "message\nwith\nnewlines")" &&
+ git reflog show -1 --format=%gs HEAD >actual &&
+ echo "message with newlines" >expected &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'simple writes' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit initial &&
+ COMMIT_OID=$(git rev-parse HEAD) &&
+
+ git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&
+ test_reflog_matches . refs/heads/something <<-EOF &&
+ $ZERO_OID $COMMIT_OID $SIGNATURE first
+ EOF
+
+ git reflog write refs/heads/something $COMMIT_OID $COMMIT_OID second &&
+ test_reflog_matches . refs/heads/something <<-EOF
+ $ZERO_OID $COMMIT_OID $SIGNATURE first
+ $COMMIT_OID $COMMIT_OID $SIGNATURE second
+ EOF
+ )
+'
+
+test_expect_success 'can write to root ref' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit initial &&
+ COMMIT_OID=$(git rev-parse HEAD) &&
+
+ git reflog write ROOT_REF_HEAD $ZERO_OID $COMMIT_OID first &&
+ test_reflog_matches . ROOT_REF_HEAD <<-EOF
+ $ZERO_OID $COMMIT_OID $SIGNATURE first
+ EOF
+ )
+'
+
+test_done
diff --git a/t/t1422-show-ref-exists.sh b/t/t1422-show-ref-exists.sh
new file mode 100755
index 0000000000..fdca3f16c8
--- /dev/null
+++ b/t/t1422-show-ref-exists.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+test_description='show-ref --exists'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+. ./test-lib.sh
+
+. "$TEST_DIRECTORY"/show-ref-exists-tests.sh
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 8a456b1142..5ae86c42be 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -7,6 +7,7 @@ test_description='git fsck random collection of tests
'
. ./test-lib.sh
+. "$TEST_DIRECTORY/lib-loose.sh"
test_expect_success setup '
git config gc.auto 0 &&
@@ -71,30 +72,6 @@ test_expect_success 'object with hash mismatch' '
)
'
-test_expect_success 'object with hash and type mismatch' '
- git init --bare hash-type-mismatch &&
- (
- cd hash-type-mismatch &&
-
- oid=$(echo blob | git hash-object -w --stdin -t garbage --literally) &&
- oldoid=$oid &&
- old=$(test_oid_to_path "$oid") &&
- new=$(dirname $old)/$(test_oid ff_2) &&
- oid="$(dirname $new)$(basename $new)" &&
-
- mv objects/$old objects/$new &&
- git update-index --add --cacheinfo 100644 $oid foo &&
- tree=$(git write-tree) &&
- cmt=$(echo bogus | git commit-tree $tree) &&
- git update-ref refs/heads/bogus $cmt &&
-
-
- test_must_fail git fsck 2>out &&
- grep "^error: $oldoid: hash-path mismatch, found at: .*$new" out &&
- grep "^error: $oldoid: object is of unknown type '"'"'garbage'"'"'" out
- )
-'
-
test_expect_success 'zlib corrupt loose object output ' '
git init --bare corrupt-loose-output &&
(
@@ -346,7 +323,7 @@ test_expect_success 'unparseable tree object' '
test_grep ! "fatal: empty filename in tree entry" out
'
-test_expect_success 'tree entry with type mismatch' '
+test_expect_success PERL_TEST_HELPERS 'tree entry with type mismatch' '
test_when_finished "remove_object \$blob" &&
test_when_finished "remove_object \$tree" &&
test_when_finished "remove_object \$commit" &&
@@ -364,7 +341,7 @@ test_expect_success 'tree entry with type mismatch' '
test_grep ! "dangling blob" out
'
-test_expect_success 'tree entry with bogus mode' '
+test_expect_success PERL_TEST_HELPERS 'tree entry with bogus mode' '
test_when_finished "remove_object \$blob" &&
test_when_finished "remove_object \$tree" &&
blob=$(echo blob | git hash-object -w --stdin) &&
@@ -984,7 +961,7 @@ corrupt_index_checksum () {
# Corrupt the checksum on the index and then
# verify that only fsck notices.
-test_expect_success 'detect corrupt index file in fsck' '
+test_expect_success PERL_TEST_HELPERS 'detect corrupt index file in fsck' '
cp .git/index .git/index.backup &&
test_when_finished "mv .git/index.backup .git/index" &&
corrupt_index_checksum &&
@@ -997,12 +974,13 @@ test_expect_success 'fsck error and recovery on invalid object type' '
(
cd garbage-type &&
- garbage_blob=$(git hash-object --stdin -w -t garbage --literally </dev/null) &&
+ garbage_blob=$(loose_obj objects garbage </dev/null) &&
test_must_fail git fsck 2>err &&
grep -e "^error" -e "^fatal" err >errors &&
- test_line_count = 1 errors &&
- grep "$garbage_blob: object is of unknown type '"'"'garbage'"'"':" err
+ test_line_count = 2 errors &&
+ test_grep "unable to parse type from header .garbage" err &&
+ test_grep "$garbage_blob: object corrupt or missing:" err
)
'
diff --git a/t/t1460-refs-migrate.sh b/t/t1460-refs-migrate.sh
index f59bc4860f..0e1116a319 100755
--- a/t/t1460-refs-migrate.sh
+++ b/t/t1460-refs-migrate.sh
@@ -7,35 +7,50 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
+print_all_reflog_entries () {
+ repo=$1 &&
+ test-tool -C "$repo" ref-store main for-each-reflog >reflogs &&
+ while read reflog
+ do
+ echo "REFLOG: $reflog" &&
+ test-tool -C "$repo" ref-store main for-each-reflog-ent "$reflog" ||
+ return 1
+ done <reflogs
+}
+
# Migrate the provided repository from one format to the other and
# verify that the references and logs are migrated over correctly.
-# Usage: test_migration <repo> <format> <skip_reflog_verify>
+# Usage: test_migration <repo> <format> [<skip_reflog_verify> [<options...>]]
# <repo> is the relative path to the repo to be migrated.
# <format> is the ref format to be migrated to.
-# <skip_reflog_verify> (true or false) whether to skip reflog verification.
+# <skip_reflog_verify> (default: false) whether to skip reflog verification.
+# <options...> are other options be passed directly to 'git refs migrate'.
test_migration () {
repo=$1 &&
format=$2 &&
- skip_reflog_verify=${3:-false} &&
+ shift 2 &&
+ skip_reflog_verify=false &&
+ if test $# -ge 1
+ then
+ skip_reflog_verify=$1
+ shift
+ fi &&
git -C "$repo" for-each-ref --include-root-refs \
--format='%(refname) %(objectname) %(symref)' >expect &&
if ! $skip_reflog_verify
then
- git -C "$repo" reflog --all >expect_logs &&
- git -C "$repo" reflog list >expect_log_list
+ print_all_reflog_entries "$repo" >expect_logs
fi &&
- git -C "$repo" refs migrate --ref-format="$2" &&
+ git -C "$repo" refs migrate --ref-format="$format" "$@" &&
git -C "$repo" for-each-ref --include-root-refs \
--format='%(refname) %(objectname) %(symref)' >actual &&
test_cmp expect actual &&
if ! $skip_reflog_verify
then
- git -C "$repo" reflog --all >actual_logs &&
- git -C "$repo" reflog list >actual_log_list &&
- test_cmp expect_logs actual_logs &&
- test_cmp expect_log_list actual_log_list
+ print_all_reflog_entries "$repo" >actual_logs &&
+ test_cmp expect_logs actual_logs
fi &&
git -C "$repo" rev-parse --show-ref-format >actual &&
@@ -224,9 +239,51 @@ do
test_commit --date "100003000 +0700" --no-tag -C repo second &&
test_migration repo "$to_format"
'
+
+ test_expect_success "$from_format -> $to_format: stash is retained" '
+ test_when_finished "rm -rf repo" &&
+ git init --ref-format=$from_format repo &&
+ (
+ cd repo &&
+ test_commit initial A &&
+ echo foo >A &&
+ git stash push &&
+ echo bar >A &&
+ git stash push &&
+ git stash list >expect.reflog &&
+ test_migration . "$to_format" &&
+ git stash list >actual.reflog &&
+ test_cmp expect.reflog actual.reflog
+ )
+ '
+
+ test_expect_success "$from_format -> $to_format: skip reflog with --skip-reflog" '
+ test_when_finished "rm -rf repo" &&
+ git init --ref-format=$from_format repo &&
+ test_commit -C repo initial &&
+ # we see that the repository contains reflogs.
+ git -C repo reflog --all >reflogs &&
+ test_line_count = 2 reflogs &&
+ test_migration repo "$to_format" true --no-reflog &&
+ # there should be no reflogs post migration.
+ git -C repo reflog --all >reflogs &&
+ test_must_be_empty reflogs
+ '
done
done
+test_expect_success 'multiple reftable blocks with multiple entries' '
+ test_when_finished "rm -rf repo" &&
+ git init --ref-format=files repo &&
+ test_commit -C repo first &&
+ printf "create refs/heads/ref-%d HEAD\n" $(test_seq 5000) >stdin &&
+ git -C repo update-ref --stdin <stdin &&
+ test_commit -C repo second &&
+ printf "update refs/heads/ref-%d HEAD\n" $(test_seq 3000) >stdin &&
+ git -C repo update-ref --stdin <stdin &&
+ test_migration repo reftable true
+'
+
test_expect_success 'migrating from files format deletes backend files' '
test_when_finished "rm -rf repo" &&
git init --ref-format=files repo &&
diff --git a/t/t1461-refs-list.sh b/t/t1461-refs-list.sh
new file mode 100755
index 0000000000..36e3d81e59
--- /dev/null
+++ b/t/t1461-refs-list.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+test_description='git refs list tests'
+
+. ./test-lib.sh
+
+git_for_each_ref='git refs list'
+. "$TEST_DIRECTORY"/for-each-ref-tests.sh
diff --git a/t/t1462-refs-exists.sh b/t/t1462-refs-exists.sh
new file mode 100755
index 0000000000..349453c4ca
--- /dev/null
+++ b/t/t1462-refs-exists.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+test_description='refs exists'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+. ./test-lib.sh
+
+git_show_ref_exists='git refs exists'
+. "$TEST_DIRECTORY"/show-ref-exists-tests.sh
diff --git a/t/t1512-rev-parse-disambiguation.sh b/t/t1512-rev-parse-disambiguation.sh
index 70f1e0a998..1a380a4184 100755
--- a/t/t1512-rev-parse-disambiguation.sh
+++ b/t/t1512-rev-parse-disambiguation.sh
@@ -24,6 +24,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
+. "$TEST_DIRECTORY/lib-loose.sh"
test_cmp_failed_rev_parse () {
dir=$1
@@ -67,8 +68,8 @@ test_expect_success 'ambiguous loose bad object parsed as OBJ_BAD' '
cd blob.bad &&
# Both have the prefix "bad0"
- echo xyzfaowcoh | git hash-object -t bad -w --stdin --literally &&
- echo xyzhjpyvwl | git hash-object -t bad -w --stdin --literally
+ echo xyzfaowcoh | loose_obj objects bad &&
+ echo xyzhjpyvwl | loose_obj objects bad
) &&
test_cmp_failed_rev_parse blob.bad bad0 <<-\EOF
diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh
index dbd8cd6906..c824c1a25c 100755
--- a/t/t1517-outside-repo.sh
+++ b/t/t1517-outside-repo.sh
@@ -107,4 +107,46 @@ test_expect_success LIBCURL 'remote-http outside repository' '
test_grep "^error: remote-curl" actual
'
+for cmd in $(git --list-cmds=main)
+do
+ cmd=${cmd%.*} # strip .sh, .perl, etc.
+ case "$cmd" in
+ archimport | citool | credential-netrc | credential-libsecret | \
+ credential-osxkeychain | cvsexportcommit | cvsimport | cvsserver | \
+ daemon | \
+ difftool--helper | filter-branch | fsck-objects | get-tar-commit-id | \
+ gui | gui--askpass | \
+ http-backend | http-fetch | http-push | init-db | \
+ merge-octopus | merge-one-file | merge-resolve | mergetool | \
+ mktag | p4 | p4.py | pickaxe | remote-ftp | remote-ftps | \
+ remote-http | remote-https | replay | send-email | \
+ sh-i18n--envsubst | shell | show | stage | submodule | svn | \
+ upload-archive--writer | upload-pack | web--browse | whatchanged)
+ expect_outcome=expect_failure ;;
+ *)
+ expect_outcome=expect_success ;;
+ esac
+ case "$cmd" in
+ instaweb)
+ prereq=PERL ;;
+ *)
+ prereq= ;;
+ esac
+ test_$expect_outcome $prereq "'git $cmd -h' outside a repository" '
+ test_expect_code 129 nongit git $cmd -h >usage &&
+ test_grep "[Uu]sage: git $cmd " usage
+ '
+ test_$expect_outcome $prereq "'git $cmd --help-all' outside a repository" '
+ test_expect_code 129 nongit git $cmd --help-all >usage &&
+ test_grep "[Uu]sage: git $cmd " usage
+ '
+done
+
+test_expect_success 'fmt-merge-msg does not crash with -h' '
+ test_expect_code 129 git fmt-merge-msg -h >usage &&
+ test_grep "[Uu]sage: git fmt-merge-msg " usage &&
+ test_expect_code 129 nongit git fmt-merge-msg -h >usage &&
+ test_grep "[Uu]sage: git fmt-merge-msg " usage
+'
+
test_done
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
new file mode 100755
index 0000000000..2beba67889
--- /dev/null
+++ b/t/t1900-repo.sh
@@ -0,0 +1,113 @@
+#!/bin/sh
+
+test_description='test git repo-info'
+
+. ./test-lib.sh
+
+# Test whether a key-value pair is correctly returned
+#
+# Usage: test_repo_info <label> <init command> <repo_name> <key> <expected value>
+#
+# Arguments:
+# label: the label of the test
+# init_command: a command which creates a repository
+# repo_name: the name of the repository that will be created in init_command
+# key: the key of the field that is being tested
+# expected_value: the value that the field should contain
+test_repo_info () {
+ label=$1
+ init_command=$2
+ repo_name=$3
+ key=$4
+ expected_value=$5
+
+ test_expect_success "setup: $label" '
+ eval "$init_command $repo_name"
+ '
+
+ test_expect_success "keyvalue: $label" '
+ echo "$key=$expected_value" > expect &&
+ git -C "$repo_name" repo info "$key" >actual &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "nul: $label" '
+ printf "%s\n%s\0" "$key" "$expected_value" >expect &&
+ git -C "$repo_name" repo info --format=nul "$key" >actual &&
+ test_cmp_bin expect actual
+ '
+}
+
+test_repo_info 'ref format files is retrieved correctly' \
+ 'git init --ref-format=files' 'format-files' 'references.format' 'files'
+
+test_repo_info 'ref format reftable is retrieved correctly' \
+ 'git init --ref-format=reftable' 'format-reftable' 'references.format' 'reftable'
+
+test_repo_info 'bare repository = false is retrieved correctly' \
+ 'git init' 'nonbare' 'layout.bare' 'false'
+
+test_repo_info 'bare repository = true is retrieved correctly' \
+ 'git init --bare' 'bare' 'layout.bare' 'true'
+
+test_repo_info 'shallow repository = false is retrieved correctly' \
+ 'git init' 'nonshallow' 'layout.shallow' 'false'
+
+test_expect_success 'setup remote' '
+ git init remote &&
+ echo x >remote/x &&
+ git -C remote add x &&
+ git -C remote commit -m x
+'
+
+test_repo_info 'shallow repository = true is retrieved correctly' \
+ 'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
+
+test_repo_info 'object.format = sha1 is retrieved correctly' \
+ 'git init --object-format=sha1' 'sha1' 'object.format' 'sha1'
+
+test_repo_info 'object.format = sha256 is retrieved correctly' \
+ 'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
+
+test_expect_success 'values returned in order requested' '
+ cat >expect <<-\EOF &&
+ layout.bare=false
+ references.format=files
+ layout.bare=false
+ EOF
+ git init --ref-format=files ordered &&
+ git -C ordered repo info layout.bare references.format layout.bare >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git-repo-info fails if an invalid key is requested' '
+ echo "error: key ${SQ}foo${SQ} not found" >expect &&
+ test_must_fail git repo info foo 2>actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git-repo-info outputs data even if there is an invalid field' '
+ echo "references.format=$(test_detect_ref_format)" >expect &&
+ test_must_fail git repo info foo references.format bar >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git-repo-info aborts when requesting an invalid format' '
+ echo "fatal: invalid format ${SQ}foo${SQ}" >expect &&
+ test_must_fail git repo info --format=foo 2>actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '-z uses nul-terminated format' '
+ printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expected &&
+ git repo info -z layout.bare layout.shallow >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'git repo info uses the last requested format' '
+ echo "layout.bare=false" >expected &&
+ git repo info --format=nul -z --format=keyvalue layout.bare >actual &&
+ test_cmp expected actual
+'
+
+test_done
diff --git a/t/t2006-checkout-index-basic.sh b/t/t2006-checkout-index-basic.sh
index bac231b167..fedd2cc097 100755
--- a/t/t2006-checkout-index-basic.sh
+++ b/t/t2006-checkout-index-basic.sh
@@ -21,6 +21,13 @@ test_expect_success 'checkout-index -h in broken repository' '
test_grep "[Uu]sage" broken/usage
'
+test_expect_success 'checkout-index does not crash with -h' '
+ test_expect_code 129 git checkout-index -h >usage &&
+ test_grep "[Uu]sage: git checkout-index " usage &&
+ test_expect_code 129 nongit git checkout-index -h >usage &&
+ test_grep "[Uu]sage: git checkout-index " usage
+'
+
test_expect_success 'checkout-index reports errors (cmdline)' '
test_must_fail git checkout-index -- does-not-exist 2>stderr &&
test_grep not.in.the.cache stderr
diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index 90638fa886..023e1301c8 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -42,8 +42,8 @@ test_expect_success '"add" using - shorthand' '
test_expect_success '"add" refuses to checkout locked branch' '
test_must_fail git worktree add zere main &&
- ! test -d zere &&
- ! test -d .git/worktrees/zere
+ test_path_is_missing zere &&
+ test_path_is_missing .git/worktrees/zere
'
test_expect_success 'checking out paths not complaining about linked checkouts' '
@@ -70,14 +70,14 @@ test_expect_success '"add" worktree' '
test_expect_success '"add" worktree with lock' '
git worktree add --detach --lock here-with-lock main &&
test_when_finished "git worktree unlock here-with-lock || :" &&
- test -f .git/worktrees/here-with-lock/locked
+ test_path_is_file .git/worktrees/here-with-lock/locked
'
test_expect_success '"add" worktree with lock and reason' '
lock_reason="why not" &&
git worktree add --detach --lock --reason "$lock_reason" here-with-lock-reason main &&
test_when_finished "git worktree unlock here-with-lock-reason || :" &&
- test -f .git/worktrees/here-with-lock-reason/locked &&
+ test_path_is_file .git/worktrees/here-with-lock-reason/locked &&
echo "$lock_reason" >expect &&
test_cmp expect .git/worktrees/here-with-lock-reason/locked
'
@@ -412,14 +412,14 @@ test_expect_success '"add --orphan" with empty repository' '
test_expect_success '"add" worktree with orphan branch and lock' '
git worktree add --lock --orphan -b orphanbr orphan-with-lock &&
test_when_finished "git worktree unlock orphan-with-lock || :" &&
- test -f .git/worktrees/orphan-with-lock/locked
+ test_path_is_file .git/worktrees/orphan-with-lock/locked
'
test_expect_success '"add" worktree with orphan branch, lock, and reason' '
lock_reason="why not" &&
git worktree add --detach --lock --reason "$lock_reason" orphan-with-lock-reason main &&
test_when_finished "git worktree unlock orphan-with-lock-reason || :" &&
- test -f .git/worktrees/orphan-with-lock-reason/locked &&
+ test_path_is_file .git/worktrees/orphan-with-lock-reason/locked &&
echo "$lock_reason" >expect &&
test_cmp expect .git/worktrees/orphan-with-lock-reason/locked
'
@@ -474,7 +474,7 @@ test_expect_success 'local clone --shared from linked checkout' '
test_expect_success '"add" worktree with --no-checkout' '
git worktree add --no-checkout -b swamp swamp &&
- ! test -e swamp/init.t &&
+ test_path_is_missing swamp/init.t &&
git -C swamp reset --hard &&
test_cmp init.t swamp/init.t
'
@@ -497,7 +497,7 @@ test_expect_success 'put a worktree under rebase' '
test_expect_success 'add a worktree, checking out a rebased branch' '
test_must_fail git worktree add new-rebase under-rebase &&
- ! test -d new-rebase
+ test_path_is_missing new-rebase
'
test_expect_success 'checking out a rebased branch from another worktree' '
@@ -535,7 +535,7 @@ test_expect_success 'checkout a branch under bisect' '
git worktree list >actual &&
grep "under-bisect.*detached HEAD" actual &&
test_must_fail git worktree add new-bisect under-bisect &&
- ! test -d new-bisect
+ test_path_is_missing new-bisect
)
'
@@ -1165,7 +1165,7 @@ test_expect_success '"add" not tripped up by magic worktree matching"' '
test_expect_success FUNNYNAMES 'sanitize generated worktree name' '
git worktree add --detach ". weird*..?.lock.lock" &&
- test -d .git/worktrees/---weird-.-
+ test_path_is_dir .git/worktrees/---weird-.-
'
test_expect_success '"add" should not fail because of another bad worktree' '
diff --git a/t/t2501-cwd-empty.sh b/t/t2501-cwd-empty.sh
index f6d8d7d03d..be9140bbaa 100755
--- a/t/t2501-cwd-empty.sh
+++ b/t/t2501-cwd-empty.sh
@@ -117,8 +117,6 @@ test_expect_success 'merge fails if cwd needs to be removed; recursive friendly'
grep "Refusing to remove the current working directory" error
'
-GIT_TEST_MERGE_ALGORITHM=ort
-
test_expect_success 'merge fails if cwd needs to be removed' '
test_required_dir_removal git merge fd_conflict
'
diff --git a/t/t3000-ls-files-others.sh b/t/t3000-ls-files-others.sh
index 13f66fd649..b41e7f0daa 100755
--- a/t/t3000-ls-files-others.sh
+++ b/t/t3000-ls-files-others.sh
@@ -73,25 +73,6 @@ test_expect_success 'ls-files --others handles non-submodule .git' '
test_cmp expected1 output
'
-test_expect_success SYMLINKS 'ls-files --others with symlinked submodule' '
- git init super &&
- git init sub &&
- (
- cd sub &&
- >a &&
- git add a &&
- git commit -m sub &&
- git pack-refs --all
- ) &&
- (
- cd super &&
- "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub &&
- git ls-files --others --exclude-standard >../actual
- ) &&
- echo sub/ >expect &&
- test_cmp expect actual
-'
-
test_expect_success 'setup nested pathspec search' '
test_create_repo nested &&
(
diff --git a/t/t3004-ls-files-basic.sh b/t/t3004-ls-files-basic.sh
index a1078f8701..4034a5a59f 100755
--- a/t/t3004-ls-files-basic.sh
+++ b/t/t3004-ls-files-basic.sh
@@ -34,6 +34,13 @@ test_expect_success 'ls-files -h in corrupt repository' '
test_grep "[Uu]sage: git ls-files " broken/usage
'
+test_expect_success 'ls-files does not crash with -h' '
+ test_expect_code 129 git ls-files -h >usage &&
+ test_grep "[Uu]sage: git ls-files " usage &&
+ test_expect_code 129 nongit git ls-files -h >usage &&
+ test_grep "[Uu]sage: git ls-files " usage
+'
+
test_expect_success SYMLINKS 'ls-files with absolute paths to symlinks' '
mkdir subs &&
ln -s nosuch link &&
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index a3a21c54cf..f3e720dc10 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -410,6 +410,20 @@ test_expect_success 'bare main worktree has HEAD at branch deleted by secondary
git -C secondary branch -D main
'
+test_expect_success 'secondary worktrees recognize core.bare=true in main config.worktree' '
+ test_when_finished "rm -rf bare_repo non_bare_repo secondary_worktree" &&
+ git init -b main non_bare_repo &&
+ test_commit -C non_bare_repo x &&
+
+ git clone --bare non_bare_repo bare_repo &&
+ git -C bare_repo config extensions.worktreeConfig true &&
+ git -C bare_repo config unset core.bare &&
+ git -C bare_repo config --worktree core.bare true &&
+
+ git -C bare_repo worktree add ../secondary_worktree &&
+ git -C secondary_worktree checkout main
+'
+
test_expect_success 'git branch --list -v with --abbrev' '
test_when_finished "git branch -D t" &&
git branch t &&
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 500c9d0e72..a6bd88a58d 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -368,6 +368,34 @@ test_expect_success 'git branch --format with ahead-behind' '
test_cmp expect actual
'
+test_expect_success 'git branch `--sort=[-]ahead-behind` option' '
+ cat >expect <<-\EOF &&
+ (HEAD detached from fromtag) 0 0
+ refs/heads/ambiguous 0 0
+ refs/heads/branch-two 0 0
+ refs/heads/branch-one 1 0
+ refs/heads/main 1 0
+ refs/heads/ref-to-branch 1 0
+ refs/heads/ref-to-remote 1 0
+ EOF
+ git branch --format="%(refname) %(ahead-behind:HEAD)" \
+ --sort=refname --sort=ahead-behind:HEAD >actual &&
+ test_cmp expect actual &&
+
+ cat >expect <<-\EOF &&
+ (HEAD detached from fromtag) 0 0
+ refs/heads/branch-one 1 0
+ refs/heads/main 1 0
+ refs/heads/ref-to-branch 1 0
+ refs/heads/ref-to-remote 1 0
+ refs/heads/ambiguous 0 0
+ refs/heads/branch-two 0 0
+ EOF
+ git branch --format="%(refname) %(ahead-behind:HEAD)" \
+ --sort=refname --sort=-ahead-behind:HEAD >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'git branch with --format=%(rest) must fail' '
test_must_fail git branch --format="%(rest)" >actual
'
diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh
index f5bf16abcd..dd0586b007 100755
--- a/t/t3300-funny-names.sh
+++ b/t/t3300-funny-names.sh
@@ -70,7 +70,7 @@ test_expect_success 'ls-files -z does not quote funny filename' '
tabs ," (dq) and spaces
EOF
git ls-files -z >ls-files.z &&
- perl -pe "y/\000/\012/" <ls-files.z >current &&
+ tr "\000" "\012" <ls-files.z >current &&
test_cmp expected current
'
@@ -107,7 +107,7 @@ test_expect_success 'diff-index -z does not quote funny filename' '
tabs ," (dq) and spaces
EOF
git diff-index -z --name-status $t0 >diff-index.z &&
- perl -pe "y/\000/\012/" <diff-index.z >current &&
+ tr "\000" "\012" <diff-index.z >current &&
test_cmp expected current
'
@@ -117,7 +117,7 @@ test_expect_success 'diff-tree -z does not quote funny filename' '
tabs ," (dq) and spaces
EOF
git diff-tree -z --name-status $t0 $t1 >diff-tree.z &&
- perl -pe y/\\000/\\012/ <diff-tree.z >current &&
+ tr "\000" "\012" <diff-tree.z >current &&
test_cmp expected current
'
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ecfc02062c..34d6ad0770 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -791,6 +791,20 @@ test_expect_success 'reword' '
grep "C changed" actual
'
+test_expect_success 'reword fast-forwarded empty commit' '
+ git commit --allow-empty -m "empty commit" --only &&
+ (
+ set_fake_editor &&
+ FAKE_COMMIT_AMEND=edited FAKE_LINES="reword 1" \
+ git rebase -i HEAD^
+ ) &&
+ test_commit_message HEAD <<-\EOF
+ empty commit
+
+ edited
+ EOF
+'
+
test_expect_success 'no uncommitted changes when rewording and the todo list is reloaded' '
git checkout E &&
test_when_finished "git checkout @{-1}" &&
@@ -1454,7 +1468,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
cat >expect <<-EOF &&
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
- - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
+ - $(git log --format="%h # %s" -1 primary)
To avoid this message, use "drop" to explicitly remove a commit.
EOF
test_config rebase.missingCommitsCheck warn &&
@@ -1472,8 +1486,8 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
cat >expect <<-EOF &&
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
- - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
- - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2)
+ - $(git log --format="%h # %s" -1 primary)
+ - $(git log --format="%h # %s" -1 primary~2)
To avoid this message, use "drop" to explicitly remove a commit.
Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
@@ -1516,11 +1530,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ig
test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
cat >expect <<-EOF &&
error: invalid command '\''pickled'\''
- error: invalid line 1: pickled $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
+ error: invalid line 1: pickled $(git log --format="%h # %s" -1 primary~4)
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
- - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
- - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
+ - $(git log --format="%h # %s" -1 primary)
+ - $(git log --format="%h # %s" -1 primary~4)
To avoid this message, use "drop" to explicitly remove a commit.
EOF
head -n5 expect >expect.2 &&
@@ -1551,11 +1565,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa
test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
cat >expect <<-EOF &&
error: invalid command '\''pickled'\''
- error: invalid line 1: pickled $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
+ error: invalid line 1: pickled $(git log --format="%h # %s" -1 primary~4)
Warning: some commits may have been dropped accidentally.
Dropped commits (newer to older):
- - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
- - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
+ - $(git log --format="%h # %s" -1 primary)
+ - $(git log --format="%h # %s" -1 primary~4)
To avoid this message, use "drop" to explicitly remove a commit.
Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
@@ -1628,11 +1642,11 @@ test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and e
test_commit "fixup! first" file2.txt "first line again" first_fixup &&
test_commit "squash! second" file1.txt "another line here" second_squash &&
cat >expected <<-EOF &&
- p $(git rev-list --abbrev-commit -1 first) first
- f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
+ p $(git rev-list --abbrev-commit -1 first) # first
+ f $(git rev-list --abbrev-commit -1 first_fixup) # fixup! first
x git show HEAD
- p $(git rev-list --abbrev-commit -1 second) second
- s $(git rev-list --abbrev-commit -1 second_squash) squash! second
+ p $(git rev-list --abbrev-commit -1 second) # second
+ s $(git rev-list --abbrev-commit -1 second_squash) # squash! second
x git show HEAD
EOF
git checkout abbrevcmd &&
@@ -1651,7 +1665,7 @@ test_expect_success 'static check of bad command' '
set_fake_editor &&
test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
git rebase -i --root 2>actual &&
- test_grep "pickled $(git rev-list --oneline -1 primary~1)" \
+ test_grep "pickled $(git log --format="%h # %s" -1 primary~1)" \
actual &&
test_grep "You can fix this with .git rebase --edit-todo.." \
actual &&
@@ -1851,15 +1865,15 @@ test_expect_success '--update-refs adds label and update-ref commands' '
set_cat_todo_editor &&
cat >expect <<-EOF &&
- pick $(git log -1 --format=%h J) J
- fixup $(git log -1 --format=%h update-refs) fixup! J # empty
+ pick $(git log -1 --format=%h J) # J
+ fixup $(git log -1 --format=%h update-refs) # fixup! J # empty
update-ref refs/heads/second
update-ref refs/heads/first
- pick $(git log -1 --format=%h K) K
- pick $(git log -1 --format=%h L) L
- fixup $(git log -1 --format=%h is-not-reordered) fixup! L # empty
+ pick $(git log -1 --format=%h K) # K
+ pick $(git log -1 --format=%h L) # L
+ fixup $(git log -1 --format=%h is-not-reordered) # fixup! L # empty
update-ref refs/heads/third
- pick $(git log -1 --format=%h M) M
+ pick $(git log -1 --format=%h M) # M
update-ref refs/heads/no-conflict-branch
update-ref refs/heads/is-not-reordered
update-ref refs/heads/shared-tip
@@ -1891,19 +1905,19 @@ test_expect_success '--update-refs adds commands with --rebase-merges' '
cat >expect <<-EOF &&
label onto
reset onto
- pick $(git log -1 --format=%h branch2~1) F
- pick $(git log -1 --format=%h branch2) I
+ pick $(git log -1 --format=%h branch2~1) # F
+ pick $(git log -1 --format=%h branch2) # I
update-ref refs/heads/branch2
label branch2
reset onto
- pick $(git log -1 --format=%h refs/heads/second) J
+ pick $(git log -1 --format=%h refs/heads/second) # J
update-ref refs/heads/second
update-ref refs/heads/first
- pick $(git log -1 --format=%h refs/heads/third~1) K
- pick $(git log -1 --format=%h refs/heads/third) L
- fixup $(git log -1 --format=%h update-refs-with-merge) fixup! L # empty
+ pick $(git log -1 --format=%h refs/heads/third~1) # K
+ pick $(git log -1 --format=%h refs/heads/third) # L
+ fixup $(git log -1 --format=%h update-refs-with-merge) # fixup! L # empty
update-ref refs/heads/third
- pick $(git log -1 --format=%h HEAD~2) M
+ pick $(git log -1 --format=%h HEAD~2) # M
update-ref refs/heads/no-conflict-branch
merge -C $(git log -1 --format=%h HEAD~1) branch2 # merge
update-ref refs/heads/merge-branch
@@ -2249,6 +2263,7 @@ test_expect_success 'non-merge commands reject merge commits' '
edit $oid
fixup $oid
squash $oid
+ drop $oid # acceptable, no advice
EOF
(
set_replace_editor todo &&
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index fcc40d6fe1..5d093e3a7a 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -257,8 +257,8 @@ test_expect_success 'auto squash of fixup commit that matches branch name which
GIT_SEQUENCE_EDITOR="cat >tmp" git rebase --autosquash -i HEAD^^ &&
sed -ne "/^[^#]/{s/[0-9a-f]\{7,\}/HASH/g;p;}" tmp >actual &&
cat <<-EOF >expect &&
- pick HASH second commit
- pick HASH fixup! self-cycle # empty
+ pick HASH # second commit
+ pick HASH # fixup! self-cycle # empty
EOF
test_cmp expect actual
'
@@ -311,10 +311,10 @@ test_auto_fixup_fixup () {
parent2=$(git rev-parse --short HEAD^^) &&
parent3=$(git rev-parse --short HEAD^^^) &&
cat >expected <<-EOF &&
- pick $parent3 first commit
- $1 $parent1 $1! first
- $1 $head $1! $2! first
- pick $parent2 second commit
+ pick $parent3 # first commit
+ $1 $parent1 # $1! first
+ $1 $head # $1! $2! first
+ pick $parent2 # second commit
EOF
test_cmp expected actual
) &&
@@ -389,11 +389,21 @@ test_expect_success 'autosquash with empty custom instructionFormat' '
set_cat_todo_editor &&
test_must_fail git -c rebase.instructionFormat= \
rebase --autosquash --force-rebase -i HEAD^ >actual &&
- git log -1 --format="pick %h %s" >expect &&
+ git log -1 --format="pick %h # %s" >expect &&
test_cmp expect actual
)
'
+test_expect_success 'autosquash with invalid custom instructionFormat' '
+ git reset --hard base &&
+ test_commit invalid-instructionFormat-test &&
+ (
+ test_must_fail git -c rebase.instructionFormat=blah \
+ rebase --autosquash --force-rebase -i HEAD^ &&
+ test_path_is_missing .git/rebase-merge
+ )
+'
+
set_backup_editor () {
write_script backup-editor.sh <<-\EOF
cp "$1" .git/backup-"$(basename "$1")"
diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh
index 127216f722..b8a8dd77e7 100755
--- a/t/t3418-rebase-continue.sh
+++ b/t/t3418-rebase-continue.sh
@@ -328,6 +328,19 @@ test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebas
test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
'
+test_expect_success 'no change in comment character due to conflicts markers with core.commentChar=auto' '
+ git checkout -b branch-a &&
+ test_commit A F1 &&
+ git checkout -b branch-b HEAD^ &&
+ test_commit B F1 &&
+ test_must_fail git rebase branch-a &&
+ printf "B\nA\n" >F1 &&
+ git add F1 &&
+ GIT_EDITOR="cat >actual" git -c core.commentChar=auto rebase --continue &&
+ # Check that "#" is still the comment character.
+ test_grep "^# Changes to be committed" actual
+'
+
test_orig_head_helper () {
test_when_finished 'git rebase --abort &&
git checkout topic &&
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 2593711fec..cc627e34a7 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -86,7 +86,7 @@ test_expect_success 'create completely different structure' '
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
test_tick &&
git rebase -i -r A main &&
- test_cmp_graph <<-\EOF
+ test_cmp_graph <<-\EOF &&
* Merge the topic branch '\''onebranch'\''
|\
| * D
@@ -99,6 +99,15 @@ test_expect_success 'create completely different structure' '
|/
* A
EOF
+
+ head="$(git show-ref --verify -s --abbrev HEAD)" &&
+ cat >expect <<-EOF &&
+ $head HEAD@{0}: rebase (finish): returning to refs/heads/main
+ $head HEAD@{1}: rebase (merge): Merge the topic branch ${SQ}onebranch${SQ}
+ EOF
+
+ git reflog -n2 HEAD >actual &&
+ test_cmp expect actual
'
test_expect_success 'generate correct todo list' '
@@ -106,18 +115,18 @@ test_expect_success 'generate correct todo list' '
label onto
reset onto
- pick $b B
+ pick $b # B
label first
reset onto
- pick $c C
+ pick $c # C
label branch-point
- pick $f F
- pick $g G
+ pick $f # F
+ pick $g # G
label second
reset branch-point # C
- pick $d D
+ pick $d # D
merge -C $e first # E
merge -C $h second # H
@@ -610,4 +619,24 @@ test_expect_success 'truncate label names' '
grep "label 0123456789-$" out
'
+test_expect_success 'reword fast-forwarded empty merge commit' '
+ oid="$(git commit-tree -m "D1" -p A D^{tree})" &&
+ oid="$(git commit-tree -m "empty merge" -p D -p $oid D^{tree})" &&
+
+ write_script sequence-editor.sh <<-\EOF &&
+ sed /^merge/s/-C/-c/ "$1" >"$1.tmp"
+ mv "$1.tmp" "$1"
+ EOF
+
+ (
+ test_set_sequence_editor "$(pwd)/sequence-editor.sh" &&
+ GIT_EDITOR="echo edited >>" git rebase -i -r D $oid
+ ) &&
+ test_commit_message HEAD <<-\EOF
+ empty merge
+
+ edited
+ EOF
+'
+
test_done
diff --git a/t/t3512-cherry-pick-submodule.sh b/t/t3512-cherry-pick-submodule.sh
index f22d1ddead..85a7932697 100755
--- a/t/t3512-cherry-pick-submodule.sh
+++ b/t/t3512-cherry-pick-submodule.sh
@@ -8,11 +8,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh
-if test "$GIT_TEST_MERGE_ALGORITHM" != ort
-then
- KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
- KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
-fi
test_submodule_switch "cherry-pick"
test_expect_success 'unrelated submodule/file conflict is ignored' '
diff --git a/t/t3513-revert-submodule.sh b/t/t3513-revert-submodule.sh
index 8bfe3ed246..32e15c72ee 100755
--- a/t/t3513-revert-submodule.sh
+++ b/t/t3513-revert-submodule.sh
@@ -30,10 +30,6 @@ git_revert () {
git revert HEAD
}
-if test "$GIT_TEST_MERGE_ALGORITHM" != ort
-then
- KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
-fi
test_submodule_switch_func "git_revert"
test_done
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 98259e2ada..1f16e6b522 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -17,11 +17,6 @@ test_expect_success 'Initialize test directory' '
git commit -m "add normal files"
'
-if test_have_prereq !FUNNYNAMES
-then
- say 'Your filesystem does not allow tabs in filenames.'
-fi
-
test_expect_success FUNNYNAMES 'add files with funny names' '
touch -- "tab embedded" "newline${LF}embedded" &&
git add -- "tab embedded" "newline${LF}embedded" &&
diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh
index 389670262e..58b3759935 100755
--- a/t/t3650-replay-basics.sh
+++ b/t/t3650-replay-basics.sh
@@ -195,4 +195,26 @@ test_expect_success 'using replay on bare repo to rebase multiple divergent bran
done
'
+test_expect_success 'merge.directoryRenames=false' '
+ # create a test case that stress-tests the rename caching
+ git switch -c rename-onto &&
+
+ mkdir -p to-rename &&
+ test_commit to-rename/move &&
+
+ mkdir -p renamed-directory &&
+ git mv to-rename/move* renamed-directory/ &&
+ test_tick &&
+ git commit -m renamed-directory &&
+
+ git switch -c rename-from HEAD^ &&
+ test_commit to-rename/add-a-file &&
+ echo modified >to-rename/add-a-file.t &&
+ test_tick &&
+ git commit -m modified to-rename/add-a-file.t &&
+
+ git -c merge.directoryRenames=false replay \
+ --onto rename-onto rename-onto..rename-from
+'
+
test_done
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index b8a05d95f3..04d2a19835 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -63,7 +63,7 @@ test_expect_success 'setup (initial)' '
'
test_expect_success 'status works (initial)' '
git add -i </dev/null >output &&
- grep "+1/-0 *+2/-0 file" output
+ test_grep "+1/-0 *+2/-0 file" output
'
test_expect_success 'setup expected' '
@@ -86,7 +86,7 @@ test_expect_success 'revert works (initial)' '
git add file &&
test_write_lines r 1 | git add -i &&
git ls-files >output &&
- ! grep . output
+ test_grep ! . output
'
test_expect_success 'add untracked (multiple)' '
@@ -109,7 +109,7 @@ test_expect_success 'setup (commit)' '
'
test_expect_success 'status works (commit)' '
git add -i </dev/null >output &&
- grep "+1/-0 *+2/-0 file" output
+ test_grep "+1/-0 *+2/-0 file" output
'
test_expect_success 'update can stage deletions' '
@@ -141,7 +141,7 @@ test_expect_success 'revert works (commit)' '
git add file &&
test_write_lines r 1 | git add -i &&
git add -i </dev/null >output &&
- grep "unchanged *+3/-0 file" output
+ test_grep "unchanged *+3/-0 file" output
'
test_expect_success 'reject multi-key input' '
@@ -185,7 +185,7 @@ test_expect_success 'setup fake editor' '
test_expect_success 'bad edit rejected' '
git reset &&
test_write_lines e n d | git add -p >output &&
- grep "hunk does not apply" output
+ test_grep "hunk does not apply" output
'
test_expect_success 'setup patch' '
@@ -198,7 +198,7 @@ test_expect_success 'setup patch' '
test_expect_success 'garbage edit rejected' '
git reset &&
test_write_lines e n d | git add -p >output &&
- grep "hunk does not apply" output
+ test_grep "hunk does not apply" output
'
test_expect_success 'setup patch' '
@@ -313,8 +313,8 @@ test_expect_success FILEMODE 'stage mode and hunk' '
chmod +x file &&
printf "y\\ny\\n" | git add -p &&
git diff --cached file >out &&
- grep "new mode" out &&
- grep "+content" out &&
+ test_grep "new mode" out &&
+ test_grep "+content" out &&
git diff file >out &&
test_must_be_empty out
'
@@ -636,7 +636,7 @@ test_expect_success 'split hunk "add -p (edit)"' '
printf "%s\n" s e q n q q |
EDITOR=: git add -p &&
git diff >actual &&
- ! grep "^+15" actual
+ test_grep ! "^+15" actual
'
test_expect_success 'split hunk "add -p (no, yes, edit)"' '
@@ -648,7 +648,7 @@ test_expect_success 'split hunk "add -p (no, yes, edit)"' '
EDITOR=: git add -p 2>error &&
test_must_be_empty error &&
git diff >actual &&
- ! grep "^+31" actual
+ test_grep ! "^+31" actual
'
test_expect_success 'split hunk with incomplete line at end' '
@@ -682,7 +682,7 @@ test_expect_success 'edit, adding lines to the first hunk' '
EDITOR=./fake_editor.sh git add -p 2>error &&
test_must_be_empty error &&
git diff --cached >actual &&
- grep "^+22" actual
+ test_grep "^+22" actual
'
test_expect_success 'patch mode ignores unmerged entries' '
@@ -696,7 +696,7 @@ test_expect_success 'patch mode ignores unmerged entries' '
test_must_fail git merge side &&
echo changed >non-conflict.t &&
echo y | git add -p >output &&
- ! grep a/conflict.t output &&
+ test_grep ! a/conflict.t output &&
cat >expected <<-\EOF &&
* Unmerged path conflict.t
diff --git a/non-conflict.t b/non-conflict.t
@@ -728,7 +728,7 @@ test_expect_success 'diffs can be colorized' '
# We do not want to depend on the exact coloring scheme
# git uses for diffs, so just check that we saw some kind of color.
- grep "$(printf "\\033")" output
+ test_grep "$(printf "\\033")" output
'
test_expect_success 'colors can be overridden' '
@@ -743,7 +743,7 @@ test_expect_success 'colors can be overridden' '
-c color.interactive.error=blue \
add -i 2>err.raw <input &&
test_decode_color <err.raw >err &&
- grep "<BLUE>Huh (trigger)?<RESET>" err &&
+ test_grep "<BLUE>Huh (trigger)?<RESET>" err &&
test_write_lines help quit >input &&
force_color git \
@@ -863,7 +863,7 @@ test_expect_success 'colorized diffs respect diff.wsErrorHighlight' '
printf y >y &&
force_color git -c diff.wsErrorHighlight=all add -p >output.raw 2>&1 <y &&
test_decode_color <output.raw >output &&
- grep "old<" output
+ test_grep "old<" output
'
test_expect_success 'diffFilter filters diff' '
@@ -876,7 +876,7 @@ test_expect_success 'diffFilter filters diff' '
# avoid depending on the exact coloring or content of the prompts,
# and just make sure we saw our diff prefixed
- grep foo:.*content output
+ test_grep foo:.*content output
'
test_expect_success 'detect bogus diffFilter output' '
@@ -886,7 +886,7 @@ test_expect_success 'detect bogus diffFilter output' '
test_config interactive.diffFilter "sed 6d" &&
printf y >y &&
force_color test_must_fail git add -p <y >output 2>&1 &&
- grep "mismatched output" output
+ test_grep "mismatched output" output
'
test_expect_success 'handle iffy colored hunk headers' '
@@ -896,7 +896,7 @@ test_expect_success 'handle iffy colored hunk headers' '
printf n >n &&
force_color git -c interactive.diffFilter="sed s/.*@@.*/XX/" \
add -p >output 2>&1 <n &&
- grep "^XX$" output
+ test_grep "^XX$" output
'
test_expect_success 'handle very large filtered diff' '
@@ -1002,7 +1002,7 @@ test_expect_success 'add -p does not expand argument lists' '
# update it, but we want to be sure that our "." pathspec
# was not expanded into the argument list of any command.
# So look only for "not-changed".
- ! grep -E "^trace: (built-in|exec|run_command): .*not-changed" trace.out
+ test_grep ! -E "^trace: (built-in|exec|run_command): .*not-changed" trace.out
'
test_expect_success 'hunk-editing handles custom comment char' '
@@ -1072,21 +1072,21 @@ test_expect_success 'setup different kinds of dirty submodules' '
test_expect_success 'status ignores dirty submodules (except HEAD)' '
git -C for-submodules add -i </dev/null >output &&
- grep dirty-head output &&
- grep dirty-both-ways output &&
- ! grep dirty-otherwise output
+ test_grep dirty-head output &&
+ test_grep dirty-both-ways output &&
+ test_grep ! dirty-otherwise output
'
test_expect_success 'handle submodules' '
echo 123 >>for-submodules/dirty-otherwise/initial.t &&
force_color git -C for-submodules add -p dirty-otherwise >output 2>&1 &&
- grep "No changes" output &&
+ test_grep "No changes" output &&
force_color git -C for-submodules add -p dirty-head >output 2>&1 <y &&
git -C for-submodules ls-files --stage dirty-head >actual &&
rev="$(git -C for-submodules/dirty-head rev-parse HEAD)" &&
- grep "$rev" actual
+ test_grep "$rev" actual
'
test_expect_success 'set up pathological context' '
@@ -1230,4 +1230,75 @@ test_expect_success 'hunk splitting works with diff.suppressBlankEmpty' '
test_cmp expect actual
'
+test_expect_success 'add -p respects diff.context' '
+ test_write_lines a b c d e f g h i j k l m >file &&
+ git add file &&
+ test_write_lines a b c d e f G h i j k l m >file &&
+ echo y | git -c diff.context=5 add -p >actual &&
+ test_grep "@@ -2,11 +2,11 @@" actual
+'
+
+test_expect_success 'add -p respects diff.interHunkContext' '
+ test_write_lines a b c d e f g h i j k l m n o p q r s >file &&
+ git add file &&
+ test_write_lines a b c d E f g i i j k l m N o p q r s >file &&
+ echo y | git -c diff.interhunkcontext=2 add -p >actual &&
+ test_grep "@@ -2,16 +2,16 @@" actual
+'
+
+test_expect_success 'add -p rejects negative diff.context' '
+ test_config diff.context -1 &&
+ test_must_fail git add -p 2>output &&
+ test_grep "diff.context cannot be negative" output
+'
+
+for cmd in add checkout restore 'commit -m file'
+do
+ test_expect_success "${cmd%% *} accepts -U and --inter-hunk-context" '
+ test_write_lines a b c d e f g h i j k l m n o p q r s t u v >file &&
+ git add file &&
+ test_write_lines a b c d e F g h i j k l m n o p Q r s t u v >file &&
+ echo y | git -c diff.context=5 -c diff.interhunkcontext=1 \
+ $cmd -p -U 4 --inter-hunk-context 2 >actual &&
+ test_grep "@@ -2,20 +2,20 @@" actual
+ '
+done
+
+test_expect_success 'reset accepts -U and --inter-hunk-context' '
+ test_write_lines a b c d e f g h i j k l m n o p q r s t u v >file &&
+ git commit -m file file &&
+ test_write_lines a b c d e F g h i j k l m n o p Q r s t u v >file &&
+ git add file &&
+ echo y | git -c diff.context=5 -c diff.interhunkcontext=1 \
+ reset -p -U 4 --inter-hunk-context 2 >actual &&
+ test_grep "@@ -2,20 +2,20 @@" actual
+'
+
+test_expect_success 'stash accepts -U and --inter-hunk-context' '
+ test_write_lines a b c d e F g h i j k l m n o p Q r s t u v >file &&
+ git commit -m file file &&
+ test_write_lines a b c d e f g h i j k l m n o p q r s t u v >file &&
+ echo y | git -c diff.context=5 -c diff.interhunkcontext=1 \
+ stash -p -U 4 --inter-hunk-context 2 >actual &&
+ test_grep "@@ -2,20 +2,20 @@" actual
+'
+
+for cmd in add checkout commit reset restore "stash save" "stash push"
+do
+ test_expect_success "$cmd rejects invalid context options" '
+ test_must_fail git $cmd -p -U -3 2>actual &&
+ cat actual | echo &&
+ test_grep -e ".--unified. cannot be negative" actual &&
+
+ test_must_fail git $cmd -p --inter-hunk-context -3 2>actual &&
+ test_grep -e ".--inter-hunk-context. cannot be negative" actual &&
+
+ test_must_fail git $cmd -U 7 2>actual &&
+ test_grep -E ".--unified. requires .(--interactive/)?--patch." actual &&
+
+ test_must_fail git $cmd --inter-hunk-context 2 2>actual &&
+ test_grep -E ".--inter-hunk-context. requires .(--interactive/)?--patch." actual
+ '
+done
+
test_done
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 74666ff3e4..0bb4648e36 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -11,6 +11,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-unique-files.sh
+test_expect_success 'setup' '
+ test_oid_cache <<-EOF
+ export_base sha1:73c9bab443d1f88ac61aa533d2eeaaa15451239c
+ export_base sha256:f210fa6346e3e2ce047bdb570426b17075980c1ac01fec8fc4b75bd3ab4bcfe4
+ EOF
+'
+
test_expect_success 'usage on cmd and subcommand invalid option' '
test_expect_code 129 git stash --invalid-option 2>usage &&
grep "or: git stash" usage &&
@@ -1177,6 +1184,28 @@ test_expect_success 'stash -- <pathspec> stashes and restores the file' '
test_path_is_file bar
'
+test_expect_success 'stash --patch <pathspec> stash and restores the file' '
+ test_write_lines b c >file &&
+ git commit -m "add a few lines" file &&
+ test_write_lines a b c d >file &&
+ test_write_lines b c d >expect-file &&
+ echo changed-other-file >other-file &&
+ test_write_lines s y n | git stash -m "stash bar" --patch file &&
+ test_cmp expect-file file &&
+ echo changed-other-file >expect &&
+ test_cmp expect other-file &&
+ git checkout HEAD -- file &&
+ git stash pop &&
+ test_cmp expect other-file &&
+ test_write_lines a b c >expect &&
+ test_cmp expect file
+'
+
+test_expect_success 'stash <pathspec> -p is rejected' '
+ test_must_fail git stash file -p 2>err &&
+ test_grep "subcommand wasn${SQ}t specified; ${SQ}push${SQ} can${SQ}t be assumed due to unexpected token ${SQ}file${SQ}" err
+'
+
test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
mkdir sub &&
>foo &&
@@ -1412,6 +1441,100 @@ test_expect_success 'stash --keep-index --include-untracked with empty tree' '
)
'
+test_expect_success 'stash export and import round-trip stashes' '
+ git reset &&
+ >untracked &&
+ >tracked1 &&
+ >tracked2 &&
+ git add tracked* &&
+ git stash -- &&
+ >subdir/untracked &&
+ >subdir/tracked1 &&
+ >subdir/tracked2 &&
+ git add subdir/tracked* &&
+ git stash --include-untracked -- subdir/ &&
+ git tag t-stash0 stash@{0} &&
+ git tag t-stash1 stash@{1} &&
+ simple=$(git stash export --print) &&
+ git stash clear &&
+ git stash import "$simple" &&
+ test_cmp_rev stash@{0} t-stash0 &&
+ test_cmp_rev stash@{1} t-stash1 &&
+ git stash export --to-ref refs/heads/foo &&
+ test_cmp_rev "$(test_oid empty_tree)" foo: &&
+ test_cmp_rev "$(test_oid empty_tree)" foo^: &&
+ test_cmp_rev t-stash0 foo^2 &&
+ test_cmp_rev t-stash1 foo^^2 &&
+ git log --first-parent --format="%s" refs/heads/foo >log &&
+ grep "^git stash: " log >log2 &&
+ test_line_count = 13 log2 &&
+ git stash clear &&
+ git stash import foo &&
+ test_cmp_rev stash@{0} t-stash0 &&
+ test_cmp_rev stash@{1} t-stash1
+'
+
+test_expect_success 'stash import appends commits' '
+ git log --format=oneline -g refs/stash >out &&
+ cat out out >out2 &&
+ git stash import refs/heads/foo &&
+ git log --format=oneline -g refs/stash >actual &&
+ test_line_count = $(wc -l <out2) actual
+'
+
+test_expect_success 'stash export can accept specified stashes' '
+ git stash clear &&
+ git stash import foo &&
+ git stash export --to-ref refs/heads/bar stash@{1} stash@{0} &&
+ git stash clear &&
+ git stash import refs/heads/bar &&
+ test_cmp_rev stash@{1} t-stash0 &&
+ test_cmp_rev stash@{0} t-stash1 &&
+ git log --format=oneline -g refs/stash >actual &&
+ test_line_count = 2 actual
+'
+
+test_expect_success 'stash export rejects invalid arguments' '
+ test_must_fail git stash export --print --to-ref refs/heads/invalid 2>err &&
+ grep "exactly one of --print and --to-ref is required" err &&
+ test_must_fail git stash export 2>err2 &&
+ grep "exactly one of --print and --to-ref is required" err2
+'
+
+test_expect_success 'stash can import and export zero stashes' '
+ git stash clear &&
+ git stash export --to-ref refs/heads/baz &&
+ test_cmp_rev "$(test_oid empty_tree)" baz: &&
+ test_cmp_rev "$(test_oid export_base)" baz &&
+ test_must_fail git rev-parse baz^1 &&
+ git stash import baz &&
+ test_must_fail git rev-parse refs/stash
+'
+
+test_expect_success 'stash rejects invalid attempts to import commits' '
+ git stash import foo &&
+ test_must_fail git stash import HEAD 2>output &&
+ oid=$(git rev-parse HEAD) &&
+ grep "$oid is not a valid exported stash commit" output &&
+ test_cmp_rev stash@{0} t-stash0 &&
+
+ git checkout --orphan orphan &&
+ git commit-tree $(test_oid empty_tree) -p "$oid" -p "$oid^" -m "" >fake-commit &&
+ git update-ref refs/heads/orphan "$(cat fake-commit)" &&
+ oid=$(git rev-parse HEAD) &&
+ test_must_fail git stash import orphan 2>output &&
+ grep "found stash commit $oid without expected prefix" output &&
+ test_cmp_rev stash@{0} t-stash0 &&
+
+ git checkout --orphan orphan2 &&
+ git commit-tree $(test_oid empty_tree) -m "" >fake-commit &&
+ git update-ref refs/heads/orphan2 "$(cat fake-commit)" &&
+ oid=$(git rev-parse HEAD) &&
+ test_must_fail git stash import orphan2 2>output &&
+ grep "found root commit $oid with invalid data" output &&
+ test_cmp_rev stash@{0} t-stash0
+'
+
test_expect_success 'stash apply should succeed with unmodified file' '
echo base >file &&
git add file &&
@@ -1549,11 +1672,9 @@ test_expect_success 'stash create reports a locked index' '
echo change >A.file &&
touch .git/index.lock &&
- cat >expect <<-EOF &&
- error: could not write index
- EOF
test_must_fail git stash create 2>err &&
- test_cmp expect err
+ test_grep "error: could not write index" err &&
+ test_grep "error: Unable to create '.*index.lock'" err
)
'
@@ -1566,11 +1687,9 @@ test_expect_success 'stash push reports a locked index' '
echo change >A.file &&
touch .git/index.lock &&
- cat >expect <<-EOF &&
- error: could not write index
- EOF
test_must_fail git stash push 2>err &&
- test_cmp expect err
+ test_grep "error: could not write index" err &&
+ test_grep "error: Unable to create '.*index.lock'" err
)
'
@@ -1584,11 +1703,41 @@ test_expect_success 'stash apply reports a locked index' '
git stash push &&
touch .git/index.lock &&
- cat >expect <<-EOF &&
- error: could not write index
- EOF
test_must_fail git stash apply 2>err &&
- test_cmp expect err
+ test_grep "error: could not write index" err &&
+ test_grep "error: Unable to create '.*index.lock'" err
+ )
+'
+
+test_expect_success 'submodules does not affect the branch recorded in stash message' '
+ git init sub_project &&
+ (
+ cd sub_project &&
+ echo "Initial content in sub_project" >sub_file.txt &&
+ git add sub_file.txt &&
+ git commit -m "Initial commit in sub_project"
+ ) &&
+
+ git init main_project &&
+ (
+ cd main_project &&
+ echo "Initial content in main_project" >main_file.txt &&
+ git add main_file.txt &&
+ git commit -m "Initial commit in main_project" &&
+
+ git -c protocol.file.allow=always submodule add ../sub_project sub &&
+ git commit -m "Added submodule sub_project" &&
+
+ git checkout -b feature_main &&
+ git -C sub checkout -b feature_sub &&
+
+ git checkout -b work_branch &&
+ echo "Important work to be stashed" >work_item.txt &&
+ git add work_item.txt &&
+ git stash push -m "custom stash for work_branch" &&
+
+ git stash list >../actual_stash_list.txt &&
+ grep "On work_branch: custom stash for work_branch" ../actual_stash_list.txt
)
'
diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh
index a51f881b1c..32b14e3a71 100755
--- a/t/t4000-diff-format.sh
+++ b/t/t4000-diff-format.sh
@@ -36,7 +36,7 @@ test_expect_success 'git diff-files -p after editing work tree.' '
# that's as far as it comes
if [ "$(git config --get core.filemode)" = false ]
then
- say 'filemode disabled on the filesystem'
+ skip_all='filemode disabled on the filesystem'
test_done
fi
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 3855d68dbc..cfeec239e0 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -11,6 +11,12 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping diff various tests; Perl not available'
+ test_done
+fi
+
test_expect_success setup '
GIT_AUTHOR_DATE="2006-06-26 00:00:00 +0000" &&
@@ -200,14 +206,30 @@ do
expect="$TEST_DIRECTORY/t4013/diff.$test"
actual="$pfx-diff.$test"
- test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
+ case "$cmd" in
+ whatchanged | whatchanged" "*)
+ prereq=!WITH_BREAKING_CHANGES
+ ;;
+ *)
+ prereq=;;
+ esac
+
+ test_expect_success $prereq "git $cmd # magic is ${magic:-(not used)}" '
{
echo "$ git $cmd"
+
+ case "$cmd" in
+ whatchanged | whatchanged" "*)
+ run="whatchanged --i-still-use-this"
+ run="$run ${cmd#whatchanged}" ;;
+ *)
+ run=$cmd ;;
+ esac &&
case "$magic" in
"")
- GIT_PRINT_SHA1_ELLIPSIS=yes git $cmd ;;
+ GIT_PRINT_SHA1_ELLIPSIS=yes git $run ;;
noellipses)
- git $cmd ;;
+ git $run ;;
esac |
sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
-e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
@@ -454,6 +476,11 @@ diff-tree --stat --compact-summary initial mode
diff-tree -R --stat --compact-summary initial mode
EOF
+test_expect_success !WITH_BREAKING_CHANGES 'whatchanged needs --i-still-use-this' '
+ test_must_fail git whatchanged >message 2>&1 &&
+ test_grep "nominated for removal" message
+'
+
test_expect_success 'log -m matches pure log' '
git log master >result &&
process_diffs result >expected &&
@@ -621,6 +648,19 @@ test_expect_success 'diff -I<regex>: detect malformed regex' '
test_grep "invalid regex given to -I: " error
'
+test_expect_success 'diff -I<regex>: ignore matching file' '
+ test_when_finished "git rm -f file1" &&
+ test_seq 50 >file1 &&
+ git add file1 &&
+ test_seq 50 | sed -e "s/13/ten and three/" -e "s/^[124-9].*/& /" >file1 &&
+
+ : >actual &&
+ git diff --raw --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual &&
+ git diff --name-only --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual &&
+ git diff --name-status --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >>actual &&
+ test_grep ! "file1" actual
+'
+
# check_prefix <patch> <src> <dst>
# check only lines with paths to avoid dependency on exact oid/contents
check_prefix () {
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 884f83fb8a..2782b1fc18 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -448,7 +448,7 @@ cat >>expect.no-threading <<EOF
---
EOF
-test_expect_success 'no threading' '
+test_expect_success PERL_TEST_HELPERS 'no threading' '
git checkout side &&
check_threading expect.no-threading main
'
@@ -466,11 +466,11 @@ In-Reply-To: <0>
References: <0>
EOF
-test_expect_success 'thread' '
+test_expect_success PERL_TEST_HELPERS 'thread' '
check_threading expect.thread --thread main
'
-test_expect_success '--thread overrides format.thread=deep' '
+test_expect_success PERL_TEST_HELPERS '--thread overrides format.thread=deep' '
test_config format.thread deep &&
check_threading expect.thread --thread main
'
@@ -490,7 +490,7 @@ In-Reply-To: <1>
References: <1>
EOF
-test_expect_success 'thread in-reply-to' '
+test_expect_success PERL_TEST_HELPERS 'thread in-reply-to' '
check_threading expect.in-reply-to --in-reply-to="<test.message>" \
--thread main
'
@@ -512,7 +512,7 @@ In-Reply-To: <0>
References: <0>
EOF
-test_expect_success 'thread cover-letter' '
+test_expect_success PERL_TEST_HELPERS 'thread cover-letter' '
check_threading expect.cover-letter --cover-letter --thread main
'
@@ -538,12 +538,12 @@ References: <1>
<0>
EOF
-test_expect_success 'thread cover-letter in-reply-to' '
+test_expect_success PERL_TEST_HELPERS 'thread cover-letter in-reply-to' '
check_threading expect.cl-irt --cover-letter \
--in-reply-to="<test.message>" --thread main
'
-test_expect_success 'thread explicit shallow' '
+test_expect_success PERL_TEST_HELPERS 'thread explicit shallow' '
check_threading expect.cl-irt --cover-letter \
--in-reply-to="<test.message>" --thread=shallow main
'
@@ -562,7 +562,7 @@ References: <0>
<1>
EOF
-test_expect_success 'thread deep' '
+test_expect_success PERL_TEST_HELPERS 'thread deep' '
check_threading expect.deep --thread=deep main
'
@@ -584,7 +584,7 @@ References: <1>
<2>
EOF
-test_expect_success 'thread deep in-reply-to' '
+test_expect_success PERL_TEST_HELPERS 'thread deep in-reply-to' '
check_threading expect.deep-irt --thread=deep \
--in-reply-to="<test.message>" main
'
@@ -609,7 +609,7 @@ References: <0>
<2>
EOF
-test_expect_success 'thread deep cover-letter' '
+test_expect_success PERL_TEST_HELPERS 'thread deep cover-letter' '
check_threading expect.deep-cl --cover-letter --thread=deep main
'
@@ -638,27 +638,27 @@ References: <1>
<3>
EOF
-test_expect_success 'thread deep cover-letter in-reply-to' '
+test_expect_success PERL_TEST_HELPERS 'thread deep cover-letter in-reply-to' '
check_threading expect.deep-cl-irt --cover-letter \
--in-reply-to="<test.message>" --thread=deep main
'
-test_expect_success 'thread via config' '
+test_expect_success PERL_TEST_HELPERS 'thread via config' '
test_config format.thread true &&
check_threading expect.thread main
'
-test_expect_success 'thread deep via config' '
+test_expect_success PERL_TEST_HELPERS 'thread deep via config' '
test_config format.thread deep &&
check_threading expect.deep main
'
-test_expect_success 'thread config + override' '
+test_expect_success PERL_TEST_HELPERS 'thread config + override' '
test_config format.thread deep &&
check_threading expect.thread --thread main
'
-test_expect_success 'thread config + --no-thread' '
+test_expect_success PERL_TEST_HELPERS 'thread config + --no-thread' '
test_config format.thread deep &&
check_threading expect.no-threading --no-thread main
'
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 52e3e476ff..9de7f73f42 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -11,12 +11,8 @@ test_description='Test special whitespace in diff engine.
. "$TEST_DIRECTORY"/lib-diff.sh
for opt_res in --patch --quiet -s --stat --shortstat --dirstat=lines \
- --raw! --name-only! --name-status!
+ --raw --name-only --name-status
do
- opts=${opt_res%!} expect_failure=
- test "$opts" = "$opt_res" ||
- expect_failure="test_expect_code 1"
-
test_expect_success "status with $opts (different)" '
echo foo >x &&
git add x &&
@@ -43,7 +39,7 @@ do
echo foo >x &&
git add x &&
echo " foo" >x &&
- $expect_failure git diff -w $opts --exit-code x
+ git diff -w $opts --exit-code x
'
done
diff --git a/t/t4018/bash-bashism-style-complete-line-capture b/t/t4018/bash-bashism-style-complete-line-capture
new file mode 100644
index 0000000000..070b979fa6
--- /dev/null
+++ b/t/t4018/bash-bashism-style-complete-line-capture
@@ -0,0 +1,4 @@
+function myfunc # RIGHT
+{
+ echo 'ChangeMe'
+}
diff --git a/t/t4018/bash-posix-style-complete-line-capture b/t/t4018/bash-posix-style-complete-line-capture
new file mode 100644
index 0000000000..b56942f322
--- /dev/null
+++ b/t/t4018/bash-posix-style-complete-line-capture
@@ -0,0 +1,4 @@
+func() { # RIGHT
+
+ ChangeMe
+}
diff --git a/t/t4018/bash-posix-style-single-command-function b/t/t4018/bash-posix-style-single-command-function
new file mode 100644
index 0000000000..398ae1c5d2
--- /dev/null
+++ b/t/t4018/bash-posix-style-single-command-function
@@ -0,0 +1,3 @@
+RIGHT() echo "hello"
+
+ ChangeMe
diff --git a/t/t4018/ini-section b/t/t4018/ini-section
new file mode 100644
index 0000000000..c895ad9b4f
--- /dev/null
+++ b/t/t4018/ini-section
@@ -0,0 +1,5 @@
+[RIGHT]
+ # comment
+ ; comment
+ name = value
+ ChangeMe
diff --git a/t/t4018/ini-section-noindent b/t/t4018/ini-section-noindent
new file mode 100644
index 0000000000..733d23c801
--- /dev/null
+++ b/t/t4018/ini-section-noindent
@@ -0,0 +1,5 @@
+[RIGHT]
+# comment
+; comment
+name = value
+ChangeMe
diff --git a/t/t4018/ini-section-same-line b/t/t4018/ini-section-same-line
new file mode 100644
index 0000000000..522a1fa4a1
--- /dev/null
+++ b/t/t4018/ini-section-same-line
@@ -0,0 +1,4 @@
+[RIGHT] name = value
+ # comment
+ ; comment
+ ChangeMe
diff --git a/t/t4018/ini-subsection b/t/t4018/ini-subsection
new file mode 100644
index 0000000000..3d47349e60
--- /dev/null
+++ b/t/t4018/ini-subsection
@@ -0,0 +1,12 @@
+[LEFT]
+
+ [LEFT "CENTER"]
+ # comment
+ ; comment
+ name = value
+
+ [LEFT "RIGHT"]
+ # comment
+ ; comment
+ name = value
+ ChangeMe
diff --git a/t/t4018/ini-subsection-noindent b/t/t4018/ini-subsection-noindent
new file mode 100644
index 0000000000..698ea00ea3
--- /dev/null
+++ b/t/t4018/ini-subsection-noindent
@@ -0,0 +1,12 @@
+[LEFT]
+
+[LEFT "CENTER"]
+# comment
+; comment
+name = value
+
+[LEFT "RIGHT"]
+# comment
+; comment
+name = value
+ChangeMe
diff --git a/t/t4018/r-indent b/t/t4018/r-indent
new file mode 100644
index 0000000000..9df440f2a4
--- /dev/null
+++ b/t/t4018/r-indent
@@ -0,0 +1,6 @@
+RIGHT <- function(a, b) {
+ c = mean(a, b)
+ d = c + 2
+ ChangeMe()
+ return (d)
+}
diff --git a/t/t4018/r-indent-nested b/t/t4018/r-indent-nested
new file mode 100644
index 0000000000..30412e6c79
--- /dev/null
+++ b/t/t4018/r-indent-nested
@@ -0,0 +1,10 @@
+LEFT = function(a, b) {
+ c = mean(a, b)
+ RIGHT = function(d, e) {
+ f = var(d, e)
+ g = f + 1
+ ChangeMe()
+ return (g)
+ }
+ return (RIGHT(2, 3))
+}
diff --git a/t/t4018/r-noindent b/t/t4018/r-noindent
new file mode 100644
index 0000000000..6d9b01ffe3
--- /dev/null
+++ b/t/t4018/r-noindent
@@ -0,0 +1,6 @@
+RIGHT <- function(a, b) {
+c = mean(a, b)
+d = c + 2
+ChangeMe()
+return (c)
+}
diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh
index f1efe482a5..c8a23d5148 100755
--- a/t/t4020-diff-external.sh
+++ b/t/t4020-diff-external.sh
@@ -237,7 +237,7 @@ check_external_diff 0 empty empty 0 on --quiet
check_external_diff 1 empty empty 1 on --quiet
check_external_diff 128 empty error 2 on --quiet
-echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
+echo NULZbetweenZwords | tr "Z" "\000" > file
test_expect_success 'force diff with "diff"' '
after=$(git hash-object file) &&
diff --git a/t/t4029-diff-trailing-space.sh b/t/t4029-diff-trailing-space.sh
index 32b6e9a4e7..90cdde88d8 100755
--- a/t/t4029-diff-trailing-space.sh
+++ b/t/t4029-diff-trailing-space.sh
@@ -31,7 +31,8 @@ test_expect_success "$test_description" '
git config --bool diff.suppressBlankEmpty true &&
git diff f > actual &&
test_cmp exp actual &&
- perl -i.bak -p -e "s/^\$/ /" exp &&
+ sed "s/^\$/ /" exp >exp.munged &&
+ mv exp.munged exp &&
git config --bool diff.suppressBlankEmpty false &&
git diff f > actual &&
test_cmp exp actual &&
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index daebf9796f..f904fc19f6 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -20,13 +20,10 @@ cat >expect.text <<'EOF'
+1
EOF
-cat >hexdump <<'EOF'
-#!/bin/sh
-"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
-EOF
-chmod +x hexdump
-
test_expect_success 'setup binary file with history' '
+ write_script hexdump <<-\EOF &&
+ tr "\000\001" "01" <"$1"
+ EOF
test_commit --printf one file "\\0\\n" &&
test_commit --printf --append two file "\\01\\n"
'
diff --git a/t/t4031-diff-rewrite-binary.sh b/t/t4031-diff-rewrite-binary.sh
index c4394a27b5..15e012ccc7 100755
--- a/t/t4031-diff-rewrite-binary.sh
+++ b/t/t4031-diff-rewrite-binary.sh
@@ -57,24 +57,19 @@ test_expect_success 'diff --stat counts binary rewrite as 0 lines' '
grep " rewrite file" diff
'
-{
- echo "#!$SHELL_PATH"
- cat <<'EOF'
-"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
-EOF
-} >dump
-chmod +x dump
-
test_expect_success 'setup textconv' '
+ write_script dump <<-\EOF &&
+ test-tool hexdump <"$1"
+ EOF
echo file diff=foo >.gitattributes &&
git config diff.foo.textconv "\"$(pwd)\""/dump
'
test_expect_success 'rewrite diff respects textconv' '
git diff -B >diff &&
- grep "dissimilarity index" diff &&
- grep "^-61" diff &&
- grep "^-0" diff
+ test_grep "dissimilarity index" diff &&
+ test_grep "^-3d 0a 00" diff &&
+ test_grep "^+3d 0a 01" diff
'
test_done
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index f51d3557f1..0be647c2fb 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -320,6 +320,7 @@ test_expect_success 'unset default driver' '
test_language_driver ada
test_language_driver bibtex
+test_language_driver bash
test_language_driver cpp
test_language_driver csharp
test_language_driver css
diff --git a/t/t4034/bash/expect b/t/t4034/bash/expect
new file mode 100644
index 0000000000..1864ab25dc
--- /dev/null
+++ b/t/t4034/bash/expect
@@ -0,0 +1,36 @@
+<BOLD>diff --git a/pre b/post<RESET>
+<BOLD>index 09ac008..60ba6a2 100644<RESET>
+<BOLD>--- a/pre<RESET>
+<BOLD>+++ b/post<RESET>
+<CYAN>@@ -1,31 +1,31 @@<RESET>
+<RED>my_var<RESET><GREEN>new_var<RESET>=10
+x=<RED>123<RESET><GREEN>456<RESET>
+echo <RED>$1<RESET><GREEN>$2<RESET>
+echo <RED>$USER<RESET><GREEN>$USERNAME<RESET>
+${<RED>HOME<RESET><GREEN>HOMEDIR<RESET>}
+((a<RED>+<RESET><GREEN>+=<RESET>b))
+((a<RED>*<RESET><GREEN>*=<RESET>b))
+((a<RED>/<RESET><GREEN>/=<RESET>b))
+((a<RED>%<RESET><GREEN>%=<RESET>b))
+((a<RED>|<RESET><GREEN>|=<RESET>b))
+((a<RED>^<RESET><GREEN>^=<RESET>b))
+((a<RED>=<RESET><GREEN>==<RESET>b))
+((a<RED>!<RESET><GREEN>!=<RESET>b))
+((a<RED><<RESET><GREEN><=<RESET>b))
+((a<RED>><RESET><GREEN>>=<RESET>b))
+$((a<RED><<RESET><GREEN><<<RESET>b))
+$((a<RED>><RESET><GREEN>>><RESET>b))
+$((a<RED>&<RESET><GREEN>&&<RESET>b))
+$((a<RED>|<RESET><GREEN>||<RESET>b))
+${a<RED>:<RESET><GREEN>:-<RESET>b}
+${a<RED>:<RESET><GREEN>:=<RESET>b}
+${a<RED>:<RESET><GREEN>:+<RESET>b}
+${a<RED>:<RESET><GREEN>:?<RESET>b}
+${a<RED>#<RESET><GREEN>##<RESET>*/}
+${a<RED>%<RESET><GREEN>%%<RESET>.*}
+${a<RED>^<RESET><GREEN>^^<RESET>}
+${a<RED>,<RESET><GREEN>,,<RESET>}
+${<GREEN>!<RESET>a}
+${a[<RED>*<RESET><GREEN>@<RESET>]}
+ls <RED>-a<RESET><GREEN>-x<RESET>
+ls <RED>--all<RESET><GREEN>--color<RESET>
diff --git a/t/t4034/bash/post b/t/t4034/bash/post
new file mode 100644
index 0000000000..2bbee8936d
--- /dev/null
+++ b/t/t4034/bash/post
@@ -0,0 +1,31 @@
+new_var=10
+x=456
+echo $2
+echo $USERNAME
+${HOMEDIR}
+((a+=b))
+((a*=b))
+((a/=b))
+((a%=b))
+((a|=b))
+((a^=b))
+((a==b))
+((a!=b))
+((a<=b))
+((a>=b))
+$((a<<b))
+$((a>>b))
+$((a&&b))
+$((a||b))
+${a:-b}
+${a:=b}
+${a:+b}
+${a:?b}
+${a##*/}
+${a%%.*}
+${a^^}
+${a,,}
+${!a}
+${a[@]}
+ls -x
+ls --color
diff --git a/t/t4034/bash/pre b/t/t4034/bash/pre
new file mode 100644
index 0000000000..8d22039c40
--- /dev/null
+++ b/t/t4034/bash/pre
@@ -0,0 +1,31 @@
+my_var=10
+x=123
+echo $1
+echo $USER
+${HOME}
+((a+b))
+((a*b))
+((a/b))
+((a%b))
+((a|b))
+((a^b))
+((a=b))
+((a!b))
+((a<b))
+((a>b))
+$((a<b))
+$((a>b))
+$((a&b))
+$((a|b))
+${a:b}
+${a:b}
+${a:b}
+${a:b}
+${a#*/}
+${a%.*}
+${a^}
+${a,}
+${a}
+${a[*]}
+ls -a
+ls --all
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index 28f9d83d4c..4d4aa1650f 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -48,11 +48,12 @@ commit_file () {
git commit "$@" -m "Commit $*" >/dev/null
}
-test_create_repo sm1 &&
-add_file . foo >/dev/null
-
-head1=$(add_file sm1 foo1 foo2)
-fullhead1=$(cd sm1; git rev-parse --verify HEAD)
+test_expect_success 'setup submodule' '
+ git init sm1 &&
+ add_file . foo &&
+ head1=$(add_file sm1 foo1 foo2) &&
+ fullhead1=$(cd sm1 && git rev-parse --verify HEAD)
+'
test_expect_success 'added submodule' '
git add sm1 &&
@@ -235,10 +236,13 @@ test_expect_success 'typechanged submodule(submodule->blob)' '
test_cmp expected actual
'
-rm -f sm1 &&
-test_create_repo sm1 &&
-head6=$(add_file sm1 foo6 foo7)
-fullhead6=$(cd sm1; git rev-parse --verify HEAD)
+test_expect_success 'setup submodule anew' '
+ rm -f sm1 &&
+ git init sm1 &&
+ head6=$(add_file sm1 foo6 foo7) &&
+ fullhead6=$(cd sm1 && git rev-parse --verify HEAD)
+'
+
test_expect_success 'nonexistent commit' '
git diff-index -p --submodule=log HEAD >actual &&
cat >expected <<-EOF &&
diff --git a/t/t4042-diff-textconv-caching.sh b/t/t4042-diff-textconv-caching.sh
index ff0e73531b..31018ceba2 100755
--- a/t/t4042-diff-textconv-caching.sh
+++ b/t/t4042-diff-textconv-caching.sh
@@ -120,6 +120,14 @@ test_expect_success 'log notes cache and still use cache for -p' '
'
test_expect_success 'caching is silently ignored outside repo' '
+ test_oid_cache <<-\EOM &&
+ oid1 sha1:5626abf
+ oid1 sha256:a4ed1f3
+ oid2 sha1:f719efd
+ oid2 sha256:aa9e7dc
+ EOM
+ oid1=$(test_oid --hash=builtin oid1) &&
+ oid2=$(test_oid --hash=builtin oid2) &&
mkdir -p non-repo &&
echo one >non-repo/one &&
echo two >non-repo/two &&
@@ -129,9 +137,9 @@ test_expect_success 'caching is silently ignored outside repo' '
-c diff.test.textconv="tr a-z A-Z <" \
-c diff.test.cachetextconv=true \
diff --no-index one two >actual &&
- cat >expect <<-\EOF &&
+ cat >expect <<-EOF &&
diff --git a/one b/two
- index 5626abf..f719efd 100644
+ index $oid1..$oid2 100644
--- a/one
+++ b/two
@@ -1 +1 @@
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 5e5bad61ca..44b4b13f5d 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -26,6 +26,23 @@ test_expect_success 'git diff --no-index directories' '
test_line_count = 14 cnt
'
+test_expect_success 'git diff --no-index with -' '
+ cat >expect <<-\EOF &&
+ diff --git a/- b/-
+ new file mode 100644
+ --- /dev/null
+ +++ b/-
+ @@ -0,0 +1 @@
+ +frotz
+ EOF
+ (
+ cd a &&
+ echo frotz |
+ test_expect_code 1 git diff --no-index /dev/null - >../actual
+ ) &&
+ test_cmp expect actual
+'
+
test_expect_success 'git diff --no-index relative path outside repo' '
(
cd repo &&
@@ -295,4 +312,79 @@ test_expect_success PIPE,SYMLINKS 'diff --no-index reads from pipes' '
test_cmp expect actual
'
+test_expect_success 'diff --no-index F F rejects pathspecs' '
+ test_must_fail git diff --no-index -- a/1 a/2 a 2>actual.err &&
+ test_grep "usage: git diff --no-index" actual.err
+'
+
+test_expect_success 'diff --no-index D F rejects pathspecs' '
+ test_must_fail git diff --no-index -- a a/2 a 2>actual.err &&
+ test_grep "usage: git diff --no-index" actual.err
+'
+
+test_expect_success 'diff --no-index F D rejects pathspecs' '
+ test_must_fail git diff --no-index -- a/1 b b 2>actual.err &&
+ test_grep "usage: git diff --no-index" actual.err
+'
+
+test_expect_success 'diff --no-index rejects absolute pathspec' '
+ test_must_fail git diff --no-index -- a b $(pwd)/a/1
+'
+
+test_expect_success 'diff --no-index with pathspec' '
+ test_expect_code 1 git diff --name-status --no-index a b 1 >actual &&
+ cat >expect <<-EOF &&
+ D a/1
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'diff --no-index with pathspec no matches' '
+ test_expect_code 0 git diff --name-status --no-index a b missing
+'
+
+test_expect_success 'diff --no-index with negative pathspec' '
+ test_expect_code 1 git diff --name-status --no-index a b ":!2" >actual &&
+ cat >expect <<-EOF &&
+ D a/1
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'setup nested' '
+ mkdir -p c/1/2 &&
+ mkdir -p d/1/2 &&
+ echo 1 >c/1/2/a &&
+ echo 2 >c/1/2/b
+'
+
+test_expect_success 'diff --no-index with pathspec nested negative pathspec' '
+ test_expect_code 0 git diff --no-index c d ":!1"
+'
+
+test_expect_success 'diff --no-index with pathspec nested pathspec' '
+ test_expect_code 1 git diff --name-status --no-index c d 1/2 >actual &&
+ cat >expect <<-EOF &&
+ D c/1/2/a
+ D c/1/2/b
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'diff --no-index with pathspec glob' '
+ test_expect_code 1 git diff --name-status --no-index c d ":(glob)**/a" >actual &&
+ cat >expect <<-EOF &&
+ D c/1/2/a
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'diff --no-index with pathspec glob and exclude' '
+ test_expect_code 1 git diff --name-status --no-index c d ":(glob,exclude)**/a" >actual &&
+ cat >expect <<-EOF &&
+ D c/1/2/b
+ EOF
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t4055-diff-context.sh b/t/t4055-diff-context.sh
index f7ff234cf9..1384a81957 100755
--- a/t/t4055-diff-context.sh
+++ b/t/t4055-diff-context.sh
@@ -38,55 +38,65 @@ test_expect_success 'setup' '
test_expect_success 'the default number of context lines is 3' '
git diff >output &&
- ! grep "^ d" output &&
- grep "^ e" output &&
- grep "^ j" output &&
- ! grep "^ k" output
+ test_grep ! "^ d" output &&
+ test_grep "^ e" output &&
+ test_grep "^ j" output &&
+ test_grep ! "^ k" output
'
test_expect_success 'diff.context honored by "log"' '
git log -1 -p >output &&
- ! grep firstline output &&
- git config diff.context 8 &&
+ test_grep ! firstline output &&
+ test_config diff.context 8 &&
git log -1 -p >output &&
- grep "^ firstline" output
+ test_grep "^ firstline" output
'
test_expect_success 'The -U option overrides diff.context' '
- git config diff.context 8 &&
+ test_config diff.context 8 &&
git log -U4 -1 >output &&
- ! grep "^ firstline" output
+ test_grep ! "^ firstline" output
'
test_expect_success 'diff.context honored by "diff"' '
- git config diff.context 8 &&
+ test_config diff.context 8 &&
git diff >output &&
- grep "^ firstline" output
+ test_grep "^ firstline" output
'
test_expect_success 'plumbing not affected' '
- git config diff.context 8 &&
+ test_config diff.context 8 &&
git diff-files -p >output &&
- ! grep "^ firstline" output
+ test_grep ! "^ firstline" output
'
test_expect_success 'non-integer config parsing' '
- git config diff.context no &&
+ test_config diff.context no &&
test_must_fail git diff 2>output &&
test_grep "bad numeric config value" output
'
test_expect_success 'negative integer config parsing' '
- git config diff.context -1 &&
+ test_config diff.context -1 &&
test_must_fail git diff 2>output &&
test_grep "bad config variable" output
'
test_expect_success '-U0 is valid, so is diff.context=0' '
- git config diff.context 0 &&
+ test_config diff.context 0 &&
git diff >output &&
- grep "^-ADDED" output &&
- grep "^+MODIFIED" output
+ test_grep "^-ADDED" output &&
+ test_grep "^+MODIFIED" output
+'
+
+test_expect_success '-U2147483647 works' '
+ echo APPENDED >>x &&
+ test_line_count = 16 x &&
+ git diff -U2147483647 >output &&
+ test_line_count = 22 output &&
+ test_grep "^-ADDED" output &&
+ test_grep "^+MODIFIED" output &&
+ test_grep "^+APPENDED" output
'
test_done
diff --git a/t/t4058-diff-duplicates.sh b/t/t4058-diff-duplicates.sh
index 2fce4a9897..16266dff2a 100755
--- a/t/t4058-diff-duplicates.sh
+++ b/t/t4058-diff-duplicates.sh
@@ -13,6 +13,12 @@ test_description='test tree diff when trees have duplicate entries'
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping diff duplicates tests; Perl not available'
+ test_done
+fi
+
# make_tree_entry <mode> <mode> <sha1>
#
# We have to rely on perl here because not all printfs understand
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index 76b83101d3..dbfeb7470b 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -363,9 +363,12 @@ test_expect_success 'typechanged submodule(submodule->blob)' '
diff_cmp expected actual
'
-rm -f sm1 &&
-test_create_repo sm1 &&
-head6=$(add_file sm1 foo6 foo7)
+test_expect_success 'setup' '
+ rm -f sm1 &&
+ git init sm1 &&
+ head6=$(add_file sm1 foo6 foo7)
+'
+
test_expect_success 'nonexistent commit' '
git diff-index -p --submodule=diff HEAD >actual &&
cat >expected <<-EOF &&
diff --git a/t/t4069-remerge-diff.sh b/t/t4069-remerge-diff.sh
index c6c94aef14..966882ce91 100755
--- a/t/t4069-remerge-diff.sh
+++ b/t/t4069-remerge-diff.sh
@@ -4,13 +4,6 @@ test_description='remerge-diff handling'
. ./test-lib.sh
-# This test is ort-specific
-if test "${GIT_TEST_MERGE_ALGORITHM}" != ort
-then
- skip_all="GIT_TEST_MERGE_ALGORITHM != ort"
- test_done
-fi
-
test_expect_success 'setup basic merges' '
test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
git add numbers &&
diff --git a/t/t4070-diff-pairs.sh b/t/t4070-diff-pairs.sh
new file mode 100755
index 0000000000..70deafb860
--- /dev/null
+++ b/t/t4070-diff-pairs.sh
@@ -0,0 +1,90 @@
+#!/bin/sh
+
+test_description='basic diff-pairs tests'
+. ./test-lib.sh
+
+# This creates a diff with added, modified, deleted, renamed, copied, and
+# typechange entries. This includes a submodule to test submodule diff support.
+test_expect_success 'setup' '
+ test_config_global protocol.file.allow always &&
+ git init sub &&
+ test_commit -C sub initial &&
+
+ git init main &&
+ cd main &&
+ echo to-be-gone >deleted &&
+ echo original >modified &&
+ echo now-a-file >symlink &&
+ test_seq 200 >two-hundred &&
+ test_seq 201 500 >five-hundred &&
+ git add . &&
+ test_tick &&
+ git commit -m base &&
+ git tag base &&
+
+ git submodule add ../sub &&
+ echo now-here >added &&
+ echo new >modified &&
+ rm deleted &&
+ mkdir subdir &&
+ echo content >subdir/file &&
+ mv two-hundred renamed &&
+ test_seq 201 500 | sed s/300/modified/ >copied &&
+ rm symlink &&
+ git add -A . &&
+ test_ln_s_add dest symlink &&
+ test_tick &&
+ git commit -m new &&
+ git tag new
+'
+
+test_expect_success 'diff-pairs recreates --raw' '
+ git diff-tree -r -M -C -C -z base new >expect &&
+ git diff-pairs --raw -z >actual <expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'diff-pairs can create -p output' '
+ git diff-tree -p -M -C -C base new >expect &&
+ git diff-tree -r -M -C -C -z base new |
+ git diff-pairs -p -z >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'diff-pairs does not support normal raw diff input' '
+ git diff-tree -r base new |
+ test_must_fail git diff-pairs >out 2>err &&
+
+ echo "usage: working without -z is not supported" >expect &&
+ test_must_be_empty out &&
+ test_cmp expect err
+'
+
+test_expect_success 'diff-pairs does not support tree objects as input' '
+ git diff-tree -z base new |
+ test_must_fail git diff-pairs -z >out 2>err &&
+
+ echo "fatal: tree objects not supported" >expect &&
+ test_must_be_empty out &&
+ test_cmp expect err
+'
+
+test_expect_success 'diff-pairs does not support pathspec arguments' '
+ git diff-tree -r -z base new |
+ test_must_fail git diff-pairs -z -- new >out 2>err &&
+
+ echo "usage: pathspec arguments not supported" >expect &&
+ test_must_be_empty out &&
+ test_cmp expect err
+'
+
+test_expect_success 'diff-pairs explicit queue flush' '
+ git diff-tree -r -M -C -C -z base new >expect &&
+ printf "\0" >>expect &&
+ git diff-tree -r -M -C -C -z base new >>expect &&
+
+ git diff-pairs --raw -z <expect >actual &&
+ test_cmp expect actual
+'
+
+test_done
diff --git a/t/t4071-diff-minimal.sh b/t/t4071-diff-minimal.sh
new file mode 100755
index 0000000000..4c484dadfb
--- /dev/null
+++ b/t/t4071-diff-minimal.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+test_description='minimal diff algorithm'
+
+. ./test-lib.sh
+
+test_expect_success 'minimal diff should not mark changes between changed lines' '
+ test_write_lines x x x x >pre &&
+ test_write_lines x x x A B C D x E F G >post &&
+ test_expect_code 1 git diff --no-index --minimal pre post >diff &&
+ test_grep ! ^[+-]x diff
+'
+
+test_done
diff --git a/t/t4072-diff-max-depth.sh b/t/t4072-diff-max-depth.sh
new file mode 100755
index 0000000000..0fbf1321f7
--- /dev/null
+++ b/t/t4072-diff-max-depth.sh
@@ -0,0 +1,116 @@
+#!/bin/sh
+
+test_description='check that diff --max-depth will limit recursion'
+. ./test-lib.sh
+
+make_dir() {
+ mkdir -p "$1" &&
+ echo "$2" >"$1/file"
+}
+
+make_files() {
+ echo "$1" >file &&
+ make_dir one "$1" &&
+ make_dir one/two "$1" &&
+ make_dir one/two/three "$1"
+}
+
+test_expect_success 'setup' '
+ git commit --allow-empty -m empty &&
+ git tag empty &&
+ make_files added &&
+ git add . &&
+ git commit -m added &&
+ make_files modified &&
+ git add . &&
+ git commit -m modified &&
+ make_files index &&
+ git add . &&
+ make_files worktree
+'
+
+test_expect_success '--max-depth is disallowed with wildcard pathspecs' '
+ test_must_fail git diff-tree --max-depth=0 HEAD^ HEAD -- "f*"
+'
+
+check_one() {
+ type=$1; shift
+ args=$1; shift
+ path=$1; shift
+ depth=$1; shift
+ test_expect_${expect:-success} "diff-$type $args, path=$path, depth=$depth" "
+ for i in $*; do echo \$i; done >expect &&
+ git diff-$type --max-depth=$depth --name-only $args -- $path >actual &&
+ test_cmp expect actual
+ "
+}
+
+# For tree comparisons, we expect to see subtrees at the boundary
+# get their own entry.
+check_trees() {
+ check_one tree "$*" '' 0 file one
+ check_one tree "$*" '' 1 file one/file one/two
+ check_one tree "$*" '' 2 file one/file one/two/file one/two/three
+ check_one tree "$*" '' 3 file one/file one/two/file one/two/three/file
+ check_one tree "$*" '' -1 file one/file one/two/file one/two/three/file
+ check_one tree "$*" one 0 one
+ check_one tree "$*" one 1 one/file one/two
+ check_one tree "$*" one 2 one/file one/two/file one/two/three
+ check_one tree "$*" one 3 one/file one/two/file one/two/three/file
+ check_one tree "$*" one/two 0 one/two
+ check_one tree "$*" one/two 1 one/two/file one/two/three
+ check_one tree "$*" one/two 2 one/two/file one/two/three/file
+ check_one tree "$*" one/two 2 one/two/file one/two/three/file
+ check_one tree "$*" one/two/three 0 one/two/three
+ check_one tree "$*" one/two/three 1 one/two/three/file
+}
+
+# But for index comparisons, we do not store subtrees at all, so we do not
+# expect them.
+check_index() {
+ check_one "$@" '' 0 file
+ check_one "$@" '' 1 file one/file
+ check_one "$@" '' 2 file one/file one/two/file
+ check_one "$@" '' 3 file one/file one/two/file one/two/three/file
+ check_one "$@" one 0
+ check_one "$@" one 1 one/file
+ check_one "$@" one 2 one/file one/two/file
+ check_one "$@" one 3 one/file one/two/file one/two/three/file
+ check_one "$@" one/two 0
+ check_one "$@" one/two 1 one/two/file
+ check_one "$@" one/two 2 one/two/file one/two/three/file
+ check_one "$@" one/two/three 0
+ check_one "$@" one/two/three 1 one/two/three/file
+
+ # Value '-1' for '--max-depth is the same as recursion without limit,
+ # and thus should always succeed.
+ local expect=
+ check_one "$@" '' -1 file one/file one/two/file one/two/three/file
+}
+
+# Check as a modification...
+check_trees HEAD^ HEAD
+# ...and as an addition...
+check_trees empty HEAD
+# ...and as a deletion.
+check_trees HEAD empty
+
+# We currently only implement max-depth for trees.
+expect=failure
+# Check index against a tree
+check_index index "--cached HEAD"
+# and index against the worktree
+check_index files ""
+expect=
+
+test_expect_success 'find shortest path within embedded pathspecs' '
+ cat >expect <<-\EOF &&
+ one/file
+ one/two/file
+ one/two/three/file
+ EOF
+ git diff-tree --max-depth=2 --name-only HEAD^ HEAD -- one one/two >actual &&
+ test_cmp expect actual
+'
+
+test_done
diff --git a/t/t4100-apply-stat.sh b/t/t4100-apply-stat.sh
index 146e73d8f5..a5664f3eb3 100755
--- a/t/t4100-apply-stat.sh
+++ b/t/t4100-apply-stat.sh
@@ -38,4 +38,17 @@ incomplete (1)
incomplete (2)
EOF
+test_expect_success 'applying a hunk header which overflows fails' '
+ cat >patch <<-\EOF &&
+ diff -u a/file b/file
+ --- a/file
+ +++ b/file
+ @@ -98765432109876543210 +98765432109876543210 @@
+ -a
+ +b
+ EOF
+ test_must_fail git apply patch 2>err &&
+ echo "error: corrupt patch at line 4" >expect &&
+ test_cmp expect err
+'
test_done
diff --git a/t/t4103-apply-binary.sh b/t/t4103-apply-binary.sh
index d370ecfe0d..8e302a5a57 100755
--- a/t/t4103-apply-binary.sh
+++ b/t/t4103-apply-binary.sh
@@ -26,10 +26,10 @@ test_expect_success 'setup' '
git commit -m "Initial Version" 2>/dev/null &&
git checkout -b binary &&
- perl -pe "y/x/\000/" <file1 >file3 &&
+ tr "x" "\000" <file1 >file3 &&
cat file3 >file4 &&
git add file2 &&
- perl -pe "y/\000/v/" <file3 >file1 &&
+ tr "y" "\000" <file3 >file1 &&
rm -f file2 &&
git update-index --add --remove file1 file2 file3 file4 &&
git commit -m "Second Version" &&
@@ -158,7 +158,7 @@ test_expect_success 'apply binary -p0 diff' '
test -z "$(git diff --name-status binary -- file3)"
'
-test_expect_success 'reject truncated binary diff' '
+test_expect_success PERL_TEST_HELPERS 'reject truncated binary diff' '
do_reset &&
# this length is calculated to get us very close to
diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh
index 0784ba033a..1e7beab001 100755
--- a/t/t4116-apply-reverse.sh
+++ b/t/t4116-apply-reverse.sh
@@ -13,14 +13,14 @@ test_description='git apply in reverse
test_expect_success setup '
test_write_lines a b c d e f g h i j k l m n >file1 &&
- perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
+ tr "ijk" "\000\001\002" <file1 >file2 &&
git add file1 file2 &&
git commit -m initial &&
git tag initial &&
test_write_lines a b c g h i J K L m o n p q >file1 &&
- perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
+ tr "mon" "\000\001\002" <file1 >file2 &&
git commit -a -m second &&
git tag second &&
diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh
index 2149ad5da4..1d6317bd71 100755
--- a/t/t4129-apply-samemode.sh
+++ b/t/t4129-apply-samemode.sh
@@ -102,15 +102,32 @@ test_expect_success POSIXPERM 'do not use core.sharedRepository for working tree
)
'
+test_file_mode_common () {
+ if test "$1" = "000000"
+ then
+ test_must_be_empty "$2"
+ else
+ test_grep "^$1 " "$2"
+ fi
+}
+
+test_file_mode_staged () {
+ git ls-files --stage -- "$2" >ls-files-output &&
+ test_file_mode_common "$1" ls-files-output
+}
+
+test_file_mode_HEAD () {
+ git ls-tree HEAD -- "$2" >ls-tree-output &&
+ test_file_mode_common "$1" ls-tree-output
+}
+
test_expect_success 'git apply respects core.fileMode' '
test_config core.fileMode false &&
echo true >script.sh &&
git add --chmod=+x script.sh &&
- git ls-files -s script.sh >ls-files-output &&
- test_grep "^100755" ls-files-output &&
+ test_file_mode_staged 100755 script.sh &&
test_tick && git commit -m "Add script" &&
- git ls-tree -r HEAD script.sh >ls-tree-output &&
- test_grep "^100755" ls-tree-output &&
+ test_file_mode_HEAD 100755 script.sh &&
echo true >>script.sh &&
test_tick && git commit -m "Modify script" script.sh &&
@@ -126,7 +143,211 @@ test_expect_success 'git apply respects core.fileMode' '
test_grep ! "has type 100644, expected 100755" err &&
git apply --cached patch 2>err &&
- test_grep ! "has type 100644, expected 100755" err
+ test_grep ! "has type 100644, expected 100755" err &&
+ git reset --hard
+'
+
+test_expect_success 'setup: git apply [--reverse] warns about incorrect file modes' '
+ test_config core.fileMode false &&
+
+ >mode_test &&
+ git add --chmod=-x mode_test &&
+ test_file_mode_staged 100644 mode_test &&
+ test_tick && git commit -m "add mode_test" &&
+ test_file_mode_HEAD 100644 mode_test &&
+ git tag mode_test_forward_initial &&
+
+ echo content >>mode_test &&
+ test_tick && git commit -m "append to mode_test" mode_test &&
+ test_file_mode_HEAD 100644 mode_test &&
+ git tag mode_test_reverse_initial &&
+
+ git format-patch -1 --stdout >patch &&
+ test_grep "^index .* 100644$" patch
+'
+
+test_expect_success 'git apply warns about incorrect file modes' '
+ test_config core.fileMode false &&
+ git reset --hard mode_test_forward_initial &&
+
+ git add --chmod=+x mode_test &&
+ test_file_mode_staged 100755 mode_test &&
+ test_tick && git commit -m "make mode_test executable" &&
+ test_file_mode_HEAD 100755 mode_test &&
+
+ git apply --index patch 2>err &&
+ test_grep "has type 100755, expected 100644" err &&
+ test_file_mode_staged 100755 mode_test &&
+ test_tick && git commit -m "redo: append to mode_test" &&
+ test_file_mode_HEAD 100755 mode_test
+'
+
+test_expect_success 'git apply --reverse warns about incorrect file modes' '
+ test_config core.fileMode false &&
+ git reset --hard mode_test_reverse_initial &&
+
+ git add --chmod=+x mode_test &&
+ test_file_mode_staged 100755 mode_test &&
+ test_tick && git commit -m "make mode_test executable" &&
+ test_file_mode_HEAD 100755 mode_test &&
+
+ git apply --index --reverse patch 2>err &&
+ test_grep "has type 100755, expected 100644" err &&
+ test_file_mode_staged 100755 mode_test &&
+ test_tick && git commit -m "undo: append to mode_test" &&
+ test_file_mode_HEAD 100755 mode_test
+'
+
+test_expect_success 'setup: git apply [--reverse] restores file modes (change_x_to_notx)' '
+ test_config core.fileMode false &&
+
+ touch change_x_to_notx &&
+ git add --chmod=+x change_x_to_notx &&
+ test_file_mode_staged 100755 change_x_to_notx &&
+ test_tick && git commit -m "add change_x_to_notx as executable" &&
+ test_file_mode_HEAD 100755 change_x_to_notx &&
+
+ git add --chmod=-x change_x_to_notx &&
+ test_file_mode_staged 100644 change_x_to_notx &&
+ test_tick && git commit -m "make change_x_to_notx not executable" &&
+ test_file_mode_HEAD 100644 change_x_to_notx &&
+
+ git rm change_x_to_notx &&
+ test_file_mode_staged 000000 change_x_to_notx &&
+ test_tick && git commit -m "remove change_x_to_notx" &&
+ test_file_mode_HEAD 000000 change_x_to_notx &&
+
+ git format-patch -o patches -3 &&
+ mv patches/0001-* change_x_to_notx-0001-create-0755.patch &&
+ mv patches/0002-* change_x_to_notx-0002-chmod-0644.patch &&
+ mv patches/0003-* change_x_to_notx-0003-delete.patch &&
+
+ test_grep "^new file mode 100755$" change_x_to_notx-0001-create-0755.patch &&
+ test_grep "^old mode 100755$" change_x_to_notx-0002-chmod-0644.patch &&
+ test_grep "^new mode 100644$" change_x_to_notx-0002-chmod-0644.patch &&
+ test_grep "^deleted file mode 100644$" change_x_to_notx-0003-delete.patch &&
+
+ git tag change_x_to_notx_initial
+'
+
+test_expect_success 'git apply restores file modes (change_x_to_notx)' '
+ test_config core.fileMode false &&
+ git reset --hard change_x_to_notx_initial &&
+
+ git apply --index change_x_to_notx-0001-create-0755.patch &&
+ test_file_mode_staged 100755 change_x_to_notx &&
+ test_tick && git commit -m "redo: add change_x_to_notx as executable" &&
+ test_file_mode_HEAD 100755 change_x_to_notx &&
+
+ git apply --index change_x_to_notx-0002-chmod-0644.patch 2>err &&
+ test_grep ! "has type 100.*, expected 100.*" err &&
+ test_file_mode_staged 100644 change_x_to_notx &&
+ test_tick && git commit -m "redo: make change_x_to_notx not executable" &&
+ test_file_mode_HEAD 100644 change_x_to_notx &&
+
+ git apply --index change_x_to_notx-0003-delete.patch 2>err &&
+ test_grep ! "has type 100.*, expected 100.*" err &&
+ test_file_mode_staged 000000 change_x_to_notx &&
+ test_tick && git commit -m "redo: remove change_notx_to_x" &&
+ test_file_mode_HEAD 000000 change_x_to_notx
+'
+
+test_expect_success 'git apply --reverse restores file modes (change_x_to_notx)' '
+ test_config core.fileMode false &&
+ git reset --hard change_x_to_notx_initial &&
+
+ git apply --index --reverse change_x_to_notx-0003-delete.patch &&
+ test_file_mode_staged 100644 change_x_to_notx &&
+ test_tick && git commit -m "undo: remove change_x_to_notx" &&
+ test_file_mode_HEAD 100644 change_x_to_notx &&
+
+ git apply --index --reverse change_x_to_notx-0002-chmod-0644.patch 2>err &&
+ test_grep ! "has type 100.*, expected 100.*" err &&
+ test_file_mode_staged 100755 change_x_to_notx &&
+ test_tick && git commit -m "undo: make change_x_to_notx not executable" &&
+ test_file_mode_HEAD 100755 change_x_to_notx &&
+
+ git apply --index --reverse change_x_to_notx-0001-create-0755.patch 2>err &&
+ test_grep ! "has type 100.*, expected 100.*" err &&
+ test_file_mode_staged 000000 change_x_to_notx &&
+ test_tick && git commit -m "undo: add change_x_to_notx as executable" &&
+ test_file_mode_HEAD 000000 change_x_to_notx
+'
+
+test_expect_success 'setup: git apply [--reverse] restores file modes (change_notx_to_x)' '
+ test_config core.fileMode false &&
+
+ touch change_notx_to_x &&
+ git add --chmod=-x change_notx_to_x &&
+ test_file_mode_staged 100644 change_notx_to_x &&
+ test_tick && git commit -m "add change_notx_to_x as not executable" &&
+ test_file_mode_HEAD 100644 change_notx_to_x &&
+
+ git add --chmod=+x change_notx_to_x &&
+ test_file_mode_staged 100755 change_notx_to_x &&
+ test_tick && git commit -m "make change_notx_to_x executable" &&
+ test_file_mode_HEAD 100755 change_notx_to_x &&
+
+ git rm change_notx_to_x &&
+ test_file_mode_staged 000000 change_notx_to_x &&
+ test_tick && git commit -m "remove change_notx_to_x" &&
+ test_file_mode_HEAD 000000 change_notx_to_x &&
+
+ git format-patch -o patches -3 &&
+ mv patches/0001-* change_notx_to_x-0001-create-0644.patch &&
+ mv patches/0002-* change_notx_to_x-0002-chmod-0755.patch &&
+ mv patches/0003-* change_notx_to_x-0003-delete.patch &&
+
+ test_grep "^new file mode 100644$" change_notx_to_x-0001-create-0644.patch &&
+ test_grep "^old mode 100644$" change_notx_to_x-0002-chmod-0755.patch &&
+ test_grep "^new mode 100755$" change_notx_to_x-0002-chmod-0755.patch &&
+ test_grep "^deleted file mode 100755$" change_notx_to_x-0003-delete.patch &&
+
+ git tag change_notx_to_x_initial
+'
+
+test_expect_success 'git apply restores file modes (change_notx_to_x)' '
+ test_config core.fileMode false &&
+ git reset --hard change_notx_to_x_initial &&
+
+ git apply --index change_notx_to_x-0001-create-0644.patch &&
+ test_file_mode_staged 100644 change_notx_to_x &&
+ test_tick && git commit -m "redo: add change_notx_to_x as not executable" &&
+ test_file_mode_HEAD 100644 change_notx_to_x &&
+
+ git apply --index change_notx_to_x-0002-chmod-0755.patch 2>err &&
+ test_grep ! "has type 100.*, expected 100.*" err &&
+ test_file_mode_staged 100755 change_notx_to_x &&
+ test_tick && git commit -m "redo: make change_notx_to_x executable" &&
+ test_file_mode_HEAD 100755 change_notx_to_x &&
+
+ git apply --index change_notx_to_x-0003-delete.patch &&
+ test_grep ! "has type 100.*, expected 100.*" err &&
+ test_file_mode_staged 000000 change_notx_to_x &&
+ test_tick && git commit -m "undo: remove change_notx_to_x" &&
+ test_file_mode_HEAD 000000 change_notx_to_x
+'
+
+test_expect_success 'git apply --reverse restores file modes (change_notx_to_x)' '
+ test_config core.fileMode false &&
+ git reset --hard change_notx_to_x_initial &&
+
+ git apply --index --reverse change_notx_to_x-0003-delete.patch &&
+ test_file_mode_staged 100755 change_notx_to_x &&
+ test_tick && git commit -m "undo: remove change_notx_to_x" &&
+ test_file_mode_HEAD 100755 change_notx_to_x &&
+
+ git apply --index --reverse change_notx_to_x-0002-chmod-0755.patch 2>err &&
+ test_grep ! "has type 100.*, expected 100.*" err &&
+ test_file_mode_staged 100644 change_notx_to_x &&
+ test_tick && git commit -m "undo: make change_notx_to_x executable" &&
+ test_file_mode_HEAD 100644 change_notx_to_x &&
+
+ git apply --index --reverse change_notx_to_x-0001-create-0644.patch 2>err &&
+ test_grep ! "has type 100.*, expected 100.*" err &&
+ test_file_mode_staged 000000 change_notx_to_x &&
+ test_tick && git commit -m "undo: add change_notx_to_x as not executable" &&
+ test_file_mode_HEAD 000000 change_notx_to_x
'
test_expect_success POSIXPERM 'patch mode for new file is canonicalized' '
diff --git a/t/t4140-apply-ita.sh b/t/t4140-apply-ita.sh
index c614eaf04c..0b11a8aef4 100755
--- a/t/t4140-apply-ita.sh
+++ b/t/t4140-apply-ita.sh
@@ -7,6 +7,10 @@ test_description='git apply of i-t-a file'
test_expect_success setup '
test_write_lines 1 2 3 4 5 >blueprint &&
+ cat blueprint >committed-file &&
+ git add committed-file &&
+ git commit -m "commit" &&
+
cat blueprint >test-file &&
git add -N test-file &&
git diff >creation-patch &&
@@ -14,7 +18,14 @@ test_expect_success setup '
rm -f test-file &&
git diff >deletion-patch &&
- grep "deleted file mode 100644" deletion-patch
+ grep "deleted file mode 100644" deletion-patch &&
+
+ git rm -f test-file &&
+ test_write_lines 6 >>committed-file &&
+ cat blueprint >test-file &&
+ git add -N test-file &&
+ git diff >complex-patch &&
+ git restore committed-file
'
test_expect_success 'apply creation patch to ita path (--cached)' '
@@ -53,4 +64,22 @@ test_expect_success 'apply deletion patch to ita path (--index)' '
git ls-files --stage --error-unmatch test-file
'
+test_expect_success 'apply creation patch to existing index with -N' '
+ git rm -f test-file &&
+ cat blueprint >index-file &&
+ git add index-file &&
+ git apply -N creation-patch &&
+
+ git ls-files --stage --error-unmatch index-file &&
+ git ls-files --stage --error-unmatch test-file
+'
+
+test_expect_success 'apply complex patch with -N' '
+ git rm -f test-file index-file &&
+ git apply -N complex-patch &&
+
+ git ls-files --stage --error-unmatch test-file &&
+ git diff | grep "a/committed-file"
+'
+
test_done
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 5e2b6c80ea..699a81ab5c 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -1084,13 +1084,13 @@ test_expect_success 'am works with multi-line in-body headers' '
Body test" --author="$LONG <long@example.com>" &&
git format-patch --stdout -1 >patch &&
# bump from, date, and subject down to in-body header
- perl -lpe "
- if (/^From:/) {
- print \"From: x <x\@example.com>\";
+ awk "
+ /^From:/{
+ print \"From: x <x@example.com>\";
print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\";
print \"Subject: x\n\";
- }
- " patch >msg &&
+ }; 1
+ " <patch >msg &&
git checkout HEAD^ &&
git am msg &&
# Ensure that the author and full message are present
diff --git a/t/t4151-am-abort.sh b/t/t4151-am-abort.sh
index edb38da701..8e1ecf8a68 100755
--- a/t/t4151-am-abort.sh
+++ b/t/t4151-am-abort.sh
@@ -112,7 +112,7 @@ test_expect_success 'am --abort will keep dirty index intact' '
test_expect_success 'am -3 stops on conflict on unborn branch' '
git checkout -f --orphan orphan &&
git reset &&
- rm -f otherfile-4 &&
+ rm -f file-1 otherfile-4 &&
test_must_fail git am -3 0003-*.patch &&
test 2 -eq $(git ls-files -u | wc -l) &&
test 4 = "$(cat otherfile-4)"
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index b0a3e84984..204325f4d5 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -81,7 +81,7 @@ test_expect_success 'activate rerere, old style (conflicting merge)' '
test_might_fail git config --unset rerere.enabled &&
test_must_fail git merge first &&
- sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
+ sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
rr=.git/rr-cache/$sha1 &&
grep "^=======\$" $rr/preimage &&
! test -f $rr/postimage &&
@@ -94,7 +94,7 @@ test_expect_success 'rerere.enabled works, too' '
git reset --hard &&
test_must_fail git merge first &&
- sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
+ sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
rr=.git/rr-cache/$sha1 &&
grep ^=======$ $rr/preimage
'
@@ -104,7 +104,7 @@ test_expect_success 'set up rr-cache' '
git config rerere.enabled true &&
git reset --hard &&
test_must_fail git merge first &&
- sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
+ sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
rr=.git/rr-cache/$sha1
'
@@ -188,7 +188,7 @@ test_expect_success 'rerere updates postimage timestamp' '
test_expect_success 'rerere clear' '
mv $rr/postimage .git/post-saved &&
- echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
+ echo "$sha1 a1" | tr "\012" "\000" >.git/MERGE_RR &&
git rerere clear &&
! test -d $rr
'
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 51f7beb59f..05cee9e41b 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -134,6 +134,12 @@ test_expect_success 'diff-filter=D' '
'
+test_expect_success 'all-negative filter' '
+ git log --no-renames --format=%s --diff-filter=d HEAD >actual &&
+ printf "%s\n" fifth fourth third second initial >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'diff-filter=R' '
git log -M --pretty="format:%s" --diff-filter=R HEAD >actual &&
@@ -486,10 +492,16 @@ test_expect_success !FAIL_PREREQS 'log with various grep.patternType configurati
)
'
-for cmd in show whatchanged reflog format-patch
+cmds="show reflog format-patch"
+if test_have_prereq !WITH_BREAKING_CHANGES
+then
+ cmds="$cmds whatchanged"
+fi
+for cmd in $cmds
do
case "$cmd" in
format-patch) myarg="HEAD~.." ;;
+ whatchanged) myarg=--i-still-use-this ;;
*) myarg= ;;
esac
@@ -1201,20 +1213,27 @@ test_expect_success 'reflog is expected format' '
test_cmp expect actual
'
-test_expect_success 'whatchanged is expected format' '
+test_expect_success !WITH_BREAKING_CHANGES 'whatchanged is expected format' '
+ whatchanged="whatchanged --i-still-use-this" &&
git log --no-merges --raw >expect &&
- git whatchanged >actual &&
+ git $whatchanged >actual &&
test_cmp expect actual
'
test_expect_success 'log.abbrevCommit configuration' '
+ whatchanged="whatchanged --i-still-use-this" &&
+
git log --abbrev-commit >expect.log.abbrev &&
git log --no-abbrev-commit >expect.log.full &&
git log --pretty=raw >expect.log.raw &&
git reflog --abbrev-commit >expect.reflog.abbrev &&
git reflog --no-abbrev-commit >expect.reflog.full &&
- git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
- git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
+
+ if test_have_prereq !WITH_BREAKING_CHANGES
+ then
+ git $whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
+ git $whatchanged --no-abbrev-commit >expect.whatchanged.full
+ fi &&
test_config log.abbrevCommit true &&
@@ -1231,10 +1250,13 @@ test_expect_success 'log.abbrevCommit configuration' '
git reflog --no-abbrev-commit >actual &&
test_cmp expect.reflog.full actual &&
- git whatchanged >actual &&
- test_cmp expect.whatchanged.abbrev actual &&
- git whatchanged --no-abbrev-commit >actual &&
- test_cmp expect.whatchanged.full actual
+ if test_have_prereq !WITH_BREAKING_CHANGES
+ then
+ git $whatchanged >actual &&
+ test_cmp expect.whatchanged.abbrev actual &&
+ git $whatchanged --no-abbrev-commit >actual &&
+ test_cmp expect.whatchanged.full actual
+ fi
'
test_expect_success '--abbrev-commit with core.abbrev=false' '
diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index 2421491931..74b7ddccb2 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -113,6 +113,18 @@ test_expect_success 'check-mailmap --stdin simple address: no mapping' '
test_cmp expect actual
'
+test_expect_success 'check-mailmap name and address: mapping' '
+ test_when_finished "rm .mailmap" &&
+ cat >.mailmap <<-EOF &&
+ Bug Reports <bugs-new@company.xx> Bugs <bugs@company.xx>
+ EOF
+ cat >expect <<-EOF &&
+ <bugs@company.xx>
+ EOF
+ git check-mailmap "bugs@company.xx" >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'No mailmap' '
cat >expect <<-EOF &&
$GIT_AUTHOR_NAME (1):
@@ -1121,4 +1133,37 @@ test_expect_success 'git cat-file --batch-command returns correct size with --us
test_cmp expect actual
'
+test_expect_success 'git cat-file --mailmap works with different author and committer' '
+ test_when_finished "rm .mailmap" &&
+ cat >.mailmap <<-\EOF &&
+ Mailmapped User <mailmapped-user@gitlab.com> C O Mitter <committer@example.com>
+ EOF
+ git commit --allow-empty -m "different author/committer" \
+ --author="Different Author <different@example.com>" &&
+ cat >expect <<-\EOF &&
+ author Different Author <different@example.com>
+ committer Mailmapped User <mailmapped-user@gitlab.com>
+ EOF
+ git cat-file --mailmap commit HEAD >log &&
+ sed -n -e "/^author /s/>.*/>/p" -e "/^committer /s/>.*/>/p" log >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git cat-file --mailmap maps both author and committer when both need mapping' '
+ test_when_finished "rm .mailmap" &&
+ cat >.mailmap <<-\EOF &&
+ Mapped Author <mapped-author@example.com> <different@example.com>
+ Mapped Committer <mapped-committer@example.com> C O Mitter <committer@example.com>
+ EOF
+ git commit --allow-empty -m "both author and committer mapped" \
+ --author="Different Author <different@example.com>" &&
+ cat >expect <<-\EOF &&
+ author Mapped Author <mapped-author@example.com>
+ committer Mapped Committer <mapped-committer@example.com>
+ EOF
+ git cat-file --mailmap commit HEAD >log &&
+ sed -n -e "/^author /s/>.*/>/p" -e "/^committer /s/>.*/>/p" log >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index f81e42a84d..8f2ba98963 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -698,7 +698,7 @@ test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trail
test_cmp expect actual
'
-test_expect_success '%(trailers:unfold) unfolds trailers' '
+test_expect_success PERL_TEST_HELPERS '%(trailers:unfold) unfolds trailers' '
git log --no-walk --pretty="%(trailers:unfold)" >actual &&
{
unfold <trailers &&
@@ -707,7 +707,7 @@ test_expect_success '%(trailers:unfold) unfolds trailers' '
test_cmp expect actual
'
-test_expect_success ':only and :unfold work together' '
+test_expect_success PERL_TEST_HELPERS ':only and :unfold work together' '
git log --no-walk --pretty="%(trailers:only,unfold)" >actual &&
git log --no-walk --pretty="%(trailers:unfold,only)" >reverse &&
test_cmp actual reverse &&
@@ -754,7 +754,7 @@ test_expect_success '%(trailers:key=foo) handles multiple lines even if folded'
test_cmp expect actual
'
-test_expect_success '%(trailers:key=foo,unfold) properly unfolds' '
+test_expect_success PERL_TEST_HELPERS '%(trailers:key=foo,unfold) properly unfolds' '
git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual &&
unfold <trailers | grep Signed-off-by >expect &&
test_cmp expect actual
diff --git a/t/t4206-log-follow-harder-copies.sh b/t/t4206-log-follow-harder-copies.sh
index bcab71c8e8..190c484321 100755
--- a/t/t4206-log-follow-harder-copies.sh
+++ b/t/t4206-log-follow-harder-copies.sh
@@ -54,4 +54,36 @@ test_expect_success 'validate the output.' '
compare_diff_patch current expected
'
+test_expect_success 'log --follow -B does not BUG' '
+ git switch --orphan break_and_follow_are_icky_so_use_both &&
+
+ test_seq 1 127 >numbers &&
+ git add numbers &&
+ git commit -m "numbers" &&
+
+ printf "%s\n" A B C D E F G H I J K L M N O Q R S T U V W X Y Z >pool &&
+ echo changed >numbers &&
+ git add pool numbers &&
+ git commit -m "pool" &&
+
+ git log -1 -B --raw --follow -- "p*"
+'
+
+test_expect_success 'log --follow -B does not die or use uninitialized memory' '
+ printf "%s\n" A B C D E F G H I J K L M N O P Q R S T U V W X Y Z >z &&
+ git add z &&
+ git commit -m "Initial" &&
+
+ test_seq 1 130 >z &&
+ echo lame >somefile &&
+ git add z somefile &&
+ git commit -m "Rewrite z, introduce lame somefile" &&
+
+ echo Content >somefile &&
+ git add somefile &&
+ git commit -m "Rewrite somefile" &&
+
+ git log -B --follow somefile
+'
+
test_done
diff --git a/t/t4209-log-pickaxe.sh b/t/t4209-log-pickaxe.sh
index a675ace081..0e2f80a268 100755
--- a/t/t4209-log-pickaxe.sh
+++ b/t/t4209-log-pickaxe.sh
@@ -93,6 +93,22 @@ test_expect_success 'usage: --no-pickaxe-regex' '
test_cmp expect actual
'
+test_expect_success 'usage: -G and -S with empty argument' '
+ cat >expect <<-\EOF &&
+ error: -S requires a non-empty argument
+ EOF
+
+ test_expect_code 129 git log -S "" 2>actual &&
+ test_cmp expect actual &&
+
+ cat >expect <<-\EOF &&
+ error: -G requires a non-empty argument
+ EOF
+
+ test_expect_code 129 git log -G "" 2>actual &&
+ test_cmp expect actual
+'
+
test_log expect_initial --grep initial
test_log expect_nomatch --grep InItial
test_log_icase expect_initial --grep InItial
diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh
index 3f163dc396..1064990de3 100755
--- a/t/t4216-log-bloom.sh
+++ b/t/t4216-log-bloom.sh
@@ -66,8 +66,9 @@ sane_unset GIT_TRACE2_CONFIG_PARAMS
setup () {
rm -f "$TRASH_DIRECTORY/trace.perf" &&
- git -c core.commitGraph=false log --pretty="format:%s" $1 >log_wo_bloom &&
- GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.perf" git -c core.commitGraph=true log --pretty="format:%s" $1 >log_w_bloom
+ eval git -c core.commitGraph=false log --pretty="format:%s" "$1" >log_wo_bloom &&
+ eval "GIT_TRACE2_PERF=\"$TRASH_DIRECTORY/trace.perf\"" \
+ git -c core.commitGraph=true log --pretty="format:%s" "$1" >log_w_bloom
}
test_bloom_filters_used () {
@@ -138,10 +139,6 @@ test_expect_success 'git log with --walk-reflogs does not use Bloom filters' '
test_bloom_filters_not_used "--walk-reflogs -- A"
'
-test_expect_success 'git log -- multiple path specs does not use Bloom filters' '
- test_bloom_filters_not_used "-- file4 A/file1"
-'
-
test_expect_success 'git log -- "." pathspec at root does not use Bloom filters' '
test_bloom_filters_not_used "-- ."
'
@@ -151,9 +148,40 @@ test_expect_success 'git log with wildcard that resolves to a single path uses B
test_bloom_filters_used "-- *renamed"
'
-test_expect_success 'git log with wildcard that resolves to a multiple paths does not uses Bloom filters' '
- test_bloom_filters_not_used "-- *" &&
- test_bloom_filters_not_used "-- file*"
+test_expect_success 'git log with multiple literal paths uses Bloom filter' '
+ test_bloom_filters_used "-- file4 A/file1" &&
+ test_bloom_filters_used "-- *" &&
+ test_bloom_filters_used "-- file*"
+'
+
+test_expect_success 'git log with paths all contain non-wildcard part uses Bloom filter' '
+ test_bloom_filters_used "-- A/\* file4" &&
+ test_bloom_filters_used "-- A/file\*" &&
+ test_bloom_filters_used "-- * A/\*"
+'
+
+test_expect_success 'git log with path only contains wildcard part does not use Bloom filter' '
+ test_bloom_filters_not_used "-- file\*" &&
+ test_bloom_filters_not_used "-- file\* A/\*" &&
+ test_bloom_filters_not_used "-- file\* *" &&
+ test_bloom_filters_not_used "-- \*"
+'
+
+test_expect_success 'git log with path contains various magic signatures' '
+ cd A &&
+ test_bloom_filters_used "-- \:\(top\)B" &&
+ cd .. &&
+
+ test_bloom_filters_used "-- \:\(glob\)A/\*\*/C" &&
+ test_bloom_filters_not_used "-- \:\(icase\)FILE4" &&
+ test_bloom_filters_not_used "-- \:\(exclude\)A/B/C" &&
+
+ test_when_finished "rm -f .gitattributes" &&
+ cat >.gitattributes <<-EOF &&
+ A/file1 text
+ A/B/file2 -text
+ EOF
+ test_bloom_filters_used "-- \:\(attr\:text\)A"
'
test_expect_success 'setup - add commit-graph to the chain without Bloom filters' '
@@ -738,20 +766,20 @@ check_corrupt_graph () {
test_cmp expect.out out
}
-test_expect_success 'Bloom reader notices too-small data chunk' '
+test_expect_success PERL_TEST_HELPERS 'Bloom reader notices too-small data chunk' '
check_corrupt_graph BDAT clear 00000000 &&
echo "warning: ignoring too-small changed-path chunk" \
"(4 < 12) in commit-graph file" >expect.err &&
test_cmp expect.err err
'
-test_expect_success 'Bloom reader notices out-of-bounds filter offsets' '
+test_expect_success PERL_TEST_HELPERS 'Bloom reader notices out-of-bounds filter offsets' '
check_corrupt_graph BIDX 12 FFFFFFFF &&
# use grep to avoid depending on exact chunk size
grep "warning: ignoring out-of-range offset (4294967295) for changed-path filter at pos 3 of .git/objects/info/commit-graph" err
'
-test_expect_success 'Bloom reader notices too-small index chunk' '
+test_expect_success PERL_TEST_HELPERS 'Bloom reader notices too-small index chunk' '
# replace the index with a single entry, making most
# lookups out-of-bounds
check_corrupt_graph BIDX clear 00000000 &&
@@ -760,7 +788,7 @@ test_expect_success 'Bloom reader notices too-small index chunk' '
test_cmp expect.err err
'
-test_expect_success 'Bloom reader notices out-of-order index offsets' '
+test_expect_success PERL_TEST_HELPERS 'Bloom reader notices out-of-order index offsets' '
# we do not know any real offsets, but we can pick
# something plausible; we should not get to the point of
# actually reading from the bogus offsets anyway.
diff --git a/t/t4255-am-submodule.sh b/t/t4255-am-submodule.sh
index a7ba08f728..e6679a01b4 100755
--- a/t/t4255-am-submodule.sh
+++ b/t/t4255-am-submodule.sh
@@ -19,7 +19,6 @@ am_3way () {
$2 git am --3way patch
}
-KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch_func "am_3way"
test_expect_success 'setup diff.submodule' '
diff --git a/t/t4256/1/mailinfo.c b/t/t4256/1/mailinfo.c
index b395adbdf2..39caeba865 100644
--- a/t/t4256/1/mailinfo.c
+++ b/t/t4256/1/mailinfo.c
@@ -1214,7 +1214,7 @@ void setup_mailinfo(struct mailinfo *mi)
mi->header_stage = 1;
mi->use_inbody_headers = 1;
mi->content_top = mi->content;
- git_config(git_mailinfo_config, mi);
+ repo_config(the_repository, git_mailinfo_config, mi);
}
void clear_mailinfo(struct mailinfo *mi)
diff --git a/t/t4256/1/mailinfo.c.orig b/t/t4256/1/mailinfo.c.orig
index 3281a37d51..b76eb866aa 100644
--- a/t/t4256/1/mailinfo.c.orig
+++ b/t/t4256/1/mailinfo.c.orig
@@ -1154,7 +1154,7 @@ void setup_mailinfo(struct mailinfo *mi)
mi->header_stage = 1;
mi->use_inbody_headers = 1;
mi->content_top = mi->content;
- git_config(git_mailinfo_config, mi);
+ repo_config(the_repository, git_mailinfo_config, mi);
}
void clear_mailinfo(struct mailinfo *mi)
diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh
index eea19907b5..6e117ee93c 100755
--- a/t/t4301-merge-tree-write-tree.sh
+++ b/t/t4301-merge-tree-write-tree.sh
@@ -4,13 +4,6 @@ test_description='git merge-tree --write-tree'
. ./test-lib.sh
-# This test is ort-specific
-if test "$GIT_TEST_MERGE_ALGORITHM" != "ort"
-then
- skip_all="GIT_TEST_MERGE_ALGORITHM != ort"
- test_done
-fi
-
test_expect_success setup '
test_write_lines 1 2 3 4 5 >numbers &&
echo hello >greeting &&
@@ -61,6 +54,25 @@ test_expect_success setup '
git commit -m first-commit
'
+test_expect_success '--quiet on clean merge' '
+ # Get rid of loose objects to start with
+ git gc &&
+ echo "0 objects, 0 kilobytes" >expect &&
+ git count-objects >actual &&
+ test_cmp expect actual &&
+
+ # Ensure merge is successful (exit code of 0)
+ git merge-tree --write-tree --quiet side1 side3 >output &&
+
+ # Ensure there is no output
+ test_must_be_empty output &&
+
+ # Ensure no loose objects written (all new objects written would have
+ # been in "outer layer" of the merge)
+ git count-objects >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'Clean merge' '
TREE_OID=$(git merge-tree --write-tree side1 side3) &&
q_to_tab <<-EOF >expect &&
@@ -73,6 +85,31 @@ test_expect_success 'Clean merge' '
test_cmp expect actual
'
+# Repeat the previous test, but turn off rename detection
+test_expect_success 'Failed merge without rename detection' '
+ test_must_fail git -c diff.renames=false merge-tree --write-tree side1 side3 >out &&
+ grep "CONFLICT (modify/delete): numbers deleted" out
+'
+
+test_expect_success '--quiet on conflicted merge' '
+ # Get rid of loose objects to start with
+ git gc &&
+ echo "0 objects, 0 kilobytes" >expect &&
+ git count-objects >actual &&
+ test_cmp expect actual &&
+
+ # Ensure merge has conflict
+ test_expect_code 1 git merge-tree --write-tree --quiet side1 side2 >output &&
+
+ # Ensure there is no output
+ test_must_be_empty output &&
+
+ # Ensure no loose objects written (all new objects written would have
+ # been in "outer layer" of the merge)
+ git count-objects >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'Content merge and a few conflicts' '
git checkout side1^0 &&
test_must_fail git merge side2 &&
diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
index 50344e17ca..027dedd976 100755
--- a/t/t5004-archive-corner-cases.sh
+++ b/t/t5004-archive-corner-cases.sh
@@ -4,6 +4,12 @@ test_description='test corner cases of git-archive'
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping archive corner cases tests; Perl not available'
+ test_done
+fi
+
# the 10knuls.tar file is used to test for an empty git generated tar
# without having to invoke tar because an otherwise valid empty GNU tar
# will be considered broken by {Open,Net}BSD tar
@@ -170,10 +176,7 @@ test_expect_success EXPENSIVE,UNZIP,UNZIP_ZIP64_SUPPORT \
blob=$(echo $s | git hash-object -w --stdin) &&
# create tree containing 65500 entries of that blob
- for i in $(test_seq 1 65500)
- do
- echo "100644 blob $blob $i" || return 1
- done >tree &&
+ test_seq -f "100644 blob $blob\t%d" 1 65500 >tree &&
tree=$(git mktree <tree) &&
# zip it, creating an archive a bit bigger than 4GB
diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh
index cb67bac1c4..270ce6ea48 100755
--- a/t/t5150-request-pull.sh
+++ b/t/t5150-request-pull.sh
@@ -7,12 +7,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
-if ! test_have_prereq PERL
-then
- skip_all='skipping request-pull tests, perl not available'
- test_done
-fi
-
test_expect_success 'setup' '
git init --bare upstream.git &&
diff --git a/t/t5200-update-server-info.sh b/t/t5200-update-server-info.sh
index 8365907055..a551e955b5 100755
--- a/t/t5200-update-server-info.sh
+++ b/t/t5200-update-server-info.sh
@@ -46,4 +46,9 @@ test_expect_success 'midx does not create duplicate pack entries' '
test_must_be_empty dups
'
+test_expect_success 'update-server-info does not crash with -h' '
+ test_expect_code 129 git update-server-info -h >usage &&
+ test_grep "[Uu]sage: git update-server-info " usage
+'
+
test_done
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index d1d6248558..73445782e7 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -9,9 +9,9 @@ test_description='git pack-object'
test_expect_success 'setup' '
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 &&
+ test-tool genzeros 4096 | tr "\000" "a" >a &&
+ test-tool genzeros 4096 | tr "\000" "b" >b &&
+ test-tool genzeros 4096 | tr "\000" "c" >c &&
test-tool genrandom "seed a" 2097152 >a_big &&
test-tool genrandom "seed b" 2097152 >b_big &&
git update-index --add a a_big b b_big c &&
@@ -140,7 +140,7 @@ test_expect_success 'pack-object <stdin parsing: --stdin-packs handles garbage'
# usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas>
# e.g.: check_deltas stderr -gt 0
check_deltas() {
- deltas=$(perl -lne '/delta (\d+)/ and print $1' "$1") &&
+ deltas=$(sed -n 's/Total [0-9][0-9]* (delta \([0-9][0-9]*\)).*/\1/p' "$1") &&
shift &&
if ! test "$deltas" "$@"
then
@@ -215,7 +215,7 @@ test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' '
check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION"
'
-test_expect_success 'compare delta flavors' '
+test_expect_success PERL_TEST_HELPERS 'compare delta flavors' '
perl -e '\''
defined($_ = -s $_) or die for @ARGV;
exit 1 if $ARGV[0] <= $ARGV[1];
@@ -525,7 +525,7 @@ test_expect_success 'index-pack --strict <pack> works in non-repo' '
test_path_is_file foo.idx
'
-test_expect_success SHA1 'show-index works OK outside a repository' '
+test_expect_success DEFAULT_HASH_ALGORITHM 'show-index works OK outside a repository' '
nongit git show-index <foo.idx
'
@@ -658,7 +658,7 @@ do
test_commit -C repo initial &&
git -C repo repack -ad &&
git -C repo verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx &&
- if test $hash = sha1
+ if test $hash = $GIT_TEST_BUILTIN_HASH
then
nongit git verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx
else
@@ -676,7 +676,7 @@ do
test_commit -C repo initial &&
git -C repo repack -ad &&
git -C repo index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack &&
- if test $hash = sha1
+ if test $hash = $GIT_TEST_BUILTIN_HASH
then
nongit git index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack
else
@@ -689,4 +689,57 @@ do
'
done
+test_expect_success 'valid and invalid --name-hash-versions' '
+ sane_unset GIT_TEST_NAME_HASH_VERSION &&
+
+ # Valid values are hard to verify other than "do not fail".
+ # Performance tests will be more valuable to validate these versions.
+ # Negative values are converted to version 1.
+ for value in -1 1 2
+ do
+ git pack-objects base --all --name-hash-version=$value || return 1
+ done &&
+
+ # Invalid values have clear post-conditions.
+ for value in 0 3
+ do
+ test_must_fail git pack-objects base --all --name-hash-version=$value 2>err &&
+ test_grep "invalid --name-hash-version option" err || return 1
+ done
+'
+
+# The following test is not necessarily a permanent choice, but since we do not
+# have a "name hash version" bit in the .bitmap file format, we cannot write the
+# hash values into the .bitmap file without risking breakage later.
+#
+# TODO: Make these compatible in the future and replace this test with the
+# expected behavior when both are specified.
+test_expect_success '--name-hash-version=2 and --write-bitmap-index are incompatible' '
+ git pack-objects base --all --name-hash-version=2 --write-bitmap-index 2>err &&
+ test_grep "currently, --write-bitmap-index requires --name-hash-version=1" err &&
+
+ # --stdout option silently removes --write-bitmap-index
+ git pack-objects --stdout --all --name-hash-version=2 --write-bitmap-index >out 2>err &&
+ ! test_grep "currently, --write-bitmap-index requires --name-hash-version=1" err
+'
+
+test_expect_success '--path-walk pack everything' '
+ git -C server rev-parse HEAD >in &&
+ GIT_PROGRESS_DELAY=0 git -C server pack-objects \
+ --stdout --revs --path-walk --progress <in >out.pack 2>err &&
+ grep "Compressing objects by path" err &&
+ git -C server index-pack --stdin <out.pack
+'
+
+test_expect_success '--path-walk thin pack' '
+ cat >in <<-EOF &&
+ $(git -C server rev-parse HEAD)
+ ^$(git -C server rev-parse HEAD~2)
+ EOF
+ GIT_PROGRESS_DELAY=0 git -C server pack-objects \
+ --thin --stdout --revs --path-walk --progress <in >out.pack 2>err &&
+ grep "Compressing objects by path" err &&
+ git -C server index-pack --fix-thin --stdin <out.pack
+'
+
test_done
diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh
index de58ca654a..ab99c8b685 100755
--- a/t/t5303-pack-corruption-resilience.sh
+++ b/t/t5303-pack-corruption-resilience.sh
@@ -103,7 +103,8 @@ test_expect_success 'create corruption in data of first object' '
create_new_pack &&
git prune-packed &&
chmod +w ${pack}.pack &&
- perl -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
+ sed "s/ base /abcdef/" ${pack}.pack >${pack}.pack.munged &&
+ mv ${pack}.pack.munged ${pack}.pack &&
test_must_fail git cat-file blob $blob_1 > /dev/null &&
test_must_fail git cat-file blob $blob_2 > /dev/null &&
test_must_fail git cat-file blob $blob_3 > /dev/null
@@ -160,7 +161,8 @@ test_expect_success 'create corruption in data of first delta' '
create_new_pack &&
git prune-packed &&
chmod +w ${pack}.pack &&
- perl -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
+ sed "s/ delta1 /abcdefgh/" ${pack}.pack >${pack}.pack.munged &&
+ mv ${pack}.pack.munged ${pack}.pack &&
git cat-file blob $blob_1 > /dev/null &&
test_must_fail git cat-file blob $blob_2 > /dev/null &&
test_must_fail git cat-file blob $blob_3 > /dev/null
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index 1f1f664871..2be7cd30de 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -364,4 +364,9 @@ test_expect_success 'gc.recentObjectsHook' '
git cat-file -p $BLOB
'
+test_expect_success 'prune does not crash with -h' '
+ test_expect_code 129 git prune -h >usage &&
+ test_grep "[Uu]sage: git prune " usage
+'
+
test_done
diff --git a/t/t5306-pack-nobase.sh b/t/t5306-pack-nobase.sh
index 805d60ff31..609399d54f 100755
--- a/t/t5306-pack-nobase.sh
+++ b/t/t5306-pack-nobase.sh
@@ -59,6 +59,11 @@ test_expect_success 'indirectly clone patch_clone' '
git pull ../.git &&
test $(git rev-parse HEAD) = $B &&
+ # The --path-walk feature of "git pack-objects" is not
+ # compatible with this kind of fetch from an incomplete repo.
+ GIT_TEST_PACK_PATH_WALK=0 &&
+ export GIT_TEST_PACK_PATH_WALK &&
+
git pull ../patch_clone/.git &&
test $(git rev-parse HEAD) = $C
)
diff --git a/t/t5309-pack-delta-cycles.sh b/t/t5309-pack-delta-cycles.sh
index 60fc710bac..6b03675d91 100755
--- a/t/t5309-pack-delta-cycles.sh
+++ b/t/t5309-pack-delta-cycles.sh
@@ -60,7 +60,10 @@ test_expect_success 'index-pack detects REF_DELTA cycles' '
test_expect_success 'failover to an object in another pack' '
clear_packs &&
git index-pack --stdin <ab.pack &&
- test_must_fail git index-pack --stdin --fix-thin <cycle.pack
+
+ # This cycle does not fail since the existence of A & B in
+ # the repo allows us to resolve the cycle.
+ git index-pack --stdin --fix-thin <cycle.pack
'
test_expect_success 'failover to a duplicate object in the same pack' '
@@ -72,7 +75,34 @@ test_expect_success 'failover to a duplicate object in the same pack' '
pack_obj $A
} >recoverable.pack &&
pack_trailer recoverable.pack &&
- test_must_fail git index-pack --fix-thin --stdin <recoverable.pack
+
+ # This cycle does not fail since the existence of a full copy
+ # of A in the pack allows us to resolve the cycle.
+ git index-pack --fix-thin --stdin <recoverable.pack
+'
+
+test_expect_success 'index-pack works with thin pack A->B->C with B on disk' '
+ git init server &&
+ (
+ cd server &&
+ test_commit_bulk 4
+ ) &&
+
+ A=$(git -C server rev-parse HEAD^{tree}) &&
+ B=$(git -C server rev-parse HEAD~1^{tree}) &&
+ C=$(git -C server rev-parse HEAD~2^{tree}) &&
+ git -C server reset --hard HEAD~1 &&
+
+ test-tool -C server pack-deltas --num-objects=2 >thin.pack <<-EOF &&
+ REF_DELTA $A $B
+ REF_DELTA $B $C
+ EOF
+
+ git clone "file://$(pwd)/server" client &&
+ (
+ cd client &&
+ git index-pack --fix-thin --stdin <../thin.pack
+ )
'
test_done
diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh
index eabfcd7ff6..6718fb98c0 100755
--- a/t/t5310-pack-bitmaps.sh
+++ b/t/t5310-pack-bitmaps.sh
@@ -26,6 +26,36 @@ has_any () {
grep -Ff "$1" "$2"
}
+# Since name-hash values are stored in the .bitmap files, add a test
+# that checks that the name-hash calculations are stable across versions.
+# Not exhaustive, but these hashing algorithms would be hard to change
+# without causing deviations here.
+test_expect_success 'name-hash value stability' '
+ cat >names <<-\EOF &&
+ first
+ second
+ third
+ a/one-long-enough-for-collisions
+ b/two-long-enough-for-collisions
+ many/parts/to/this/path/enough/to/collide/in/v2
+ enough/parts/to/this/path/enough/to/collide/in/v2
+ EOF
+
+ test-tool name-hash <names >out &&
+
+ cat >expect <<-\EOF &&
+ 2582249472 1763573760 first
+ 2289942528 1188134912 second
+ 2300837888 1130758144 third
+ 2544516325 3963087891 a/one-long-enough-for-collisions
+ 2544516325 4013419539 b/two-long-enough-for-collisions
+ 1420111091 1709547268 many/parts/to/this/path/enough/to/collide/in/v2
+ 1420111091 1709547268 enough/parts/to/this/path/enough/to/collide/in/v2
+ EOF
+
+ test_cmp expect out
+'
+
test_bitmap_cases () {
writeLookupTable=false
for i in "$@"
@@ -128,8 +158,9 @@ test_bitmap_cases () {
ls .git/objects/pack/ | grep bitmap >output &&
test_line_count = 1 output &&
# verify equivalent packs are generated with/without using bitmap index
- packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
- packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
+ # Be careful to not use the path-walk option in either case.
+ packasha1=$(git pack-objects --no-use-bitmap-index --no-path-walk --all packa </dev/null) &&
+ packbsha1=$(git pack-objects --use-bitmap-index --no-path-walk --all packb </dev/null) &&
list_packed_objects packa-$packasha1.idx >packa.objects &&
list_packed_objects packb-$packbsha1.idx >packb.objects &&
test_cmp packa.objects packb.objects
@@ -358,6 +389,14 @@ test_bitmap_cases () {
git init --bare client.git &&
(
cd client.git &&
+
+ # This test relies on reusing a delta, but if the
+ # path-walk machinery is engaged, the base object
+ # is considered too small to use during the
+ # dynamic computation, so is not used.
+ GIT_TEST_PACK_PATH_WALK=0 &&
+ export GIT_TEST_PACK_PATH_WALK &&
+
git config transfer.unpackLimit 1 &&
git fetch .. delta-reuse-old:delta-reuse-old &&
git fetch .. delta-reuse-new:delta-reuse-new &&
@@ -391,7 +430,7 @@ test_bitmap_cases () {
# mark the commits which did not receive bitmaps as preferred,
# and generate the bitmap again
- perl -pe "s{^}{create refs/tags/include/$. }" <before |
+ sed "s|\(.*\)|create refs/tags/include/\1 \1|" before |
git update-ref --stdin &&
git -c pack.preferBitmapTips=refs/tags/include repack -adb &&
@@ -419,7 +458,10 @@ test_bitmap_cases () {
cat >expect <<-\EOF &&
error: missing value for '\''pack.preferbitmaptips'\''
EOF
- git repack -adb 2>actual &&
+
+ # Disable name hash version adjustment due to stderr comparison.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git repack -adb 2>actual &&
test_cmp expect actual
)
'
@@ -453,6 +495,36 @@ test_bitmap_cases () {
grep "ignoring extra bitmap" trace2.txt
)
'
+
+ test_expect_success 'load corrupt bitmap' '
+ rm -fr repo &&
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+ git config pack.writeBitmapLookupTable '"$writeLookupTable"' &&
+
+ test_commit base &&
+
+ git repack -adb &&
+ bitmap="$(ls .git/objects/pack/pack-*.bitmap)" &&
+ chmod +w $bitmap &&
+
+ test-tool bitmap list-commits-with-offset >offsets &&
+ xor_off=$(head -n1 offsets | awk "{print \$3}") &&
+ printf '\161' |
+ dd of=$bitmap count=1 bs=1 conv=notrunc seek=$xor_off &&
+
+ git rev-list --objects --no-object-names HEAD >expect.raw &&
+ git rev-list --objects --use-bitmap-index --no-object-names HEAD \
+ >actual.raw &&
+
+ sort expect.raw >expect &&
+ sort actual.raw >actual &&
+
+ test_cmp expect actual
+ )
+ '
}
test_bitmap_cases
diff --git a/t/t5316-pack-delta-depth.sh b/t/t5316-pack-delta-depth.sh
index 32cf422745..03dfb7a61e 100755
--- a/t/t5316-pack-delta-depth.sh
+++ b/t/t5316-pack-delta-depth.sh
@@ -76,11 +76,11 @@ test_expect_success 'create series of packs' '
max_chain() {
git index-pack --verify-stat-only "$1" >output &&
- perl -lne '
- BEGIN { $len = 0 }
- /chain length = (\d+)/ and $len = $1;
- END { print $len }
- ' output
+ awk '
+ BEGIN { len=0 }
+ /chain length = [0-9]+:/{ len=$4 }
+ END { print len }
+ ' <output | tr -d ':'
}
# Note that this whole setup is pretty reliant on the current
@@ -89,15 +89,18 @@ max_chain() {
# adjusted (or scrapped if the heuristics have become too unreliable)
test_expect_success 'packing produces a long delta' '
# Use --window=0 to make sure we are seeing reused deltas,
- # not computing a new long chain.
- pack=$(git pack-objects --all --window=0 </dev/null pack) &&
+ # not computing a new long chain. (Also avoid the --path-walk
+ # option as it may break delta chains.)
+ pack=$(git pack-objects --all --window=0 --no-path-walk </dev/null pack) &&
echo 9 >expect &&
max_chain pack-$pack.pack >actual &&
test_cmp expect actual
'
test_expect_success '--depth limits depth' '
- pack=$(git pack-objects --all --depth=5 </dev/null pack) &&
+ # Avoid --path-walk to avoid breaking delta chains across path
+ # boundaries.
+ pack=$(git pack-objects --all --depth=5 --no-path-walk </dev/null pack) &&
echo 5 >expect &&
max_chain pack-$pack.pack >actual &&
test_cmp expect actual
diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
index f68f64cd85..0b3404f58f 100755
--- a/t/t5318-commit-graph.sh
+++ b/t/t5318-commit-graph.sh
@@ -837,7 +837,7 @@ check_corrupt_chunk () {
test_cmp expect.out out
}
-test_expect_success 'reader notices too-small oid fanout chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader notices too-small oid fanout chunk' '
# make it big enough that the graph file is plausible,
# otherwise we hit an earlier check
check_corrupt_chunk OIDF clear $(printf "000000%02x" $(test_seq 250)) &&
@@ -848,7 +848,7 @@ test_expect_success 'reader notices too-small oid fanout chunk' '
test_cmp expect.err err
'
-test_expect_success 'reader notices fanout/lookup table mismatch' '
+test_expect_success PERL_TEST_HELPERS 'reader notices fanout/lookup table mismatch' '
check_corrupt_chunk OIDF 1020 "FFFFFFFF" &&
cat >expect.err <<-\EOF &&
error: commit-graph OID lookup chunk is the wrong size
@@ -857,7 +857,7 @@ test_expect_success 'reader notices fanout/lookup table mismatch' '
test_cmp expect.err err
'
-test_expect_success 'reader notices out-of-bounds fanout' '
+test_expect_success PERL_TEST_HELPERS 'reader notices out-of-bounds fanout' '
# Rather than try to corrupt a specific hash, we will just
# wreck them all. But we cannot just set them all to 0xFFFFFFFF or
# similar, as they are used for hi/lo starts in a binary search (so if
@@ -873,7 +873,7 @@ test_expect_success 'reader notices out-of-bounds fanout' '
test_cmp expect.err err
'
-test_expect_success 'reader notices too-small commit data chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader notices too-small commit data chunk' '
check_corrupt_chunk CDAT clear 00000000 &&
cat >expect.err <<-\EOF &&
error: commit-graph commit data chunk is wrong size
@@ -882,7 +882,7 @@ test_expect_success 'reader notices too-small commit data chunk' '
test_cmp expect.err err
'
-test_expect_success 'reader notices out-of-bounds extra edge' '
+test_expect_success PERL_TEST_HELPERS 'reader notices out-of-bounds extra edge' '
check_corrupt_chunk EDGE clear &&
cat >expect.err <<-\EOF &&
error: commit-graph extra-edges pointer out of bounds
@@ -890,7 +890,7 @@ test_expect_success 'reader notices out-of-bounds extra edge' '
test_cmp expect.err err
'
-test_expect_success 'reader notices too-small generations chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader notices too-small generations chunk' '
check_corrupt_chunk GDA2 clear 00000000 &&
cat >expect.err <<-\EOF &&
error: commit-graph generations chunk is wrong size
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 0f215ad2e8..93f319a4b2 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -28,11 +28,11 @@ midx_read_expect () {
EOF
if test $NUM_PACKS -ge 1
then
- ls $OBJECT_DIR/pack/ | grep idx | sort
+ ls "$OBJECT_DIR"/pack/ | grep idx | sort
fi &&
printf "object-dir: $OBJECT_DIR\n"
} >expect &&
- test-tool read-midx $OBJECT_DIR >actual &&
+ test-tool read-midx "$OBJECT_DIR" >actual &&
test_cmp expect actual
}
@@ -305,7 +305,7 @@ test_expect_success 'midx picks objects from preferred pack' '
ofs=$(git show-index <objects/pack/test-BC-$bc.idx | grep $b |
cut -d" " -f1) &&
- printf "%s %s\tobjects/pack/test-BC-%s.pack\n" \
+ printf "%s %s\t./objects/pack/test-BC-%s.pack\n" \
"$b" "$ofs" "$bc" >expect &&
grep ^$b out >actual &&
@@ -639,7 +639,7 @@ test_expect_success 'force some 64-bit offsets with pack-objects' '
( cd ../objects64 && pwd ) >.git/objects/info/alternates &&
midx64=$(git multi-pack-index --object-dir=../objects64 write)
) &&
- midx_read_expect 1 63 5 objects64 " large-offsets"
+ midx_read_expect 1 63 5 "$(pwd)/objects64" " large-offsets"
'
test_expect_success 'verify multi-pack-index with 64-bit offsets' '
@@ -989,6 +989,23 @@ test_expect_success 'repack --batch-size=0 repacks everything' '
)
'
+test_expect_success EXPENSIVE 'repack/expire with many packs' '
+ cp -r dup many &&
+ (
+ cd many &&
+
+ for i in $(test_seq 1 100)
+ do
+ test_commit extra$i &&
+ git maintenance run --task=loose-objects || return 1
+ done &&
+
+ git multi-pack-index write &&
+ git multi-pack-index repack &&
+ git multi-pack-index expire
+ )
+'
+
test_expect_success 'repack --batch-size=<large> repacks everything' '
(
cd dup2 &&
@@ -1083,7 +1100,10 @@ test_expect_success 'load reverse index when missing .idx, .pack' '
mv $idx.bak $idx &&
mv $pack $pack.bak &&
- git cat-file --batch-check="%(objectsize:disk)" <tip
+ git cat-file --batch-check="%(objectsize:disk)" <tip &&
+
+ test_must_fail git multi-pack-index write 2>err &&
+ test_grep "could not load pack" err
)
'
@@ -1120,7 +1140,7 @@ corrupt_chunk () {
corrupt_chunk_file $midx "$@"
}
-test_expect_success 'reader notices too-small oid fanout chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader notices too-small oid fanout chunk' '
corrupt_chunk OIDF clear 00000000 &&
test_must_fail git log 2>err &&
cat >expect <<-\EOF &&
@@ -1130,7 +1150,7 @@ test_expect_success 'reader notices too-small oid fanout chunk' '
test_cmp expect err
'
-test_expect_success 'reader notices too-small oid lookup chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader notices too-small oid lookup chunk' '
corrupt_chunk OIDL clear 00000000 &&
test_must_fail git log 2>err &&
cat >expect <<-\EOF &&
@@ -1140,7 +1160,7 @@ test_expect_success 'reader notices too-small oid lookup chunk' '
test_cmp expect err
'
-test_expect_success 'reader notices too-small pack names chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader notices too-small pack names chunk' '
# There is no NUL to terminate the name here, so the
# chunk is too short.
corrupt_chunk PNAM clear 70656666 &&
@@ -1151,7 +1171,7 @@ test_expect_success 'reader notices too-small pack names chunk' '
test_cmp expect err
'
-test_expect_success 'reader handles unaligned chunks' '
+test_expect_success PERL_TEST_HELPERS 'reader handles unaligned chunks' '
# A 9-byte PNAM means all of the subsequent chunks
# will no longer be 4-byte aligned, but it is still
# a valid one-pack chunk on its own (it is "foo.pack\0").
@@ -1165,7 +1185,7 @@ test_expect_success 'reader handles unaligned chunks' '
test_cmp expect.err err
'
-test_expect_success 'reader notices too-small object offset chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader notices too-small object offset chunk' '
corrupt_chunk OOFF clear 00000000 &&
test_must_fail git log 2>err &&
cat >expect <<-\EOF &&
@@ -1175,7 +1195,7 @@ test_expect_success 'reader notices too-small object offset chunk' '
test_cmp expect err
'
-test_expect_success 'reader bounds-checks large offset table' '
+test_expect_success PERL_TEST_HELPERS 'reader bounds-checks large offset table' '
# re-use the objects64 dir here to cheaply get access to a midx
# with large offsets.
git init repo &&
@@ -1197,7 +1217,7 @@ test_expect_success 'reader bounds-checks large offset table' '
)
'
-test_expect_success 'reader notices too-small revindex chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader notices too-small revindex chunk' '
# We only get a revindex with bitmaps (and likewise only
# load it when they are asked for).
test_config repack.writeBitmaps true &&
@@ -1214,7 +1234,7 @@ test_expect_success 'reader notices too-small revindex chunk' '
test_cmp expect.err err
'
-test_expect_success 'reader notices out-of-bounds fanout' '
+test_expect_success PERL_TEST_HELPERS 'reader notices out-of-bounds fanout' '
# This is similar to the out-of-bounds fanout test in t5318. The values
# in adjacent entries should be large but not identical (they
# are used as hi/lo starts for a binary search, which would then abort
diff --git a/t/t5323-pack-redundant.sh b/t/t5323-pack-redundant.sh
index 8dbbcc5e51..2d96afd6f7 100755
--- a/t/t5323-pack-redundant.sh
+++ b/t/t5323-pack-redundant.sh
@@ -36,9 +36,20 @@ relationship between packs and objects is as follows:
. ./test-lib.sh
+if test_have_prereq WITH_BREAKING_CHANGES
+then
+ skip_all='skipping git-pack-redundant tests; built with breaking changes'
+ test_done
+fi
+
main_repo=main.git
shared_repo=shared.git
+test_expect_success 'pack-redundant needs --i-still-use-this' '
+ test_must_fail git pack-redundant >message 2>&1 &&
+ test_grep "nominated for removal" message
+'
+
git_pack_redundant='git pack-redundant --i-still-use-this'
# Create commits in <repo> and assign each commit's oid to shell variables
diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index a32be3867d..49a057cc2e 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -401,7 +401,7 @@ test_expect_success 'verify across alternates' '
)
'
-test_expect_success 'reader bounds-checks base-graph chunk' '
+test_expect_success PERL_TEST_HELPERS 'reader bounds-checks base-graph chunk' '
git clone --no-hardlinks . corrupt-base-chunk &&
(
cd corrupt-base-chunk &&
diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh
index d27557b9b0..892aeb09e4 100755
--- a/t/t5326-multi-pack-bitmaps.sh
+++ b/t/t5326-multi-pack-bitmaps.sh
@@ -176,8 +176,8 @@ test_midx_bitmap_cases () {
comm -13 bitmaps commits >before &&
test_line_count = 1 before &&
- perl -ne "printf(\"create refs/tags/include/%d \", $.); print" \
- <before | git update-ref --stdin &&
+ sed "s|\(.*\)|create refs/tags/include/\1 \1|" before |
+ git update-ref --stdin &&
rm -fr $midx-$(midx_checksum $objdir).bitmap &&
rm -fr $midx &&
diff --git a/t/t5328-commit-graph-64bit-time.sh b/t/t5328-commit-graph-64bit-time.sh
index a766a3e3f8..d8891e6a92 100755
--- a/t/t5328-commit-graph-64bit-time.sh
+++ b/t/t5328-commit-graph-64bit-time.sh
@@ -74,7 +74,7 @@ test_expect_success 'single commit with generation data exceeding UINT32_MAX' '
git -C repo-uint32-max commit-graph verify
'
-test_expect_success 'reader notices out-of-bounds generation overflow' '
+test_expect_success PERL_TEST_HELPERS 'reader notices out-of-bounds generation overflow' '
graph=.git/objects/info/commit-graph &&
test_when_finished "rm -rf $graph" &&
git commit-graph write --reachable &&
diff --git a/t/t5329-pack-objects-cruft.sh b/t/t5329-pack-objects-cruft.sh
index b71a0aef40..25ddda5cf3 100755
--- a/t/t5329-pack-objects-cruft.sh
+++ b/t/t5329-pack-objects-cruft.sh
@@ -360,43 +360,6 @@ test_expect_success 'expired objects are pruned' '
)
'
-test_expect_success 'repack --cruft generates a cruft pack' '
- git init repo &&
- test_when_finished "rm -fr repo" &&
- (
- cd repo &&
-
- test_commit reachable &&
- git branch -M main &&
- git checkout --orphan other &&
- test_commit unreachable &&
-
- git checkout main &&
- git branch -D other &&
- git tag -d unreachable &&
- # objects are not cruft if they are contained in the reflogs
- git reflog expire --all --expire=all &&
-
- git rev-list --objects --all --no-object-names >reachable.raw &&
- git cat-file --batch-all-objects --batch-check="%(objectname)" >objects &&
- sort <reachable.raw >reachable &&
- comm -13 reachable objects >unreachable &&
-
- git repack --cruft -d &&
-
- cruft=$(basename $(ls $packdir/pack-*.mtimes) .mtimes) &&
- pack=$(basename $(ls $packdir/pack-*.pack | grep -v $cruft) .pack) &&
-
- git show-index <$packdir/$pack.idx >actual.raw &&
- cut -f2 -d" " actual.raw | sort >actual &&
- test_cmp reachable actual &&
-
- git show-index <$packdir/$cruft.idx >actual.raw &&
- cut -f2 -d" " actual.raw | sort >actual &&
- test_cmp unreachable actual
- )
-'
-
test_expect_success 'loose objects mtimes upsert others' '
git init repo &&
test_when_finished "rm -fr repo" &&
@@ -470,219 +433,6 @@ test_expect_success 'expiring cruft objects with git gc' '
)
'
-test_expect_success 'cruft packs are not included in geometric repack' '
- git init repo &&
- test_when_finished "rm -fr repo" &&
- (
- cd repo &&
-
- test_commit reachable &&
- git repack -Ad &&
- git branch -M main &&
-
- git checkout --orphan other &&
- test_commit cruft &&
- git repack -d &&
-
- git checkout main &&
- git branch -D other &&
- git tag -d cruft &&
- git reflog expire --all --expire=all &&
-
- git repack --cruft &&
-
- find $packdir -type f | sort >before &&
- git repack --geometric=2 -d &&
- find $packdir -type f | sort >after &&
-
- test_cmp before after
- )
-'
-
-test_expect_success 'repack --geometric collects once-cruft objects' '
- git init repo &&
- test_when_finished "rm -fr repo" &&
- (
- cd repo &&
-
- test_commit reachable &&
- git repack -Ad &&
- git branch -M main &&
-
- git checkout --orphan other &&
- git rm -rf . &&
- test_commit --no-tag cruft &&
- cruft="$(git rev-parse HEAD)" &&
-
- git checkout main &&
- git branch -D other &&
- git reflog expire --all --expire=all &&
-
- # Pack the objects created in the previous step into a cruft
- # pack. Intentionally leave loose copies of those objects
- # around so we can pick them up in a subsequent --geometric
- # reapack.
- git repack --cruft &&
-
- # Now make those objects reachable, and ensure that they are
- # packed into the new pack created via a --geometric repack.
- git update-ref refs/heads/other $cruft &&
-
- # Without this object, the set of unpacked objects is exactly
- # the set of objects already in the cruft pack. Tweak that set
- # to ensure we do not overwrite the cruft pack entirely.
- test_commit reachable2 &&
-
- find $packdir -name "pack-*.idx" | sort >before &&
- git repack --geometric=2 -d &&
- find $packdir -name "pack-*.idx" | sort >after &&
-
- {
- git rev-list --objects --no-object-names $cruft &&
- git rev-list --objects --no-object-names reachable..reachable2
- } >want.raw &&
- sort want.raw >want &&
-
- pack=$(comm -13 before after) &&
- git show-index <$pack >objects.raw &&
-
- cut -d" " -f2 objects.raw | sort >got &&
-
- test_cmp want got
- )
-'
-
-test_expect_success 'cruft repack with no reachable objects' '
- git init repo &&
- test_when_finished "rm -fr repo" &&
- (
- cd repo &&
-
- test_commit base &&
- git repack -ad &&
-
- base="$(git rev-parse base)" &&
-
- git for-each-ref --format="delete %(refname)" >in &&
- git update-ref --stdin <in &&
- git reflog expire --all --expire=all &&
- rm -fr .git/index &&
-
- git repack --cruft -d &&
-
- git cat-file -t $base
- )
-'
-
-write_blob () {
- test-tool genrandom "$@" >in &&
- git hash-object -w -t blob in
-}
-
-find_pack () {
- for idx in $(ls $packdir/pack-*.idx)
- do
- git show-index <$idx >out &&
- if grep -q "$1" out
- then
- echo $idx
- fi || return 1
- done
-}
-
-test_expect_success 'cruft repack with --max-pack-size' '
- git init max-pack-size &&
- (
- cd max-pack-size &&
- test_commit base &&
-
- # two cruft objects which exceed the maximum pack size
- foo=$(write_blob foo 1048576) &&
- bar=$(write_blob bar 1048576) &&
- test-tool chmtime --get -1000 \
- "$objdir/$(test_oid_to_path $foo)" >foo.mtime &&
- test-tool chmtime --get -2000 \
- "$objdir/$(test_oid_to_path $bar)" >bar.mtime &&
- git repack --cruft --max-pack-size=1M &&
- find $packdir -name "*.mtimes" >cruft &&
- test_line_count = 2 cruft &&
-
- foo_mtimes="$(basename $(find_pack $foo) .idx).mtimes" &&
- bar_mtimes="$(basename $(find_pack $bar) .idx).mtimes" &&
- test-tool pack-mtimes $foo_mtimes >foo.actual &&
- test-tool pack-mtimes $bar_mtimes >bar.actual &&
-
- echo "$foo $(cat foo.mtime)" >foo.expect &&
- echo "$bar $(cat bar.mtime)" >bar.expect &&
-
- test_cmp foo.expect foo.actual &&
- test_cmp bar.expect bar.actual &&
- test "$foo_mtimes" != "$bar_mtimes"
- )
-'
-
-test_expect_success 'cruft repack with pack.packSizeLimit' '
- (
- cd max-pack-size &&
- # repack everything back together to remove the existing cruft
- # pack (but to keep its objects)
- git repack -adk &&
- git -c pack.packSizeLimit=1M repack --cruft &&
- # ensure the same post condition is met when --max-pack-size
- # would otherwise be inferred from the configuration
- find $packdir -name "*.mtimes" >cruft &&
- test_line_count = 2 cruft &&
- for pack in $(cat cruft)
- do
- test-tool pack-mtimes "$(basename $pack)" >objects &&
- test_line_count = 1 objects || return 1
- done
- )
-'
-
-test_expect_success 'cruft repack respects repack.cruftWindow' '
- git init repo &&
- test_when_finished "rm -fr repo" &&
- (
- cd repo &&
-
- test_commit base &&
-
- GIT_TRACE2_EVENT=$(pwd)/event.trace \
- git -c pack.window=1 -c repack.cruftWindow=2 repack \
- --cruft --window=3 &&
-
- grep "pack-objects.*--window=2.*--cruft" event.trace
- )
-'
-
-test_expect_success 'cruft repack respects --window by default' '
- git init repo &&
- test_when_finished "rm -fr repo" &&
- (
- cd repo &&
-
- test_commit base &&
-
- GIT_TRACE2_EVENT=$(pwd)/event.trace \
- git -c pack.window=2 repack --cruft --window=3 &&
-
- grep "pack-objects.*--window=3.*--cruft" event.trace
- )
-'
-
-test_expect_success 'cruft repack respects --quiet' '
- git init repo &&
- test_when_finished "rm -fr repo" &&
- (
- cd repo &&
-
- test_commit base &&
- GIT_PROGRESS_DELAY=0 git repack --cruft --quiet 2>err &&
- test_must_be_empty err
- )
-'
-
test_expect_success 'cruft --local drops unreachable objects' '
git init alternate &&
git init repo &&
@@ -945,4 +695,56 @@ test_expect_success 'additional cruft blobs via gc.recentObjectsHook' '
)
'
+test_expect_success 'split cruft packs with --max-cruft-size' '
+ repo=cruft-with--max-cruft-size &&
+ test_when_finished "rm -fr $repo" &&
+
+ git init "$repo" &&
+
+ (
+ cd "$repo" &&
+
+ git config core.compression 0 &&
+
+ sz=$((1024 * 1024)) && # 1MiB
+ test-tool genrandom foo $sz >foo &&
+ test-tool genrandom bar $sz >bar &&
+ foo="$(git hash-object -w -t blob foo)" &&
+ bar="$(git hash-object -w -t blob bar)" &&
+
+ to=$packdir/pack &&
+ # Pack together foo and bar into a single 2MiB pack.
+ pack="$(git pack-objects $to <<-EOF
+ $foo
+ $bar
+ EOF
+ )" &&
+
+ # Then generate a cruft pack containing foo and bar.
+ #
+ # Generate the pack with --max-pack-size equal to the
+ # size of one object, forcing us to write two cruft
+ # packs.
+ git pack-objects --cruft --max-pack-size=$sz $to <<-EOF &&
+ -pack-$pack.pack
+ EOF
+
+ ls $packdir/pack-*.mtimes >crufts &&
+ test_line_count = 2 crufts &&
+
+ for cruft in $(cat crufts)
+ do
+ test-tool pack-mtimes "$(basename "$cruft")" || return 1
+ done >actual.raw &&
+
+ cut -d" " -f1 <actual.raw | sort >actual &&
+ sort >expect <<-EOF &&
+ $foo
+ $bar
+ EOF
+
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/t/t5331-pack-objects-stdin.sh b/t/t5331-pack-objects-stdin.sh
index b48c0cbe8f..4a8df5a389 100755
--- a/t/t5331-pack-objects-stdin.sh
+++ b/t/t5331-pack-objects-stdin.sh
@@ -64,7 +64,7 @@ test_expect_success '--stdin-packs is incompatible with --filter' '
cd stdin-packs &&
test_must_fail git pack-objects --stdin-packs --stdout \
--filter=blob:none </dev/null 2>err &&
- test_grep "cannot use --filter with --stdin-packs" err
+ test_grep "options .--stdin-packs. and .--filter. cannot be used together" err
)
'
@@ -236,4 +236,124 @@ test_expect_success 'pack-objects --stdin with packfiles from main and alternate
test_cmp expected-objects actual-objects
'
+objdir=.git/objects
+packdir=$objdir/pack
+
+objects_in_packs () {
+ for p in "$@"
+ do
+ git show-index <"$packdir/pack-$p.idx" || return 1
+ done >objects.raw &&
+
+ cut -d' ' -f2 objects.raw | sort &&
+ rm -f objects.raw
+}
+
+test_expect_success '--stdin-packs=follow walks into unknown packs' '
+ test_when_finished "rm -fr repo" &&
+
+ git init repo &&
+ (
+ cd repo &&
+
+ for c in A B C D
+ do
+ test_commit "$c" || return 1
+ done &&
+
+ A="$(echo A | git pack-objects --revs $packdir/pack)" &&
+ B="$(echo A..B | git pack-objects --revs $packdir/pack)" &&
+ C="$(echo B..C | git pack-objects --revs $packdir/pack)" &&
+ D="$(echo C..D | git pack-objects --revs $packdir/pack)" &&
+ test_commit E &&
+
+ git prune-packed &&
+
+ cat >in <<-EOF &&
+ pack-$B.pack
+ ^pack-$C.pack
+ pack-$D.pack
+ EOF
+
+ # With just --stdin-packs, pack "A" is unknown to us, so
+ # only objects from packs "B" and "D" are included in
+ # the output pack.
+ P=$(git pack-objects --stdin-packs $packdir/pack <in) &&
+ objects_in_packs $B $D >expect &&
+ objects_in_packs $P >actual &&
+ test_cmp expect actual &&
+
+ # But with --stdin-packs=follow, objects from both
+ # included packs reach objects from the unknown pack, so
+ # objects from pack "A" is included in the output pack
+ # in addition to the above.
+ P=$(git pack-objects --stdin-packs=follow $packdir/pack <in) &&
+ objects_in_packs $A $B $D >expect &&
+ objects_in_packs $P >actual &&
+ test_cmp expect actual &&
+
+ # And with --unpacked, we will pick up objects from unknown
+ # packs that are reachable from loose objects. Loose object E
+ # reaches objects in pack A, but there are three excluded packs
+ # in between.
+ #
+ # The resulting pack should include objects reachable from E
+ # that are not present in packs B, C, or D, along with those
+ # present in pack A.
+ cat >in <<-EOF &&
+ ^pack-$B.pack
+ ^pack-$C.pack
+ ^pack-$D.pack
+ EOF
+
+ P=$(git pack-objects --stdin-packs=follow --unpacked \
+ $packdir/pack <in) &&
+
+ {
+ objects_in_packs $A &&
+ git rev-list --objects --no-object-names D..E
+ }>expect.raw &&
+ sort expect.raw >expect &&
+ objects_in_packs $P >actual &&
+ test_cmp expect actual
+ )
+'
+
+stdin_packs__follow_with_only () {
+ rm -fr stdin_packs__follow_with_only &&
+ git init stdin_packs__follow_with_only &&
+ (
+ cd stdin_packs__follow_with_only &&
+
+ test_commit A &&
+ test_commit B &&
+
+ git rev-parse "$@" >B.objects &&
+
+ echo A | git pack-objects --revs $packdir/pack &&
+ B="$(git pack-objects $packdir/pack <B.objects)" &&
+
+ git cat-file --batch-check="%(objectname)" --batch-all-objects >objs &&
+ for obj in $(cat objs)
+ do
+ rm -f $objdir/$(test_oid_to_path $obj) || return 1
+ done &&
+
+ ( cd $packdir && ls pack-*.pack ) >in &&
+ git pack-objects --stdin-packs=follow --stdout >/dev/null <in
+ )
+}
+
+test_expect_success '--stdin-packs=follow tolerates missing blobs' '
+ stdin_packs__follow_with_only HEAD HEAD^{tree}
+'
+
+test_expect_success '--stdin-packs=follow tolerates missing trees' '
+ stdin_packs__follow_with_only HEAD HEAD:B.t
+'
+
+test_expect_success '--stdin-packs=follow tolerates missing commits' '
+ stdin_packs__follow_with_only HEAD HEAD^{tree}
+'
+
test_done
diff --git a/t/t5332-multi-pack-reuse.sh b/t/t5332-multi-pack-reuse.sh
index 57cad7708f..395d09444c 100755
--- a/t/t5332-multi-pack-reuse.sh
+++ b/t/t5332-multi-pack-reuse.sh
@@ -7,6 +7,13 @@ test_description='pack-objects multi-pack reuse'
GIT_TEST_MULTI_PACK_INDEX=0
GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0
+
+# The --path-walk option does not consider the preferred pack
+# at all for reusing deltas, so this variable changes the
+# behavior of this test, if enabled.
+GIT_TEST_PACK_PATH_WALK=0
+export GIT_TEST_PACK_PATH_WALK
+
objdir=.git/objects
packdir=$objdir/pack
diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh
index 1dd6284756..1f7a5d82ee 100755
--- a/t/t5333-pseudo-merge-bitmaps.sh
+++ b/t/t5333-pseudo-merge-bitmaps.sh
@@ -28,9 +28,8 @@ test_pseudo_merges_reused () {
tag_everything () {
git rev-list --all --no-object-names >in &&
- perl -lne '
- print "create refs/tags/" . $. . " " . $1 if /([0-9a-f]+)/
- ' <in | git update-ref --stdin
+ sed 's|\(.*\)|create refs/tags/\1 \1|' in |
+ git update-ref --stdin
}
test_expect_success 'setup' '
@@ -102,7 +101,7 @@ test_expect_success 'stale bitmap traversal with pseudo-merges' '
test_cmp expect actual
'
-test_expect_success 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' '
+test_expect_success PERL_TEST_HELPERS 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' '
test_config bitmapPseudoMerge.test.pattern "refs/tags/" &&
test_config bitmapPseudoMerge.test.maxMerges 1 &&
test_config bitmapPseudoMerge.test.stableThreshold never &&
@@ -208,7 +207,8 @@ test_expect_success 'bitmapPseudoMerge.stableThreshold creates stable groups' '
'
test_expect_success 'out of order thresholds are rejected' '
- test_must_fail git \
+ # Disable the test var to remove a stderr message.
+ test_must_fail env GIT_TEST_NAME_HASH_VERSION=1 git \
-c bitmapPseudoMerge.test.pattern="refs/*" \
-c bitmapPseudoMerge.test.threshold=1.month.ago \
-c bitmapPseudoMerge.test.stableThreshold=1.week.ago \
@@ -234,9 +234,8 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
test_commit_bulk 16 &&
git rev-list HEAD~16.. >in &&
-
- perl -lne "print \"create refs/remotes/$r/tags/\$. \$_\"" <in |
- git update-ref --stdin || return 1
+ sed "s|\(.*\)|create refs/remotes/$r/tags/\1 \1|" in >refs &&
+ git update-ref --stdin <refs || return 1
done &&
git \
@@ -251,7 +250,7 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
do
test_pseudo_merge_commits $m >oids &&
grep -f oids refs |
- perl -lne "print \$1 if /refs\/remotes\/([0-9]+)/" |
+ sed -n "s|refs/remotes/\([0-9][0-9]*\)/|\1|p" &&
sort -u || return 1
done >remotes &&
@@ -446,4 +445,21 @@ test_expect_success 'pseudo-merge closure' '
)
'
+test_expect_success 'use pseudo-merge in boundary traversal' '
+ git init pseudo-merge-boundary-traversal &&
+ (
+ cd pseudo-merge-boundary-traversal &&
+
+ git config bitmapPseudoMerge.test.pattern refs/ &&
+ git config pack.useBitmapBoundaryTraversal true &&
+
+ test_commit A &&
+ git repack -adb &&
+ test_commit B &&
+
+ nr=$(git rev-list --count --use-bitmap-index HEAD~1..HEAD) &&
+ test 1 -eq "$nr"
+ )
+'
+
test_done
diff --git a/t/t5334-incremental-multi-pack-index.sh b/t/t5334-incremental-multi-pack-index.sh
index 26257e5660..d30d7253d6 100755
--- a/t/t5334-incremental-multi-pack-index.sh
+++ b/t/t5334-incremental-multi-pack-index.sh
@@ -44,4 +44,91 @@ test_expect_success 'convert incremental to non-incremental' '
compare_results_with_midx 'non-incremental MIDX conversion'
+write_midx_layer () {
+ n=1
+ if test -f $midx_chain
+ then
+ n="$(($(wc -l <$midx_chain) + 1))"
+ fi
+
+ for i in 1 2
+ do
+ test_commit $n.$i &&
+ git repack -d || return 1
+ done &&
+ git multi-pack-index write --bitmap --incremental
+}
+
+test_expect_success 'write initial MIDX layer' '
+ git repack -ad &&
+ write_midx_layer
+'
+
+test_expect_success 'read bitmap from first MIDX layer' '
+ git rev-list --test-bitmap 1.2
+'
+
+test_expect_success 'write another MIDX layer' '
+ write_midx_layer
+'
+
+test_expect_success 'midx verify with multiple layers' '
+ test_path_is_file "$midx_chain" &&
+ test_line_count = 2 "$midx_chain" &&
+
+ git multi-pack-index verify
+'
+
+test_expect_success 'read bitmap from second MIDX layer' '
+ git rev-list --test-bitmap 2.2
+'
+
+test_expect_success 'read earlier bitmap from second MIDX layer' '
+ git rev-list --test-bitmap 1.2
+'
+
+test_expect_success 'show object from first pack' '
+ git cat-file -p 1.1
+'
+
+test_expect_success 'show object from second pack' '
+ git cat-file -p 2.2
+'
+
+for reuse in false single multi
+do
+ test_expect_success "full clone (pack.allowPackReuse=$reuse)" '
+ rm -fr clone.git &&
+
+ git config pack.allowPackReuse $reuse &&
+ git clone --no-local --bare . clone.git
+ '
+done
+
+test_expect_success 'relink existing MIDX layer' '
+ rm -fr "$midxdir" &&
+
+ GIT_TEST_MIDX_WRITE_REV=1 git multi-pack-index write --bitmap &&
+
+ midx_hash="$(test-tool read-midx --checksum $objdir)" &&
+
+ test_path_is_file "$packdir/multi-pack-index" &&
+ test_path_is_file "$packdir/multi-pack-index-$midx_hash.bitmap" &&
+ test_path_is_file "$packdir/multi-pack-index-$midx_hash.rev" &&
+
+ test_commit another &&
+ git repack -d &&
+ git multi-pack-index write --bitmap --incremental &&
+
+ test_path_is_missing "$packdir/multi-pack-index" &&
+ test_path_is_missing "$packdir/multi-pack-index-$midx_hash.bitmap" &&
+ test_path_is_missing "$packdir/multi-pack-index-$midx_hash.rev" &&
+
+ test_path_is_file "$midxdir/multi-pack-index-$midx_hash.midx" &&
+ test_path_is_file "$midxdir/multi-pack-index-$midx_hash.bitmap" &&
+ test_path_is_file "$midxdir/multi-pack-index-$midx_hash.rev" &&
+ test_line_count = 2 "$midx_chain"
+
+'
+
test_done
diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh
index 3f81f16e13..83b42ff073 100755
--- a/t/t5400-send-pack.sh
+++ b/t/t5400-send-pack.sh
@@ -55,6 +55,13 @@ test_expect_success setup '
echo Rebase &&
git log'
+test_expect_success 'send-pack does not crash with -h' '
+ test_expect_code 129 git send-pack -h >usage &&
+ test_grep "[Uu]sage: git send-pack " usage &&
+ test_expect_code 129 nongit git send-pack -h >usage &&
+ test_grep "[Uu]sage: git send-pack " usage
+'
+
test_expect_success 'pack the source repository' '
git repack -a -d &&
git prune
@@ -268,7 +275,7 @@ extract_ref_advertisement () {
'
}
-test_expect_success 'receive-pack de-dupes .have lines' '
+test_expect_success PERL_TEST_HELPERS 'receive-pack de-dupes .have lines' '
git init shared &&
git -C shared commit --allow-empty -m both &&
git clone -s shared fork &&
diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh
index 723d1e17ec..17a46fd3ba 100755
--- a/t/t5401-update-hooks.sh
+++ b/t/t5401-update-hooks.sh
@@ -64,14 +64,14 @@ test_expect_success 'updated as expected' '
'
test_expect_success 'hooks ran' '
- test -f victim.git/pre-receive.args &&
- test -f victim.git/pre-receive.stdin &&
- test -f victim.git/update.args &&
- test -f victim.git/update.stdin &&
- test -f victim.git/post-receive.args &&
- test -f victim.git/post-receive.stdin &&
- test -f victim.git/post-update.args &&
- test -f victim.git/post-update.stdin
+ test_path_is_file victim.git/pre-receive.args &&
+ test_path_is_file victim.git/pre-receive.stdin &&
+ test_path_is_file victim.git/update.args &&
+ test_path_is_file victim.git/update.stdin &&
+ test_path_is_file victim.git/post-receive.args &&
+ test_path_is_file victim.git/post-receive.stdin &&
+ test_path_is_file victim.git/post-update.args &&
+ test_path_is_file victim.git/post-update.stdin
'
test_expect_success 'pre-receive hook input' '
diff --git a/t/t5408-send-pack-stdin.sh b/t/t5408-send-pack-stdin.sh
index 526a675045..ec339761c2 100755
--- a/t/t5408-send-pack-stdin.sh
+++ b/t/t5408-send-pack-stdin.sh
@@ -69,15 +69,24 @@ test_expect_success 'stdin mixed with cmdline' '
test_expect_success 'cmdline refs written in order' '
clear_remote &&
- test_must_fail git send-pack remote.git A:foo B:foo &&
- verify_push A foo
+ test_must_fail git send-pack remote.git A:foo B:foo 2>err &&
+ test_grep "multiple updates for ref ${SQ}refs/heads/foo${SQ} not allowed" err &&
+ test_must_fail git --git-dir=remote.git rev-parse foo
+'
+
+test_expect_success 'cmdline refs with multiple duplicates' '
+ clear_remote &&
+ test_must_fail git send-pack remote.git A:foo B:foo C:foo 2>err &&
+ test_grep "multiple updates for ref ${SQ}refs/heads/foo${SQ} not allowed" err &&
+ test_must_fail git --git-dir=remote.git rev-parse foo
'
test_expect_success '--stdin refs come after cmdline' '
clear_remote &&
echo A:foo >input &&
test_must_fail git send-pack remote.git --stdin B:foo <input &&
- verify_push B foo
+ test_grep "multiple updates for ref ${SQ}refs/heads/foo${SQ} not allowed" err &&
+ test_must_fail git --git-dir=remote.git rev-parse foo
'
test_expect_success 'refspecs and --mirror do not mix (cmdline)' '
diff --git a/t/t5410-receive-pack-alternates.sh b/t/t5410-receive-pack-alternates.sh
deleted file mode 100755
index 0b28e4e452..0000000000
--- a/t/t5410-receive-pack-alternates.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/sh
-
-test_description='git receive-pack with alternate ref filtering'
-
-GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
-export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
-
-. ./test-lib.sh
-
-test_expect_success 'setup' '
- test_commit base &&
- git clone -s --bare . fork &&
- git checkout -b public/branch main &&
- test_commit public &&
- git checkout -b private/branch main &&
- test_commit private
-'
-
-extract_haves () {
- depacketize | perl -lne '/^(\S+) \.have/ and print $1'
-}
-
-test_expect_success 'with core.alternateRefsCommand' '
- write_script fork/alternate-refs <<-\EOF &&
- git --git-dir="$1" for-each-ref \
- --format="%(objectname)" \
- refs/heads/public/
- EOF
- test_config -C fork core.alternateRefsCommand ./alternate-refs &&
- git rev-parse public/branch >expect &&
- printf "0000" | git receive-pack fork >actual &&
- extract_haves <actual >actual.haves &&
- test_cmp expect actual.haves
-'
-
-test_expect_success 'with core.alternateRefsPrefixes' '
- test_config -C fork core.alternateRefsPrefixes "refs/heads/private" &&
- git rev-parse private/branch >expect &&
- printf "0000" | git receive-pack fork >actual &&
- extract_haves <actual >actual.haves &&
- test_cmp expect actual.haves
-'
-
-test_done
diff --git a/t/t5410-receive-pack.sh b/t/t5410-receive-pack.sh
new file mode 100755
index 0000000000..09d6bfd2a1
--- /dev/null
+++ b/t/t5410-receive-pack.sh
@@ -0,0 +1,100 @@
+#!/bin/sh
+
+test_description='git receive-pack'
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ test_commit base &&
+ git clone -s --bare . fork &&
+ git checkout -b public/branch main &&
+ test_commit public &&
+ git checkout -b private/branch main &&
+ test_commit private
+'
+
+extract_haves () {
+ depacketize | sed -n 's/^\([^ ][^ ]*\) \.have/\1/p'
+}
+
+test_expect_success 'with core.alternateRefsCommand' '
+ write_script fork/alternate-refs <<-\EOF &&
+ git --git-dir="$1" for-each-ref \
+ --format="%(objectname)" \
+ refs/heads/public/
+ EOF
+ test_config -C fork core.alternateRefsCommand ./alternate-refs &&
+ git rev-parse public/branch >expect &&
+ printf "0000" | git receive-pack fork >actual &&
+ extract_haves <actual >actual.haves &&
+ test_cmp expect actual.haves
+'
+
+test_expect_success 'with core.alternateRefsPrefixes' '
+ test_config -C fork core.alternateRefsPrefixes "refs/heads/private" &&
+ git rev-parse private/branch >expect &&
+ printf "0000" | git receive-pack fork >actual &&
+ extract_haves <actual >actual.haves &&
+ test_cmp expect actual.haves
+'
+
+# The `tee.exe` shipped in Git for Windows v2.49.0 is known to hang frequently
+# when spawned from `git.exe` and piping its output to `git.exe`. This seems
+# related to MSYS2 runtime bug fixes regarding the signal handling; Let's just
+# skip the tests that need to exercise this when the faulty MSYS2 runtime is
+# detected; The test cases are exercised enough in other matrix jobs of the CI
+# runs.
+test_lazy_prereq TEE_DOES_NOT_HANG '
+ test_have_prereq !MINGW &&
+ case "$(uname -a)" in *3.5.7-463ebcdc.x86_64*) false;; esac
+'
+
+test_expect_success TEE_DOES_NOT_HANG \
+ 'receive-pack missing objects fails connectivity check' '
+ test_when_finished rm -rf repo remote.git setup.git &&
+
+ git init repo &&
+ git -C repo commit --allow-empty -m 1 &&
+ git clone --bare repo setup.git &&
+ git -C repo commit --allow-empty -m 2 &&
+
+ # Capture git-send-pack(1) output sent to git-receive-pack(1).
+ git -C repo send-pack ../setup.git --all \
+ --receive-pack="tee ${SQ}$(pwd)/out${SQ} | git-receive-pack" &&
+
+ # Replay captured git-send-pack(1) output on new empty repository.
+ git init --bare remote.git &&
+ git receive-pack remote.git <out >actual 2>err &&
+
+ test_grep "missing necessary objects" actual &&
+ test_grep "fatal: Failed to traverse parents" err &&
+ test_must_fail git -C remote.git cat-file -e $(git -C repo rev-parse HEAD)
+'
+
+test_expect_success TEE_DOES_NOT_HANG \
+ 'receive-pack missing objects bypasses connectivity check' '
+ test_when_finished rm -rf repo remote.git setup.git &&
+
+ git init repo &&
+ git -C repo commit --allow-empty -m 1 &&
+ git clone --bare repo setup.git &&
+ git -C repo commit --allow-empty -m 2 &&
+
+ # Capture git-send-pack(1) output sent to git-receive-pack(1).
+ git -C repo send-pack ../setup.git --all \
+ --receive-pack="tee ${SQ}$(pwd)/out${SQ} | git-receive-pack" &&
+
+ # Replay captured git-send-pack(1) output on new empty repository.
+ git init --bare remote.git &&
+ git receive-pack --skip-connectivity-check remote.git <out >actual 2>err &&
+
+ test_grep ! "missing necessary objects" actual &&
+ test_must_be_empty err &&
+ git -C remote.git cat-file -e $(git -C repo rev-parse HEAD) &&
+ test_must_fail git -C remote.git rev-list $(git -C repo rev-parse HEAD)
+'
+
+test_done
diff --git a/t/t5503-tagfollow.sh b/t/t5503-tagfollow.sh
index 195fc64dd4..febe441041 100755
--- a/t/t5503-tagfollow.sh
+++ b/t/t5503-tagfollow.sh
@@ -7,6 +7,12 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping tagfollow tests; Perl not available'
+ test_done
+fi
+
# End state of the repository:
#
# T - tag1 S - tag2
@@ -160,4 +166,18 @@ test_expect_success 'new clone fetch main and tags' '
test_cmp expect actual
'
+test_expect_success 'fetch specific OID with tag following' '
+ git init --bare clone3.git &&
+ (
+ cd clone3.git &&
+ git remote add origin .. &&
+ git fetch origin $B:refs/heads/main &&
+
+ git -C .. for-each-ref >expect &&
+ git for-each-ref >actual &&
+
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh
index 8212a70be8..438250c75e 100755
--- a/t/t5504-fetch-receive-strict.sh
+++ b/t/t5504-fetch-receive-strict.sh
@@ -64,12 +64,6 @@ test_expect_success 'fetch with transfer.fsckobjects' '
)
'
-cat >exp <<EOF
-To dst
-! refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
-Done
-EOF
-
test_expect_success 'push without strict' '
rm -rf dst &&
git init dst &&
@@ -78,6 +72,11 @@ test_expect_success 'push without strict' '
git config fetch.fsckobjects false &&
git config transfer.fsckobjects false
) &&
+ cat >exp <<-\EOF &&
+ To dst
+ ! refs/heads/main:refs/heads/test [remote rejected] (missing necessary objects)
+ Done
+ EOF
test_must_fail git push --porcelain dst main:refs/heads/test >act &&
test_cmp exp act
'
@@ -94,11 +93,6 @@ test_expect_success 'push with !receive.fsckobjects' '
test_cmp exp act
'
-cat >exp <<EOF
-To dst
-! refs/heads/main:refs/heads/test [remote rejected] (unpacker error)
-EOF
-
test_expect_success 'push with receive.fsckobjects' '
rm -rf dst &&
git init dst &&
@@ -107,6 +101,10 @@ test_expect_success 'push with receive.fsckobjects' '
git config receive.fsckobjects true &&
git config transfer.fsckobjects false
) &&
+ cat >exp <<-\EOF &&
+ To dst
+ ! refs/heads/main:refs/heads/test [remote rejected] (unpacker error)
+ EOF
test_must_fail git push --porcelain dst main:refs/heads/test >act &&
test_cmp exp act
'
@@ -129,15 +127,14 @@ test_expect_success 'repair the "corrupt or missing" object' '
git fsck
'
-cat >bogus-commit <<EOF
-tree $EMPTY_TREE
-author Bugs Bunny 1234567890 +0000
-committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
-
-This commit object intentionally broken
-EOF
-
test_expect_success 'setup bogus commit' '
+ cat >bogus-commit <<-EOF &&
+ tree $EMPTY_TREE
+ author Bugs Bunny 1234567890 +0000
+ committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
+
+ This commit object intentionally broken
+ EOF
commit="$(git hash-object --literally -t commit -w --stdin <bogus-commit)"
'
@@ -167,6 +164,8 @@ test_expect_success 'fsck with unsorted skipList' '
test_expect_success 'fsck with invalid or bogus skipList input' '
git -c fsck.skipList=/dev/null -c fsck.missingEmail=ignore fsck &&
+ test_must_fail git -c fsck.skipList -c fsck.missingEmail=ignore fsck 2>err &&
+ test_grep "unable to parse '\'fsck.skiplist\'' from command-line config" err &&
test_must_fail git -c fsck.skipList=does-not-exist -c fsck.missingEmail=ignore fsck 2>err &&
test_grep "could not open.*: does-not-exist" err &&
test_must_fail git -c fsck.skipList=.git/config -c fsck.missingEmail=ignore fsck 2>err &&
@@ -213,6 +212,11 @@ test_expect_success 'fsck with exhaustive accepted skipList input (various types
test_must_be_empty err
'
+test_expect_success 'receive-pack with missing receive.fsck.skipList path' '
+ test_must_fail git -c receive.fsck.skipList receive-pack dst 2>err &&
+ test_grep "unable to parse '\'receive.fsck.skiplist\'' from command-line config" err
+'
+
test_expect_success 'push with receive.fsck.skipList' '
git push . $commit:refs/heads/bogus &&
rm -rf dst &&
@@ -255,6 +259,9 @@ test_expect_success 'fetch with fetch.fsck.skipList' '
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
# Invalid and/or bogus skipList input
+ test_must_fail git --git-dir=dst/.git -c fetch.fsck.skipList fetch \
+ "file://$(pwd)" $refspec 2>err &&
+ test_grep "unable to parse '\'fetch.fsck.skiplist\'' from command-line config" err &&
git --git-dir=dst/.git config fetch.fsck.skipList /dev/null &&
test_must_fail git --git-dir=dst/.git fetch "file://$(pwd)" $refspec &&
git --git-dir=dst/.git config fetch.fsck.skipList does-not-exist &&
@@ -352,7 +359,7 @@ test_expect_success \
grep "Cannot demote unterminatedheader" act
'
-test_expect_success 'badFilemode is not a strict error' '
+test_expect_success PERL_TEST_HELPERS 'badFilemode is not a strict error' '
git init --bare badmode.git &&
tree=$(
cd badmode.git &&
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 519f7973e3..e592c0bcde 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -499,7 +499,7 @@ test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
cd test &&
git fetch two "refs/heads/*:refs/remotes/two/*" &&
git remote set-head --auto two >output 2>&1 &&
- echo "${SQ}two/HEAD${SQ} is unchanged and points to ${SQ}main${SQ}" >expect &&
+ echo "${SQ}two/HEAD${SQ} is now created and points to ${SQ}main${SQ}" >expect &&
test_cmp expect output
)
'
@@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '
)
'
+test_expect_success 'non-mirror fetch does not interfere with mirror' '
+ test_when_finished rm -rf headnotmain &&
+ (
+ git init --bare -b notmain headnotmain &&
+ cd headnotmain &&
+ git remote add -f other ../two &&
+ test "$(git symbolic-ref HEAD)" = "refs/heads/notmain"
+ )
+'
+
test_expect_success 'add --mirror=fetch' '
mkdir mirror-fetch &&
git init -b main mirror-fetch/parent &&
@@ -1113,7 +1123,7 @@ Pull: refs/heads/main:refs/heads/origin
Pull: refs/heads/next:refs/heads/origin2
EOF
-test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
+test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/remotes' '
git clone one five &&
origin_url=$(pwd)/one &&
(
@@ -1139,7 +1149,7 @@ test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
)
'
-test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
+test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches' '
git clone --template= one six &&
origin_url=$(pwd)/one &&
(
@@ -1155,7 +1165,7 @@ test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
)
'
-test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' '
+test_expect_success !WITH_BREAKING_CHANGES 'migrate a remote from named file in $GIT_DIR/branches (2)' '
git clone --template= one seven &&
(
cd seven &&
@@ -1634,4 +1644,91 @@ test_expect_success 'empty config clears remote.*.pushurl list' '
test_cmp expect actual
'
+test_expect_success 'forbid adding subset of existing remote' '
+ test_when_finished "git remote rm outer" &&
+ git remote add outer url &&
+ test_must_fail git remote add outer/inner url 2>err &&
+ test_grep ".outer/inner. is a subset of existing remote .outer." err
+'
+
+test_expect_success 'forbid adding superset of existing remote' '
+ test_when_finished "git remote rm outer/inner" &&
+ git remote add outer/inner url &&
+ test_must_fail git remote add outer url 2>err &&
+ test_grep ".outer. is a superset of existing remote .outer/inner." err
+'
+
+test_expect_success 'rename handles unborn HEAD' '
+ test_when_finished "git remote remove unborn-renamed" &&
+ git remote add unborn url &&
+ git symbolic-ref refs/remotes/unborn/HEAD refs/remotes/unborn/nonexistent &&
+ git remote rename unborn unborn-renamed &&
+ git symbolic-ref refs/remotes/unborn-renamed/HEAD >actual &&
+ echo refs/remotes/unborn-renamed/nonexistent >expected &&
+ test_cmp expected actual
+'
+
+test_expect_success 'rename can nest a remote into itself' '
+ test_commit parent-commit &&
+ COMMIT_ID=$(git rev-parse HEAD) &&
+ test_when_finished "git remote remove parent || true" &&
+ git remote add parent url &&
+ git update-ref refs/remotes/parent/branch $COMMIT_ID &&
+ test_when_finished "git remote remove parent/child" &&
+ git remote rename parent parent/child &&
+ git for-each-ref refs/remotes/ >actual &&
+ printf "$COMMIT_ID commit\trefs/remotes/parent/child/branch\n" >expected &&
+ test_cmp expected actual
+'
+
+test_expect_success 'rename can nest a remote into itself with a conflicting branch name' '
+ test_commit parent-conflict &&
+ COMMIT_ID=$(git rev-parse HEAD) &&
+ test_when_finished "git remote remove parent || true" &&
+ git remote add parent url &&
+ git update-ref refs/remotes/parent/child $COMMIT_ID &&
+ test_when_finished "git remote remove parent/child" &&
+ test_must_fail git remote rename parent parent/child 2>err &&
+ test_grep "renaming remote references failed" err &&
+ test_grep "The remote you are trying to rename has conflicting references" err &&
+ git for-each-ref refs/remotes/ >actual &&
+ printf "$COMMIT_ID commit\trefs/remotes/parent/child\n" >expected &&
+ test_cmp expected actual
+'
+
+test_expect_success 'rename can unnest a remote' '
+ test_commit parent-child-commit &&
+ COMMIT_ID=$(git rev-parse HEAD) &&
+ test_when_finished "git remote remove parent/child || true" &&
+ git remote add parent/child url &&
+ git update-ref refs/remotes/parent/child/branch $COMMIT_ID &&
+ git remote rename parent/child parent &&
+ git for-each-ref refs/remotes/ >actual &&
+ printf "$COMMIT_ID commit\trefs/remotes/parent/branch\n" >expected &&
+ test_cmp expected actual
+'
+
+test_expect_success 'rename moves around the reflog' '
+ test_commit reflog-old &&
+ COMMIT_ID=$(git rev-parse HEAD) &&
+ test_config core.logAllRefUpdates true &&
+ test_when_finished "git remote remove reflog-old || true" &&
+ git remote add reflog-old url &&
+ git update-ref refs/remotes/reflog-old/branch $COMMIT_ID &&
+ test-tool ref-store main for-each-reflog >actual &&
+ test_grep refs/remotes/reflog-old/branch actual &&
+ test-tool ref-store main for-each-reflog-ent refs/remotes/reflog-old/branch >reflog-entries-old &&
+ test_line_count = 1 reflog-entries-old &&
+ git remote rename reflog-old reflog-new &&
+ test-tool ref-store main for-each-reflog >actual &&
+ test_grep ! refs/remotes/reflog-old actual &&
+ test_grep refs/remotes/reflog-new/branch actual &&
+ test-tool ref-store main for-each-reflog-ent refs/remotes/reflog-new/branch >reflog-entries-new &&
+ cat >expect <<-EOF &&
+ $(cat reflog-entries-old)
+ $COMMIT_ID $COMMIT_ID $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1112912173 -0700 remote: renamed refs/remotes/reflog-old/branch to refs/remotes/reflog-new/branch
+ EOF
+ test_cmp expect reflog-entries-new
+'
+
test_done
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 2d9587059f..83d1aadf9f 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -8,7 +8,11 @@ test_description='Per branch config variables affects "git fetch".
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-bundle.sh
-D=$(pwd)
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping fetch tests; Perl not available'
+ test_done
+fi
test_expect_success setup '
echo >file original &&
@@ -34,296 +38,304 @@ test_expect_success "clone and setup child repos" '
git clone . three &&
(
cd three &&
- git config branch.main.remote two &&
- git config branch.main.merge refs/heads/one &&
- mkdir -p .git/remotes &&
- cat >.git/remotes/two <<-\EOF
- URL: ../two/.git/
- Pull: refs/heads/main:refs/heads/two
- Pull: refs/heads/one:refs/heads/one
- EOF
+ git config set remote.two.url ../two/.git/ &&
+ git config set remote.two.fetch refs/heads/main:refs/heads/two &&
+ git config set --append remote.two.fetch refs/heads/one:refs/heads/one &&
+ git config set branch.main.remote two &&
+ git config set branch.main.merge refs/heads/one
) &&
git clone . bundle &&
git clone . seven
'
test_expect_success "fetch test" '
- cd "$D" &&
echo >file updated by origin &&
git commit -a -m "updated by origin" &&
- cd two &&
- git fetch &&
- git rev-parse --verify refs/heads/one &&
- mine=$(git rev-parse refs/heads/one) &&
- his=$(cd ../one && git rev-parse refs/heads/main) &&
- test "z$mine" = "z$his"
-'
-
-test_expect_success "fetch test for-merge" '
- cd "$D" &&
- cd three &&
- git fetch &&
- git rev-parse --verify refs/heads/two &&
- git rev-parse --verify refs/heads/one &&
- main_in_two=$(cd ../two && git rev-parse main) &&
- one_in_two=$(cd ../two && git rev-parse one) &&
- {
- echo "$one_in_two " &&
- echo "$main_in_two not-for-merge"
- } >expected &&
- cut -f -2 .git/FETCH_HEAD >actual &&
- test_cmp expected actual'
-
-test_expect_success "fetch test remote HEAD" '
- cd "$D" &&
- cd two &&
- git fetch &&
- git rev-parse --verify refs/remotes/origin/HEAD &&
- git rev-parse --verify refs/remotes/origin/main &&
- head=$(git rev-parse refs/remotes/origin/HEAD) &&
- branch=$(git rev-parse refs/remotes/origin/main) &&
- test "z$head" = "z$branch"'
-
-test_expect_success "fetch test remote HEAD change" '
- cd "$D" &&
- cd two &&
- git switch -c other &&
- git push -u origin other &&
- git rev-parse --verify refs/remotes/origin/HEAD &&
- git rev-parse --verify refs/remotes/origin/main &&
- git rev-parse --verify refs/remotes/origin/other &&
- git remote set-head origin other &&
- git fetch &&
- head=$(git rev-parse refs/remotes/origin/HEAD) &&
- branch=$(git rev-parse refs/remotes/origin/other) &&
- test "z$head" = "z$branch"'
-
-test_expect_success "fetch test followRemoteHEAD never" '
- test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
- cd "$D" &&
cd two &&
- git update-ref --no-deref -d refs/remotes/origin/HEAD &&
- git config set remote.origin.followRemoteHEAD "never" &&
git fetch &&
- test_must_fail git rev-parse --verify refs/remotes/origin/HEAD
+ git rev-parse --verify refs/heads/one &&
+ mine=$(git rev-parse refs/heads/one) &&
+ his=$(cd ../one && git rev-parse refs/heads/main) &&
+ test "z$mine" = "z$his"
)
'
-test_expect_success "fetch test followRemoteHEAD warn no change" '
- test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
+test_expect_success "fetch test for-merge" '
(
- cd "$D" &&
- cd two &&
- git rev-parse --verify refs/remotes/origin/other &&
- git remote set-head origin other &&
- git rev-parse --verify refs/remotes/origin/HEAD &&
- git rev-parse --verify refs/remotes/origin/main &&
- git config set remote.origin.followRemoteHEAD "warn" &&
- git fetch >output &&
- echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
- "but we have ${SQ}other${SQ} locally." >expect &&
- test_cmp expect output &&
- head=$(git rev-parse refs/remotes/origin/HEAD) &&
- branch=$(git rev-parse refs/remotes/origin/other) &&
- test "z$head" = "z$branch"
+ cd three &&
+ git fetch &&
+ git rev-parse --verify refs/heads/two &&
+ git rev-parse --verify refs/heads/one &&
+ main_in_two=$(cd ../two && git rev-parse main) &&
+ one_in_two=$(cd ../two && git rev-parse one) &&
+ {
+ echo "$one_in_two " &&
+ echo "$main_in_two not-for-merge"
+ } >expected &&
+ cut -f -2 .git/FETCH_HEAD >actual &&
+ test_cmp expected actual
)
'
-test_expect_success "fetch test followRemoteHEAD warn create" '
- test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
+test_expect_success "fetch test remote HEAD" '
(
- cd "$D" &&
cd two &&
- git update-ref --no-deref -d refs/remotes/origin/HEAD &&
- git config set remote.origin.followRemoteHEAD "warn" &&
+ git fetch &&
+ git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
- output=$(git fetch) &&
- test "z" = "z$output" &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/main) &&
test "z$head" = "z$branch"
)
'
-test_expect_success "fetch test followRemoteHEAD warn detached" '
- test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
+test_expect_success "fetch test remote HEAD in bare repository" '
+ test_when_finished rm -rf barerepo &&
(
- cd "$D" &&
- cd two &&
- git update-ref --no-deref -d refs/remotes/origin/HEAD &&
- git update-ref refs/remotes/origin/HEAD HEAD &&
- HEAD=$(git log --pretty="%H") &&
- git config set remote.origin.followRemoteHEAD "warn" &&
- git fetch >output &&
- echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
- "but we have a detached HEAD pointing to" \
- "${SQ}${HEAD}${SQ} locally." >expect &&
- test_cmp expect output
+ git init --bare barerepo &&
+ cd barerepo &&
+ git remote add upstream ../two &&
+ git fetch upstream &&
+ git rev-parse --verify refs/remotes/upstream/HEAD &&
+ git rev-parse --verify refs/remotes/upstream/main &&
+ head=$(git rev-parse refs/remotes/upstream/HEAD) &&
+ branch=$(git rev-parse refs/remotes/upstream/main) &&
+ test "z$head" = "z$branch"
)
'
-test_expect_success "fetch test followRemoteHEAD warn quiet" '
- test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
+
+test_expect_success "fetch test remote HEAD change" '
(
- cd "$D" &&
cd two &&
- git rev-parse --verify refs/remotes/origin/other &&
- git remote set-head origin other &&
+ git switch -c other &&
+ git push -u origin other &&
git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
- git config set remote.origin.followRemoteHEAD "warn" &&
- output=$(git fetch --quiet) &&
- test "z" = "z$output" &&
+ git rev-parse --verify refs/remotes/origin/other &&
+ git remote set-head origin other &&
+ git fetch &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/other) &&
test "z$head" = "z$branch"
)
'
+test_expect_success "fetch test followRemoteHEAD never" '
+ git -C two update-ref --no-deref -d refs/remotes/origin/HEAD &&
+ test_config -C two remote.origin.followRemoteHEAD "never" &&
+ GIT_TRACE_PACKET=$PWD/trace.out git -C two fetch &&
+ # Confirm that we do not even ask for HEAD when we are
+ # not going to act on it.
+ test_grep ! "ref-prefix HEAD" trace.out &&
+ test_must_fail git -C two rev-parse --verify refs/remotes/origin/HEAD
+'
+
+test_expect_success "fetch test followRemoteHEAD warn no change" '
+ git -C two rev-parse --verify refs/remotes/origin/other &&
+ git -C two remote set-head origin other &&
+ git -C two rev-parse --verify refs/remotes/origin/HEAD &&
+ git -C two rev-parse --verify refs/remotes/origin/main &&
+ test_config -C two remote.origin.followRemoteHEAD "warn" &&
+ git -C two fetch >output &&
+ echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
+ "but we have ${SQ}other${SQ} locally." >expect &&
+ test_cmp expect output &&
+ head=$(git -C two rev-parse refs/remotes/origin/HEAD) &&
+ branch=$(git -C two rev-parse refs/remotes/origin/other) &&
+ test "z$head" = "z$branch"
+'
+
+test_expect_success "fetch test followRemoteHEAD warn create" '
+ git -C two update-ref --no-deref -d refs/remotes/origin/HEAD &&
+ test_config -C two remote.origin.followRemoteHEAD "warn" &&
+ git -C two rev-parse --verify refs/remotes/origin/main &&
+ output=$(git -C two fetch) &&
+ test "z" = "z$output" &&
+ head=$(git -C two rev-parse refs/remotes/origin/HEAD) &&
+ branch=$(git -C two rev-parse refs/remotes/origin/main) &&
+ test "z$head" = "z$branch"
+'
+
+test_expect_success "fetch test followRemoteHEAD warn detached" '
+ git -C two update-ref --no-deref -d refs/remotes/origin/HEAD &&
+ git -C two update-ref refs/remotes/origin/HEAD HEAD &&
+ HEAD=$(git -C two log --pretty="%H") &&
+ test_config -C two remote.origin.followRemoteHEAD "warn" &&
+ git -C two fetch >output &&
+ echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
+ "but we have a detached HEAD pointing to" \
+ "${SQ}${HEAD}${SQ} locally." >expect &&
+ test_cmp expect output
+'
+
+test_expect_success "fetch test followRemoteHEAD warn quiet" '
+ git -C two rev-parse --verify refs/remotes/origin/other &&
+ git -C two remote set-head origin other &&
+ git -C two rev-parse --verify refs/remotes/origin/HEAD &&
+ git -C two rev-parse --verify refs/remotes/origin/main &&
+ test_config -C two remote.origin.followRemoteHEAD "warn" &&
+ output=$(git -C two fetch --quiet) &&
+ test "z" = "z$output" &&
+ head=$(git -C two rev-parse refs/remotes/origin/HEAD) &&
+ branch=$(git -C two rev-parse refs/remotes/origin/other) &&
+ test "z$head" = "z$branch"
+'
+
test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is same" '
- test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
- (
- cd "$D" &&
- cd two &&
- git rev-parse --verify refs/remotes/origin/other &&
- git remote set-head origin other &&
- git rev-parse --verify refs/remotes/origin/HEAD &&
- git rev-parse --verify refs/remotes/origin/main &&
- git config set remote.origin.followRemoteHEAD "warn-if-not-main" &&
- actual=$(git fetch) &&
- test "z" = "z$actual" &&
- head=$(git rev-parse refs/remotes/origin/HEAD) &&
- branch=$(git rev-parse refs/remotes/origin/other) &&
- test "z$head" = "z$branch"
- )
+ git -C two rev-parse --verify refs/remotes/origin/other &&
+ git -C two remote set-head origin other &&
+ git -C two rev-parse --verify refs/remotes/origin/HEAD &&
+ git -C two rev-parse --verify refs/remotes/origin/main &&
+ test_config -C two remote.origin.followRemoteHEAD "warn-if-not-main" &&
+ actual=$(git -C two fetch) &&
+ test "z" = "z$actual" &&
+ head=$(git -C two rev-parse refs/remotes/origin/HEAD) &&
+ branch=$(git -C two rev-parse refs/remotes/origin/other) &&
+ test "z$head" = "z$branch"
'
test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is different" '
- test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
- (
- cd "$D" &&
- cd two &&
- git rev-parse --verify refs/remotes/origin/other &&
- git remote set-head origin other &&
- git rev-parse --verify refs/remotes/origin/HEAD &&
- git rev-parse --verify refs/remotes/origin/main &&
- git config set remote.origin.followRemoteHEAD "warn-if-not-some/different-branch" &&
- git fetch >actual &&
- echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
- "but we have ${SQ}other${SQ} locally." >expect &&
- test_cmp expect actual &&
- head=$(git rev-parse refs/remotes/origin/HEAD) &&
- branch=$(git rev-parse refs/remotes/origin/other) &&
- test "z$head" = "z$branch"
- )
+ git -C two rev-parse --verify refs/remotes/origin/other &&
+ git -C two remote set-head origin other &&
+ git -C two rev-parse --verify refs/remotes/origin/HEAD &&
+ git -C two rev-parse --verify refs/remotes/origin/main &&
+ test_config -C two remote.origin.followRemoteHEAD "warn-if-not-some/different-branch" &&
+ git -C two fetch >actual &&
+ echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
+ "but we have ${SQ}other${SQ} locally." >expect &&
+ test_cmp expect actual &&
+ head=$(git -C two rev-parse refs/remotes/origin/HEAD) &&
+ branch=$(git -C two rev-parse refs/remotes/origin/other) &&
+ test "z$head" = "z$branch"
'
test_expect_success "fetch test followRemoteHEAD always" '
- test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
- (
- cd "$D" &&
- cd two &&
- git rev-parse --verify refs/remotes/origin/other &&
- git remote set-head origin other &&
- git rev-parse --verify refs/remotes/origin/HEAD &&
- git rev-parse --verify refs/remotes/origin/main &&
- git config set remote.origin.followRemoteHEAD "always" &&
- git fetch &&
- head=$(git rev-parse refs/remotes/origin/HEAD) &&
- branch=$(git rev-parse refs/remotes/origin/main) &&
- test "z$head" = "z$branch"
- )
+ git -C two rev-parse --verify refs/remotes/origin/other &&
+ git -C two remote set-head origin other &&
+ git -C two rev-parse --verify refs/remotes/origin/HEAD &&
+ git -C two rev-parse --verify refs/remotes/origin/main &&
+ test_config -C two remote.origin.followRemoteHEAD "always" &&
+ git -C two fetch &&
+ head=$(git -C two rev-parse refs/remotes/origin/HEAD) &&
+ branch=$(git -C two rev-parse refs/remotes/origin/main) &&
+ test "z$head" = "z$branch"
+'
+
+test_expect_success 'followRemoteHEAD does not kick in with refspecs' '
+ git -C two remote set-head origin other &&
+ test_config -C two remote.origin.followRemoteHEAD always &&
+ git -C two fetch origin refs/heads/main:refs/remotes/origin/main &&
+ echo refs/remotes/origin/other >expect &&
+ git -C two symbolic-ref refs/remotes/origin/HEAD >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'followRemoteHEAD create does not overwrite dangling symref' '
+ git -C two remote add -m does-not-exist custom-head ../one &&
+ test_config -C two remote.custom-head.followRemoteHEAD create &&
+ git -C two fetch custom-head &&
+ echo refs/remotes/custom-head/does-not-exist >expect &&
+ git -C two symbolic-ref refs/remotes/custom-head/HEAD >actual &&
+ test_cmp expect actual
'
test_expect_success 'fetch --prune on its own works as expected' '
- cd "$D" &&
git clone . prune &&
- cd prune &&
- git update-ref refs/remotes/origin/extrabranch main &&
+ (
+ cd prune &&
+ git update-ref refs/remotes/origin/extrabranch main &&
- git fetch --prune origin &&
- test_must_fail git rev-parse origin/extrabranch
+ git fetch --prune origin &&
+ test_must_fail git rev-parse origin/extrabranch
+ )
'
test_expect_success 'fetch --prune with a branch name keeps branches' '
- cd "$D" &&
git clone . prune-branch &&
- cd prune-branch &&
- git update-ref refs/remotes/origin/extrabranch main &&
+ (
+ cd prune-branch &&
+ git update-ref refs/remotes/origin/extrabranch main &&
- git fetch --prune origin main &&
- git rev-parse origin/extrabranch
+ git fetch --prune origin main &&
+ git rev-parse origin/extrabranch
+ )
'
test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
- cd "$D" &&
git clone . prune-namespace &&
- cd prune-namespace &&
+ (
+ cd prune-namespace &&
- git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
- git rev-parse origin/main
+ git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
+ git rev-parse origin/main
+ )
'
test_expect_success 'fetch --prune handles overlapping refspecs' '
- cd "$D" &&
git update-ref refs/pull/42/head main &&
git clone . prune-overlapping &&
- cd prune-overlapping &&
- git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
+ (
+ cd prune-overlapping &&
+ git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
- git fetch --prune origin &&
- git rev-parse origin/main &&
- git rev-parse origin/pr/42 &&
+ git fetch --prune origin &&
+ git rev-parse origin/main &&
+ git rev-parse origin/pr/42 &&
- git config --unset-all remote.origin.fetch &&
- git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
- git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
+ git config --unset-all remote.origin.fetch &&
+ git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
+ git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
- git fetch --prune origin &&
- git rev-parse origin/main &&
- git rev-parse origin/pr/42
+ git fetch --prune origin &&
+ git rev-parse origin/main &&
+ git rev-parse origin/pr/42
+ )
'
test_expect_success 'fetch --prune --tags prunes branches but not tags' '
- cd "$D" &&
git clone . prune-tags &&
- cd prune-tags &&
- git tag sometag main &&
- # Create what looks like a remote-tracking branch from an earlier
- # fetch that has since been deleted from the remote:
- git update-ref refs/remotes/origin/fake-remote main &&
-
- git fetch --prune --tags origin &&
- git rev-parse origin/main &&
- test_must_fail git rev-parse origin/fake-remote &&
- git rev-parse sometag
+ (
+ cd prune-tags &&
+ git tag sometag main &&
+ # Create what looks like a remote-tracking branch from an earlier
+ # fetch that has since been deleted from the remote:
+ git update-ref refs/remotes/origin/fake-remote main &&
+
+ git fetch --prune --tags origin &&
+ git rev-parse origin/main &&
+ test_must_fail git rev-parse origin/fake-remote &&
+ git rev-parse sometag
+ )
'
test_expect_success 'fetch --prune --tags with branch does not prune other things' '
- cd "$D" &&
git clone . prune-tags-branch &&
- cd prune-tags-branch &&
- git tag sometag main &&
- git update-ref refs/remotes/origin/extrabranch main &&
+ (
+ cd prune-tags-branch &&
+ git tag sometag main &&
+ git update-ref refs/remotes/origin/extrabranch main &&
- git fetch --prune --tags origin main &&
- git rev-parse origin/extrabranch &&
- git rev-parse sometag
+ git fetch --prune --tags origin main &&
+ git rev-parse origin/extrabranch &&
+ git rev-parse sometag
+ )
'
test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' '
- cd "$D" &&
git clone . prune-tags-refspec &&
- cd prune-tags-refspec &&
- git tag sometag main &&
- git update-ref refs/remotes/origin/foo/otherbranch main &&
- git update-ref refs/remotes/origin/extrabranch main &&
-
- git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
- test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
- git rev-parse origin/extrabranch &&
- git rev-parse sometag
+ (
+ cd prune-tags-refspec &&
+ git tag sometag main &&
+ git update-ref refs/remotes/origin/foo/otherbranch main &&
+ git update-ref refs/remotes/origin/extrabranch main &&
+
+ git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
+ test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
+ git rev-parse origin/extrabranch &&
+ git rev-parse sometag
+ )
'
test_expect_success 'fetch --tags gets tags even without a configured remote' '
@@ -344,21 +356,21 @@ test_expect_success 'fetch --tags gets tags even without a configured remote' '
'
test_expect_success REFFILES 'fetch --prune fails to delete branches' '
- cd "$D" &&
git clone . prune-fail &&
- cd prune-fail &&
- git update-ref refs/remotes/origin/extrabranch main &&
- git pack-refs --all &&
- : this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds &&
- >.git/packed-refs.new &&
+ (
+ cd prune-fail &&
+ git update-ref refs/remotes/origin/extrabranch main &&
+ git pack-refs --all &&
+ : this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds &&
+ >.git/packed-refs.new &&
- test_must_fail git fetch --prune origin
+ test_must_fail git fetch --prune origin
+ )
'
test_expect_success 'fetch --atomic works with a single branch' '
- test_when_finished "rm -rf \"$D\"/atomic" &&
+ test_when_finished "rm -rf atomic" &&
- cd "$D" &&
git clone . atomic &&
git branch atomic-branch &&
oid=$(git rev-parse atomic-branch) &&
@@ -371,9 +383,8 @@ test_expect_success 'fetch --atomic works with a single branch' '
'
test_expect_success 'fetch --atomic works with multiple branches' '
- test_when_finished "rm -rf \"$D\"/atomic" &&
+ test_when_finished "rm -rf atomic" &&
- cd "$D" &&
git clone . atomic &&
git branch atomic-branch-1 &&
git branch atomic-branch-2 &&
@@ -386,9 +397,8 @@ test_expect_success 'fetch --atomic works with multiple branches' '
'
test_expect_success 'fetch --atomic works with mixed branches and tags' '
- test_when_finished "rm -rf \"$D\"/atomic" &&
+ test_when_finished "rm -rf atomic" &&
- cd "$D" &&
git clone . atomic &&
git branch atomic-mixed-branch &&
git tag atomic-mixed-tag &&
@@ -400,9 +410,8 @@ test_expect_success 'fetch --atomic works with mixed branches and tags' '
'
test_expect_success 'fetch --atomic prunes references' '
- test_when_finished "rm -rf \"$D\"/atomic" &&
+ test_when_finished "rm -rf atomic" &&
- cd "$D" &&
git branch atomic-prune-delete &&
git clone . atomic &&
git branch --delete atomic-prune-delete &&
@@ -416,9 +425,8 @@ test_expect_success 'fetch --atomic prunes references' '
'
test_expect_success 'fetch --atomic aborts with non-fast-forward update' '
- test_when_finished "rm -rf \"$D\"/atomic" &&
+ test_when_finished "rm -rf atomic" &&
- cd "$D" &&
git branch atomic-non-ff &&
git clone . atomic &&
git rev-parse HEAD >actual &&
@@ -435,9 +443,8 @@ test_expect_success 'fetch --atomic aborts with non-fast-forward update' '
'
test_expect_success 'fetch --atomic executes a single reference transaction only' '
- test_when_finished "rm -rf \"$D\"/atomic" &&
+ test_when_finished "rm -rf atomic" &&
- cd "$D" &&
git clone . atomic &&
git branch atomic-hooks-1 &&
git branch atomic-hooks-2 &&
@@ -462,9 +469,8 @@ test_expect_success 'fetch --atomic executes a single reference transaction only
'
test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' '
- test_when_finished "rm -rf \"$D\"/atomic" &&
+ test_when_finished "rm -rf atomic" &&
- cd "$D" &&
git clone . atomic &&
git branch atomic-hooks-abort-1 &&
git branch atomic-hooks-abort-2 &&
@@ -499,9 +505,8 @@ test_expect_success 'fetch --atomic aborts all reference updates if hook aborts'
'
test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
- test_when_finished "rm -rf \"$D\"/atomic" &&
+ test_when_finished "rm -rf atomic" &&
- cd "$D" &&
git clone . atomic &&
oid=$(git rev-parse HEAD) &&
@@ -523,9 +528,21 @@ test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
test_cmp expected atomic/.git/FETCH_HEAD
'
+test_expect_success REFFILES 'fetch --atomic fails transaction if reference locked' '
+ test_when_finished "rm -rf upstream repo" &&
+
+ git init upstream &&
+ git -C upstream commit --allow-empty -m 1 &&
+ git -C upstream switch -c foobar &&
+ git clone --mirror upstream repo &&
+ git -C upstream commit --allow-empty -m 2 &&
+ touch repo/refs/heads/foobar.lock &&
+
+ test_must_fail git -C repo fetch --atomic origin
+'
+
test_expect_success '--refmap="" ignores configured refspec' '
- cd "$TRASH_DIRECTORY" &&
- git clone "$D" remote-refs &&
+ git clone . remote-refs &&
git -C remote-refs rev-parse remotes/origin/main >old &&
git -C remote-refs update-ref refs/remotes/origin/main main~1 &&
git -C remote-refs rev-parse remotes/origin/main >new &&
@@ -549,34 +566,26 @@ test_expect_success '--refmap="" and --prune' '
test_expect_success 'fetch tags when there is no tags' '
- cd "$D" &&
-
- mkdir notags &&
- cd notags &&
- git init &&
-
- git fetch -t ..
+ git init notags &&
+ git -C notags fetch -t ..
'
test_expect_success 'fetch following tags' '
- cd "$D" &&
git tag -a -m "annotated" anno HEAD &&
git tag light HEAD &&
- mkdir four &&
- cd four &&
- git init &&
-
- git fetch .. :track &&
- git show-ref --verify refs/tags/anno &&
- git show-ref --verify refs/tags/light
-
+ git init four &&
+ (
+ cd four &&
+ git fetch .. :track &&
+ git show-ref --verify refs/tags/anno &&
+ git show-ref --verify refs/tags/light
+ )
'
test_expect_success 'fetch uses remote ref names to describe new refs' '
- cd "$D" &&
git init descriptive &&
(
cd descriptive &&
@@ -604,30 +613,20 @@ test_expect_success 'fetch uses remote ref names to describe new refs' '
test_expect_success 'fetch must not resolve short tag name' '
- cd "$D" &&
-
- mkdir five &&
- cd five &&
- git init &&
-
- test_must_fail git fetch .. anno:five
+ git init five &&
+ test_must_fail git -C five fetch .. anno:five
'
test_expect_success 'fetch can now resolve short remote name' '
- cd "$D" &&
git update-ref refs/remotes/six/HEAD HEAD &&
- mkdir six &&
- cd six &&
- git init &&
-
- git fetch .. six:six
+ git init six &&
+ git -C six fetch .. six:six
'
test_expect_success 'create bundle 1' '
- cd "$D" &&
echo >file updated again by origin &&
git commit -a -m "tip" &&
git bundle create --version=3 bundle1 main^..main
@@ -641,35 +640,36 @@ test_expect_success 'header of bundle looks right' '
OID refs/heads/main
EOF
- sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
+ sed -e "s/$OID_REGEX/OID/g" -e "5q" bundle1 >actual &&
test_cmp expect actual
'
test_expect_success 'create bundle 2' '
- cd "$D" &&
git bundle create bundle2 main~2..main
'
test_expect_success 'unbundle 1' '
- cd "$D/bundle" &&
- git checkout -b some-branch &&
- test_must_fail git fetch "$D/bundle1" main:main
+ (
+ cd bundle &&
+ git checkout -b some-branch &&
+ test_must_fail git fetch bundle1 main:main
+ )
'
test_expect_success 'bundle 1 has only 3 files ' '
- cd "$D" &&
test_bundle_object_count bundle1 3
'
test_expect_success 'unbundle 2' '
- cd "$D/bundle" &&
- git fetch ../bundle2 main:main &&
- test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)"
+ (
+ cd bundle &&
+ git fetch ../bundle2 main:main &&
+ test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)"
+ )
'
test_expect_success 'bundle does not prerequisite objects' '
- cd "$D" &&
touch file2 &&
git add file2 &&
git commit -m add.file2 file2 &&
@@ -679,7 +679,6 @@ test_expect_success 'bundle does not prerequisite objects' '
test_expect_success 'bundle should be able to create a full history' '
- cd "$D" &&
git tag -a -m "1.0" v1.0 main &&
git bundle create bundle4 v1.0
@@ -733,7 +732,6 @@ test_expect_success 'quoting of a strangely named repo' '
test_expect_success 'bundle should record HEAD correctly' '
- cd "$D" &&
git bundle create bundle5 HEAD main &&
git bundle list-heads bundle5 >actual &&
for h in HEAD refs/heads/main
@@ -753,7 +751,6 @@ test_expect_success 'mark initial state of origin/main' '
test_expect_success 'explicit fetch should update tracking' '
- cd "$D" &&
git branch -f side &&
(
cd three &&
@@ -768,7 +765,6 @@ test_expect_success 'explicit fetch should update tracking' '
test_expect_success 'explicit pull should update tracking' '
- cd "$D" &&
git branch -f side &&
(
cd three &&
@@ -782,7 +778,6 @@ test_expect_success 'explicit pull should update tracking' '
'
test_expect_success 'explicit --refmap is allowed only with command-line refspec' '
- cd "$D" &&
(
cd three &&
test_must_fail git fetch --refmap="*:refs/remotes/none/*"
@@ -790,7 +785,6 @@ test_expect_success 'explicit --refmap is allowed only with command-line refspec
'
test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
- cd "$D" &&
git branch -f side &&
(
cd three &&
@@ -805,7 +799,6 @@ test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
'
test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
- cd "$D" &&
git branch -f side &&
(
cd three &&
@@ -820,7 +813,6 @@ test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
test_expect_success 'configured fetch updates tracking' '
- cd "$D" &&
git branch -f side &&
(
cd three &&
@@ -834,7 +826,6 @@ test_expect_success 'configured fetch updates tracking' '
'
test_expect_success 'non-matching refspecs do not confuse tracking update' '
- cd "$D" &&
git update-ref refs/odd/location HEAD &&
(
cd three &&
@@ -851,14 +842,12 @@ test_expect_success 'non-matching refspecs do not confuse tracking update' '
test_expect_success 'pushing nonexistent branch by mistake should not segv' '
- cd "$D" &&
test_must_fail git push seven no:no
'
test_expect_success 'auto tag following fetches minimum' '
- cd "$D" &&
git clone .git follow &&
git checkout HEAD^0 &&
(
@@ -1240,7 +1229,12 @@ test_expect_success 'all boundary commits are excluded' '
test_tick &&
git merge otherside &&
ad=$(git log --no-walk --format=%ad HEAD) &&
- git bundle create twoside-boundary.bdl main --since="$ad" &&
+
+ # If the a different name hash function is used here, then no delta
+ # pair is found and the bundle does not expand to three objects
+ # when fixing the thin object.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git bundle create twoside-boundary.bdl main --since="$ad" &&
test_bundle_object_count --thin twoside-boundary.bdl 3
'
@@ -1252,7 +1246,7 @@ test_expect_success 'fetch --prune prints the remotes url' '
cd only-prunes &&
git fetch --prune origin 2>&1 | head -n1 >../actual
) &&
- echo "From ${D}/." >expect &&
+ echo "From $(pwd)/." >expect &&
test_cmp expect actual
'
@@ -1302,14 +1296,14 @@ test_expect_success 'fetching with auto-gc does not lock up' '
echo "$*" &&
false
EOF
- git clone "file://$D" auto-gc &&
+ git clone "file://$PWD" auto-gc &&
test_commit test2 &&
(
cd auto-gc &&
git config fetch.unpackLimit 1 &&
git config gc.autoPackLimit 1 &&
git config gc.autoDetach false &&
- GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
+ GIT_ASK_YESNO="$TRASH_DIRECTORY/askyesno" git fetch --verbose >fetch.out 2>&1 &&
test_grep "Auto packing the repository" fetch.out &&
! grep "Should I try again" fetch.out
)
diff --git a/t/t5515-fetch-merge-logic.sh b/t/t5515-fetch-merge-logic.sh
index 320d26796d..8ac04d742c 100755
--- a/t/t5515-fetch-merge-logic.sh
+++ b/t/t5515-fetch-merge-logic.sh
@@ -104,28 +104,31 @@ test_expect_success setup '
git config remote.config-glob.fetch refs/heads/*:refs/remotes/rem/* &&
remotes="$remotes config-glob" &&
- mkdir -p .git/remotes &&
- cat >.git/remotes/remote-explicit <<-\EOF &&
- URL: ../.git/
- Pull: refs/heads/main:remotes/rem/main
- Pull: refs/heads/one:remotes/rem/one
- Pull: two:remotes/rem/two
- Pull: refs/heads/three:remotes/rem/three
- EOF
- remotes="$remotes remote-explicit" &&
-
- cat >.git/remotes/remote-glob <<-\EOF &&
- URL: ../.git/
- Pull: refs/heads/*:refs/remotes/rem/*
- EOF
- remotes="$remotes remote-glob" &&
-
- mkdir -p .git/branches &&
- echo "../.git" > .git/branches/branches-default &&
- remotes="$remotes branches-default" &&
-
- echo "../.git#one" > .git/branches/branches-one &&
- remotes="$remotes branches-one" &&
+ if ! test_have_prereq WITH_BREAKING_CHANGES
+ then
+ mkdir -p .git/remotes &&
+ cat >.git/remotes/remote-explicit <<-\EOF &&
+ URL: ../.git/
+ Pull: refs/heads/main:remotes/rem/main
+ Pull: refs/heads/one:remotes/rem/one
+ Pull: two:remotes/rem/two
+ Pull: refs/heads/three:remotes/rem/three
+ EOF
+ remotes="$remotes remote-explicit" &&
+
+ cat >.git/remotes/remote-glob <<-\EOF &&
+ URL: ../.git/
+ Pull: refs/heads/*:refs/remotes/rem/*
+ EOF
+ remotes="$remotes remote-glob" &&
+
+ mkdir -p .git/branches &&
+ echo "../.git" > .git/branches/branches-default &&
+ remotes="$remotes branches-default" &&
+
+ echo "../.git#one" > .git/branches/branches-one &&
+ remotes="$remotes branches-one"
+ fi &&
for remote in $remotes ; do
git config branch.br-$remote.remote $remote &&
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 041d7d806f..46926e7bbd 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -105,7 +105,6 @@ check_push_result () {
}
test_expect_success setup '
-
>path1 &&
git add path1 &&
test_tick &&
@@ -117,7 +116,6 @@ test_expect_success setup '
test_tick &&
git commit -a -m second &&
the_commit=$(git show-ref -s --verify refs/heads/main)
-
'
for cmd in push fetch
@@ -322,104 +320,82 @@ test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf
'
test_expect_success 'push with matching heads' '
-
mk_test testrepo heads/main &&
git push testrepo : &&
check_push_result testrepo $the_commit heads/main
-
'
test_expect_success 'push with matching heads on the command line' '
-
mk_test testrepo heads/main &&
git push testrepo : &&
check_push_result testrepo $the_commit heads/main
-
'
test_expect_success 'failed (non-fast-forward) push with matching heads' '
-
mk_test testrepo heads/main &&
git push testrepo : &&
git commit --amend -massaged &&
test_must_fail git push testrepo &&
check_push_result testrepo $the_commit heads/main &&
git reset --hard $the_commit
-
'
test_expect_success 'push --force with matching heads' '
-
mk_test testrepo heads/main &&
git push testrepo : &&
git commit --amend -massaged &&
git push --force testrepo : &&
! check_push_result testrepo $the_commit heads/main &&
git reset --hard $the_commit
-
'
test_expect_success 'push with matching heads and forced update' '
-
mk_test testrepo heads/main &&
git push testrepo : &&
git commit --amend -massaged &&
git push testrepo +: &&
! check_push_result testrepo $the_commit heads/main &&
git reset --hard $the_commit
-
'
test_expect_success 'push with no ambiguity (1)' '
-
mk_test testrepo heads/main &&
git push testrepo main:main &&
check_push_result testrepo $the_commit heads/main
-
'
test_expect_success 'push with no ambiguity (2)' '
-
mk_test testrepo remotes/origin/main &&
git push testrepo main:origin/main &&
check_push_result testrepo $the_commit remotes/origin/main
-
'
test_expect_success 'push with colon-less refspec, no ambiguity' '
-
mk_test testrepo heads/main heads/t/main &&
git branch -f t/main main &&
git push testrepo main &&
check_push_result testrepo $the_commit heads/main &&
check_push_result testrepo $the_first_commit heads/t/main
-
'
test_expect_success 'push with weak ambiguity (1)' '
-
mk_test testrepo heads/main remotes/origin/main &&
git push testrepo main:main &&
check_push_result testrepo $the_commit heads/main &&
check_push_result testrepo $the_first_commit remotes/origin/main
-
'
test_expect_success 'push with weak ambiguity (2)' '
-
mk_test testrepo heads/main remotes/origin/main remotes/another/main &&
git push testrepo main:main &&
check_push_result testrepo $the_commit heads/main &&
check_push_result testrepo $the_first_commit remotes/origin/main remotes/another/main
-
'
test_expect_success 'push with ambiguity' '
-
mk_test testrepo heads/frotz tags/frotz &&
test_must_fail git push testrepo main:frotz &&
check_push_result testrepo $the_first_commit heads/frotz tags/frotz
-
'
test_expect_success 'push with onelevel ref' '
@@ -428,17 +404,14 @@ test_expect_success 'push with onelevel ref' '
'
test_expect_success 'push with colon-less refspec (1)' '
-
mk_test testrepo heads/frotz tags/frotz &&
git branch -f frotz main &&
git push testrepo frotz &&
check_push_result testrepo $the_commit heads/frotz &&
check_push_result testrepo $the_first_commit tags/frotz
-
'
test_expect_success 'push with colon-less refspec (2)' '
-
mk_test testrepo heads/frotz tags/frotz &&
if git show-ref --verify -q refs/heads/frotz
then
@@ -448,7 +421,6 @@ test_expect_success 'push with colon-less refspec (2)' '
git push -f testrepo frotz &&
check_push_result testrepo $the_commit tags/frotz &&
check_push_result testrepo $the_first_commit heads/frotz
-
'
test_expect_success 'push with colon-less refspec (3)' '
@@ -465,7 +437,6 @@ test_expect_success 'push with colon-less refspec (3)' '
'
test_expect_success 'push with colon-less refspec (4)' '
-
mk_test testrepo &&
if git show-ref --verify -q refs/heads/frotz
then
@@ -475,38 +446,34 @@ test_expect_success 'push with colon-less refspec (4)' '
git push testrepo frotz &&
check_push_result testrepo $the_commit tags/frotz &&
test 1 = $( cd testrepo && git show-ref | wc -l )
-
'
test_expect_success 'push head with non-existent, incomplete dest' '
-
mk_test testrepo &&
git push testrepo main:branch &&
check_push_result testrepo $the_commit heads/branch
-
'
test_expect_success 'push tag with non-existent, incomplete dest' '
-
mk_test testrepo &&
git tag -f v1.0 &&
git push testrepo v1.0:tag &&
check_push_result testrepo $the_commit tags/tag
-
'
-test_expect_success 'push sha1 with non-existent, incomplete dest' '
-
+test_expect_success 'push oid with non-existent, incomplete dest' '
mk_test testrepo &&
test_must_fail git push testrepo $(git rev-parse main):foo
-
'
test_expect_success 'push ref expression with non-existent, incomplete dest' '
-
mk_test testrepo &&
test_must_fail git push testrepo main^:branch
+'
+test_expect_success 'push ref expression with non-existent oid src' '
+ mk_test testrepo &&
+ test_must_fail git push testrepo $(test_oid 001):branch
'
for head in HEAD @
@@ -550,7 +517,6 @@ do
git checkout main &&
git push testrepo $head:branch &&
check_push_result testrepo $the_commit heads/branch
-
'
test_expect_success "push with config remote.*.push = $head" '
@@ -596,7 +562,6 @@ test_expect_success 'push with remote.pushdefault' '
'
test_expect_success 'push with config remote.*.pushurl' '
-
mk_test testrepo heads/main &&
git checkout main &&
test_config remote.there.url test2repo &&
@@ -655,7 +620,6 @@ test_expect_success 'push ignores "branch." config without subsection' '
'
test_expect_success 'push with dry-run' '
-
mk_test testrepo heads/main &&
old_commit=$(git -C testrepo show-ref -s --verify refs/heads/main) &&
git push --dry-run testrepo : &&
@@ -663,7 +627,6 @@ test_expect_success 'push with dry-run' '
'
test_expect_success 'push updates local refs' '
-
mk_test testrepo heads/main &&
mk_child testrepo child &&
(
@@ -673,11 +636,9 @@ test_expect_success 'push updates local refs' '
test $(git rev-parse main) = \
$(git rev-parse remotes/origin/main)
)
-
'
test_expect_success 'push updates up-to-date local refs' '
-
mk_test testrepo heads/main &&
mk_child testrepo child1 &&
mk_child testrepo child2 &&
@@ -689,11 +650,9 @@ test_expect_success 'push updates up-to-date local refs' '
test $(git rev-parse main) = \
$(git rev-parse remotes/origin/main)
)
-
'
test_expect_success 'push preserves up-to-date packed refs' '
-
mk_test testrepo heads/main &&
mk_child testrepo child &&
(
@@ -701,11 +660,9 @@ test_expect_success 'push preserves up-to-date packed refs' '
git push &&
! test -f .git/refs/remotes/origin/main
)
-
'
test_expect_success 'push does not update local refs on failure' '
-
mk_test testrepo heads/main &&
mk_child testrepo child &&
echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
@@ -717,16 +674,13 @@ test_expect_success 'push does not update local refs on failure' '
test $(git rev-parse main) != \
$(git rev-parse remotes/origin/main)
)
-
'
test_expect_success 'allow deleting an invalid remote ref' '
-
mk_test testrepo heads/branch &&
rm -f testrepo/.git/objects/??/* &&
git push testrepo :refs/heads/branch &&
(cd testrepo && test_must_fail git rev-parse --verify refs/heads/branch)
-
'
test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
@@ -744,8 +698,8 @@ test_expect_success 'pushing valid refs triggers post-receive and post-update ho
EOF
cat >update.expect <<-EOF &&
- refs/heads/main $orgmain $newmain
refs/heads/next $orgnext $newnext
+ refs/heads/main $orgmain $newmain
EOF
cat >post-receive.expect <<-EOF &&
@@ -808,8 +762,8 @@ test_expect_success 'deletion of a non-existent ref is not fed to post-receive a
EOF
cat >update.expect <<-EOF &&
- refs/heads/main $orgmain $newmain
refs/heads/nonexistent $ZERO_OID $ZERO_OID
+ refs/heads/main $orgmain $newmain
EOF
cat >post-receive.expect <<-EOF &&
@@ -868,10 +822,10 @@ test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks w
EOF
cat >update.expect <<-EOF &&
- refs/heads/main $orgmain $newmain
refs/heads/next $orgnext $newnext
- refs/heads/seen $orgseen $newseen
refs/heads/nonexistent $ZERO_OID $ZERO_OID
+ refs/heads/main $orgmain $newmain
+ refs/heads/seen $orgseen $newseen
EOF
cat >post-receive.expect <<-EOF &&
@@ -975,7 +929,7 @@ test_expect_success 'allow push to HEAD of non-bare repository (config)' '
! grep "warning: updating the current branch" stderr
'
-test_expect_success 'fetch with branches' '
+test_expect_success !WITH_BREAKING_CHANGES 'fetch with branches' '
mk_empty testrepo &&
git branch second $the_first_commit &&
git checkout second &&
@@ -991,7 +945,7 @@ test_expect_success 'fetch with branches' '
git checkout main
'
-test_expect_success 'fetch with branches containing #' '
+test_expect_success !WITH_BREAKING_CHANGES 'fetch with branches containing #' '
mk_empty testrepo &&
mkdir testrepo/.git/branches &&
echo "..#second" > testrepo/.git/branches/branch2 &&
@@ -1005,7 +959,7 @@ test_expect_success 'fetch with branches containing #' '
git checkout main
'
-test_expect_success 'push with branches' '
+test_expect_success !WITH_BREAKING_CHANGES 'push with branches' '
mk_empty testrepo &&
git checkout second &&
@@ -1022,7 +976,7 @@ test_expect_success 'push with branches' '
)
'
-test_expect_success 'push with branches containing #' '
+test_expect_success !WITH_BREAKING_CHANGES 'push with branches containing #' '
mk_empty testrepo &&
test_when_finished "rm -rf .git/branches" &&
@@ -1211,18 +1165,16 @@ test_expect_success 'push --porcelain --dry-run rejected' '
'
test_expect_success 'push --prune' '
- mk_test testrepo heads/main heads/second heads/foo heads/bar &&
+ mk_test testrepo heads/main heads/foo heads/bar &&
git push --prune testrepo : &&
check_push_result testrepo $the_commit heads/main &&
- check_push_result testrepo $the_first_commit heads/second &&
! check_push_result testrepo $the_first_commit heads/foo heads/bar
'
test_expect_success 'push --prune refspec' '
- mk_test testrepo tmp/main tmp/second tmp/foo tmp/bar &&
+ mk_test testrepo tmp/main tmp/foo tmp/bar &&
git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
check_push_result testrepo $the_commit tmp/main &&
- check_push_result testrepo $the_first_commit tmp/second &&
! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
'
@@ -1253,7 +1205,7 @@ do
'
done
-test_expect_success 'fetch exact SHA1' '
+test_expect_success 'fetch exact oid' '
mk_test testrepo heads/main hidden/one &&
git push testrepo main:refs/hidden/one &&
(
@@ -1299,7 +1251,7 @@ test_expect_success 'fetch exact SHA1' '
)
'
-test_expect_success 'fetch exact SHA1 in protocol v2' '
+test_expect_success 'fetch exact oid in protocol v2' '
mk_test testrepo heads/main hidden/one &&
git push testrepo main:refs/hidden/one &&
git -C testrepo config transfer.hiderefs refs/hidden &&
@@ -1314,8 +1266,10 @@ test_expect_success 'fetch exact SHA1 in protocol v2' '
test_must_fail git -C child cat-file -t $the_commit &&
# fetching the hidden object succeeds by default
- # NEEDSWORK: should this match the v0 behavior instead?
- git -C child fetch -v ../testrepo $the_commit:refs/heads/copy
+ GIT_TRACE_PACKET=$PWD/trace.out \
+ git -C child fetch -v ../testrepo $the_commit:refs/heads/copy &&
+
+ test_grep ! "ref-prefix.*$the_commit" trace.out
'
for configallowtipsha1inwant in true false
@@ -1909,4 +1863,23 @@ test_expect_success 'push with config push.useBitmaps' '
--thin --delta-base-offset -q --no-use-bitmap-index <false
'
+test_expect_success 'push with config pack.usePathWalk=true' '
+ mk_test testrepo heads/main &&
+ git checkout main &&
+ test_config pack.usePathWalk true &&
+ GIT_TRACE2_EVENT="$(pwd)/path-walk.txt" \
+ git push --quiet testrepo main:test &&
+
+ test_region pack-objects path-walk path-walk.txt
+'
+
+test_expect_success 'push with F/D conflict with deletion and creation' '
+ test_when_finished "git branch -D branch" &&
+ git branch branch/conflict &&
+ mk_test testrepo heads/branch/conflict &&
+ git branch -D branch/conflict &&
+ git branch branch &&
+ git push testrepo :refs/heads/branch/conflict refs/heads/branch
+'
+
test_done
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 47534f1062..0e0019347e 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -472,6 +472,66 @@ test_expect_success 'pull --no-autostash & merge.autostash unset' '
test_pull_autostash_fail --no-autostash --no-rebase
'
+test_expect_success 'pull succeeds with dirty working directory and pull.autostash=true' '
+ test_config pull.autostash true &&
+ test_pull_autostash 1 --rebase &&
+ test_pull_autostash 2 --no-rebase &&
+ test_pull_autostash 1 --autostash --rebase &&
+ test_pull_autostash 2 --autostash --no-rebase
+'
+
+test_expect_success 'pull fails with dirty working directory and pull.autostash=false' '
+ test_config pull.autostash false &&
+ test_pull_autostash_fail --rebase &&
+ test_pull_autostash_fail --no-rebase &&
+ test_pull_autostash_fail --no-autostash --rebase &&
+ test_pull_autostash_fail --no-autostash --no-rebase
+'
+
+test_expect_success 'pull --autostash overrides pull.autostash=false' '
+ test_config pull.autostash false &&
+ test_pull_autostash 1 --autostash --rebase &&
+ test_pull_autostash 2 --autostash --no-rebase
+'
+
+test_expect_success 'pull --no-autostash overrides pull.autostash=true' '
+ test_config pull.autostash true &&
+ test_pull_autostash_fail --no-autostash --rebase &&
+ test_pull_autostash_fail --no-autostash --no-rebase
+'
+
+test_expect_success 'pull.autostash=true overrides rebase.autostash' '
+ test_config pull.autostash true &&
+ test_config rebase.autostash true &&
+ test_pull_autostash 1 --rebase &&
+ test_config rebase.autostash false &&
+ test_pull_autostash 1 --rebase
+'
+
+test_expect_success 'pull.autostash=false overrides rebase.autostash' '
+ test_config pull.autostash false &&
+ test_config rebase.autostash true &&
+ test_pull_autostash_fail --rebase &&
+ test_config rebase.autostash false &&
+ test_pull_autostash_fail --rebase
+'
+
+test_expect_success 'pull.autostash=true overrides merge.autostash' '
+ test_config pull.autostash true &&
+ test_config merge.autostash true &&
+ test_pull_autostash 2 --no-rebase &&
+ test_config merge.autostash false &&
+ test_pull_autostash 2 --no-rebase
+'
+
+test_expect_success 'pull.autostash=false overrides merge.autostash' '
+ test_config pull.autostash false &&
+ test_config merge.autostash true &&
+ test_pull_autostash_fail --no-rebase &&
+ test_config merge.autostash false &&
+ test_pull_autostash_fail --no-rebase
+'
+
test_expect_success 'pull.rebase' '
git reset --hard before-rebase &&
test_config pull.rebase true &&
@@ -813,7 +873,7 @@ test_expect_success 'git pull --rebase does not reapply old patches' '
cd dst &&
test_must_fail git pull --rebase &&
cat .git/rebase-merge/done .git/rebase-merge/git-rebase-todo >work &&
- grep -v -e \# -e ^$ work >patches &&
+ grep -v -e ^\# -e ^$ work >patches &&
test_line_count = 1 patches &&
rm -f work
)
diff --git a/t/t5530-upload-pack-error.sh b/t/t5530-upload-pack-error.sh
index 558eedf25a..d40292cfb7 100755
--- a/t/t5530-upload-pack-error.sh
+++ b/t/t5530-upload-pack-error.sh
@@ -4,8 +4,6 @@ test_description='errors in upload-pack'
. ./test-lib.sh
-D=$(pwd)
-
corrupt_repo () {
object_sha1=$(git rev-parse "$1") &&
ob=$(expr "$object_sha1" : "\(..\)") &&
@@ -21,11 +19,7 @@ test_expect_success 'setup and corrupt repository' '
test_tick &&
echo changed >file &&
git commit -a -m changed &&
- corrupt_repo HEAD:file
-
-'
-
-test_expect_success 'fsck fails' '
+ corrupt_repo HEAD:file &&
test_must_fail git fsck
'
@@ -40,17 +34,12 @@ test_expect_success 'upload-pack fails due to error in pack-objects packing' '
'
test_expect_success 'corrupt repo differently' '
-
git hash-object -w file &&
- corrupt_repo HEAD^^{tree}
-
-'
-
-test_expect_success 'fsck fails' '
+ corrupt_repo HEAD^^{tree} &&
test_must_fail git fsck
'
-test_expect_success 'upload-pack fails due to error in rev-list' '
+test_expect_success 'upload-pack fails due to error in rev-list' '
printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \
$(($hexsz + 10)) $(git rev-parse HEAD) \
$(($hexsz + 12)) $(git rev-parse HEAD^) >input &&
@@ -59,7 +48,6 @@ test_expect_success 'upload-pack fails due to error in rev-list' '
'
test_expect_success 'upload-pack fails due to bad want (no object)' '
-
printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
$(($hexsz + 29)) $(test_oid deadbeef) >input &&
test_must_fail git upload-pack . <input >output 2>output.err &&
@@ -69,7 +57,6 @@ test_expect_success 'upload-pack fails due to bad want (no object)' '
'
test_expect_success 'upload-pack fails due to bad want (not tip)' '
-
oid=$(echo an object we have | git hash-object -w --stdin) &&
printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
$(($hexsz + 29)) "$oid" >input &&
@@ -80,7 +67,6 @@ test_expect_success 'upload-pack fails due to bad want (not tip)' '
'
test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
-
printf "%04xwant %s\n00000009done\n0000" \
$((hexsz + 10)) $(git rev-parse HEAD) >input &&
test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
@@ -105,18 +91,48 @@ test_expect_success 'upload-pack tolerates EOF just after stateless client wants
test_cmp expect actual
'
-test_expect_success 'create empty repository' '
-
- mkdir foo &&
- cd foo &&
- git init
-
-'
-
test_expect_success 'fetch fails' '
+ git init foo &&
+ test_must_fail git -C foo fetch .. main
+'
- test_must_fail git fetch .. main
+test_expect_success 'upload-pack ACKs repeated non-commit objects repeatedly (protocol v0)' '
+ commit_id=$(git rev-parse HEAD) &&
+ tree_id=$(git rev-parse HEAD^{tree}) &&
+ test-tool pkt-line pack >request <<-EOF &&
+ want $commit_id
+ 0000
+ have $tree_id
+ have $tree_id
+ 0000
+ EOF
+ git upload-pack --stateless-rpc . <request >actual &&
+ depacketize <actual >actual.raw &&
+ grep ^ACK actual.raw >actual.acks &&
+ cat >expect <<-EOF &&
+ ACK $tree_id
+ ACK $tree_id
+ EOF
+ test_cmp expect actual.acks
+'
+test_expect_success 'upload-pack ACKs repeated non-commit objects once only (protocol v2)' '
+ commit_id=$(git rev-parse HEAD) &&
+ tree_id=$(git rev-parse HEAD^{tree}) &&
+ test-tool pkt-line pack >request <<-EOF &&
+ command=fetch
+ object-format=$(test_oid algo)
+ 0001
+ want $commit_id
+ have $tree_id
+ have $tree_id
+ 0000
+ EOF
+ GIT_PROTOCOL=version=2 git upload-pack . <request >actual &&
+ depacketize <actual >actual.raw &&
+ grep ^ACK actual.raw >actual.acks &&
+ echo "ACK $tree_id" >expect &&
+ test_cmp expect actual.acks
'
test_done
diff --git a/t/t5532-fetch-proxy.sh b/t/t5532-fetch-proxy.sh
index 3755822629..95d0f33b29 100755
--- a/t/t5532-fetch-proxy.sh
+++ b/t/t5532-fetch-proxy.sh
@@ -4,6 +4,12 @@ test_description='fetching via git:// using core.gitproxy'
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping fetch proxy tests; Perl not available'
+ test_done
+fi
+
test_expect_success 'setup remote repo' '
git init remote &&
(cd remote &&
diff --git a/t/t5534-push-signed.sh b/t/t5534-push-signed.sh
index c91a62b77a..2a782214ee 100755
--- a/t/t5534-push-signed.sh
+++ b/t/t5534-push-signed.sh
@@ -205,7 +205,7 @@ test_expect_success GPG 'inconsistent push options in signed push not allowed' '
# Tweak the push output to make the push option outside the cert
# different, then replay it on a fresh dst, checking that ff is not
# deleted.
- perl -pe "s/([^ ])bar/\$1baz/" push >push.tweak &&
+ sed "s/\([^ ]\)bar/\1baz/" push >push.tweak &&
prepare_dst &&
git -C dst config receive.certnonceseed sekrit &&
git -C dst config receive.advertisepushoptions 1 &&
diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh
index 37f7547a4c..6588ce6226 100755
--- a/t/t5537-fetch-shallow.sh
+++ b/t/t5537-fetch-shallow.sh
@@ -271,22 +271,21 @@ test_expect_success 'shallow fetches check connectivity before writing shallow f
git -C "$REPO" config protocol.version 2 &&
git -C client config protocol.version 2 &&
- git -C client fetch --depth=2 "$HTTPD_URL/one_time_perl/repo" main:a_branch &&
+ git -C client fetch --depth=2 "$HTTPD_URL/one_time_script/repo" main:a_branch &&
# Craft a situation in which the server sends back an unshallow request
# with an empty packfile. This is done by refetching with a shorter
# depth (to ensure that the packfile is empty), and overwriting the
# shallow line in the response with the unshallow line we want.
- printf "$(test_oid perl)" \
- "$(git -C "$REPO" rev-parse HEAD)" \
- "$(git -C "$REPO" rev-parse HEAD^)" \
- >"$HTTPD_ROOT_PATH/one-time-perl" &&
+ write_script "$HTTPD_ROOT_PATH/one-time-script" <<-EOF &&
+ sed "$(printf "$(test_oid perl)" "$(git -C "$REPO" rev-parse HEAD)" "$(git -C "$REPO" rev-parse HEAD^)")" "\$1"
+ EOF
test_must_fail env GIT_TEST_SIDEBAND_ALL=0 git -C client \
- fetch --depth=1 "$HTTPD_URL/one_time_perl/repo" \
+ fetch --depth=1 "$HTTPD_URL/one_time_script/repo" \
main:a_branch &&
- # Ensure that the one-time-perl script was used.
- ! test -e "$HTTPD_ROOT_PATH/one-time-perl" &&
+ # Ensure that the one-time-script script was used.
+ ! test -e "$HTTPD_ROOT_PATH/one-time-script" &&
# Ensure that the resulting repo is consistent, despite our failure to
# fetch.
diff --git a/t/t5538-push-shallow.sh b/t/t5538-push-shallow.sh
index e91fcc173e..dc0e972943 100755
--- a/t/t5538-push-shallow.sh
+++ b/t/t5538-push-shallow.sh
@@ -123,4 +123,45 @@ EOF
git cat-file blob $(echo 1|git hash-object --stdin) >/dev/null
)
'
+
+test_expect_success 'push new commit from shallow clone has correct object count' '
+ git init origin &&
+ test_commit -C origin a &&
+ test_commit -C origin b &&
+
+ git clone --depth=1 "file://$(pwd)/origin" client &&
+ git -C client checkout -b topic &&
+ git -C client commit --allow-empty -m "empty" &&
+ GIT_PROGRESS_DELAY=0 git -C client push --progress origin topic 2>err &&
+ test_grep "Enumerating objects: 1, done." err
+'
+
+test_expect_success 'push new commit from shallow clone has good deltas' '
+ git init base &&
+ test_seq 1 999 >base/a &&
+ test_commit -C base initial &&
+ git -C base add a &&
+ git -C base commit -m "big a" &&
+
+ git clone --depth=1 "file://$(pwd)/base" deltas &&
+ git -C deltas checkout -b deltas &&
+ test_seq 1 1000 >deltas/a &&
+ git -C deltas commit -a -m "bigger a" &&
+ GIT_PROGRESS_DELAY=0 git -C deltas push --progress origin deltas 2>err &&
+
+ test_grep "Enumerating objects: 5, done" err &&
+
+ # If the delta base is found, then this message uses "bytes".
+ # If the delta base is not found, then this message uses "KiB".
+ test_grep "Writing objects: .* bytes" err &&
+
+ git -C deltas commit --amend -m "changed message" &&
+ GIT_TRACE2_EVENT="$(pwd)/config-push.txt" \
+ GIT_PROGRESS_DELAY=0 git -C deltas -c pack.usePathWalk=true \
+ push --progress -f origin deltas 2>err &&
+
+ test_grep "Enumerating objects: 1, done" err &&
+ test_region pack-objects path-walk config-push.txt
+'
+
test_done
diff --git a/t/t5540-http-push-webdav.sh b/t/t5540-http-push-webdav.sh
index 37db3dec0c..3fa05ff185 100755
--- a/t/t5540-http-push-webdav.sh
+++ b/t/t5540-http-push-webdav.sh
@@ -201,4 +201,14 @@ test_expect_failure 'push to password-protected repository (no user in URL)' '
test_cmp expect actual
'
+test_expect_success 'push to password-protected repository (netrc)' '
+ test_commit pw-netrc &&
+ echo "default login user@host password pass@host" >"$HOME/.netrc" &&
+ GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
+ git rev-parse --verify HEAD >expect &&
+ git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
+ rev-parse --verify HEAD >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh
index 04b47ad84a..3a700b0676 100755
--- a/t/t5543-atomic-push.sh
+++ b/t/t5543-atomic-push.sh
@@ -280,4 +280,34 @@ test_expect_success 'atomic push reports (reject by non-ff)' '
test_cmp expect actual
'
+test_expect_success 'atomic push reports exit code failure' '
+ write_script receive-pack-wrapper <<-\EOF &&
+ git-receive-pack "$@"
+ exit 1
+ EOF
+ test_must_fail git -C workbench push --atomic \
+ --receive-pack="${SQ}$(pwd)${SQ}/receive-pack-wrapper" \
+ up HEAD:refs/heads/no-conflict 2>err &&
+ cat >expect <<-EOF &&
+ To ../upstream
+ * [new branch] HEAD -> no-conflict
+ error: failed to push some refs to ${SQ}../upstream${SQ}
+ EOF
+ test_cmp expect err
+'
+
+test_expect_success 'atomic push reports exit code failure with porcelain' '
+ write_script receive-pack-wrapper <<-\EOF &&
+ git-receive-pack "$@"
+ exit 1
+ EOF
+ test_must_fail git -C workbench push --atomic --porcelain \
+ --receive-pack="${SQ}$(pwd)${SQ}/receive-pack-wrapper" \
+ up HEAD:refs/heads/no-conflict-porcelain 2>err &&
+ cat >expect <<-EOF &&
+ error: failed to push some refs to ${SQ}../upstream${SQ}
+ EOF
+ test_cmp expect err
+'
+
test_done
diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh
index 6282728eaf..4c19404ebe 100755
--- a/t/t5548-push-porcelain.sh
+++ b/t/t5548-push-porcelain.sh
@@ -54,29 +54,67 @@ format_and_save_expect () {
sed -e 's/^> //' -e 's/Z$//' >expect
}
+create_upstream_template () {
+ git init --bare upstream-template.git &&
+ git clone upstream-template.git tmp_work_dir &&
+ create_commits_in tmp_work_dir A B &&
+ (
+ cd tmp_work_dir &&
+ git push origin \
+ $B:refs/heads/main \
+ $A:refs/heads/foo \
+ $A:refs/heads/bar \
+ $A:refs/heads/baz
+ ) &&
+ rm -rf tmp_work_dir
+}
+
+setup_upstream () {
+ if test $# -ne 1
+ then
+ BUG "location of upstream repository is not provided"
+ fi &&
+ rm -rf "$1" &&
+ if ! test -d upstream-template.git
+ then
+ create_upstream_template
+ fi &&
+ git clone --mirror upstream-template.git "$1" &&
+ # The upstream repository provides services using the HTTP protocol.
+ if ! test "$1" = "upstream.git"
+ then
+ git -C "$1" config http.receivepack true
+ fi
+}
+
setup_upstream_and_workbench () {
- # Upstream after setup : main(B) foo(A) bar(A) baz(A)
- # Workbench after setup : main(A)
+ if test $# -ne 1
+ then
+ BUG "location of upstream repository is not provided"
+ fi
+ upstream="$1"
+
+ # Upstream after setup: main(B) foo(A) bar(A) baz(A)
+ # Workbench after setup: main(A) baz(A) next(A)
test_expect_success "setup upstream repository and workbench" '
- rm -rf upstream.git workbench &&
- git init --bare upstream.git &&
- git init workbench &&
- create_commits_in workbench A B &&
+ setup_upstream "$upstream" &&
+ rm -rf workbench &&
+ git clone "$upstream" workbench &&
(
cd workbench &&
+ git update-ref refs/heads/main $A &&
+ git update-ref refs/heads/baz $A &&
+ git update-ref refs/heads/next $A &&
# Try to make a stable fixed width for abbreviated commit ID,
# this fixed-width oid will be replaced with "<OID>".
git config core.abbrev 7 &&
- git remote add origin ../upstream.git &&
- git update-ref refs/heads/main $A &&
- git push origin \
- $B:refs/heads/main \
- $A:refs/heads/foo \
- $A:refs/heads/bar \
- $A:refs/heads/baz
+ git config advice.pushUpdateRejected false
) &&
- git -C "workbench" config advice.pushUpdateRejected false &&
- upstream=upstream.git
+ # The upstream repository provides services using the HTTP protocol.
+ if ! test "$upstream" = "upstream.git"
+ then
+ git -C workbench remote set-url origin "$HTTPD_URL/smart/upstream.git"
+ fi
'
}
@@ -88,34 +126,29 @@ run_git_push_porcelain_output_test() {
;;
file)
PROTOCOL="builtin protocol"
- URL_PREFIX="\.\."
+ URL_PREFIX=".*"
;;
esac
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
# Refs of workbench: main(A) baz(A) next(A)
# git-push : main(A) NULL (B) baz(A) next(A)
- test_expect_success "porcelain output of successful git-push ($PROTOCOL)" '
- (
- cd workbench &&
- git update-ref refs/heads/main $A &&
- git update-ref refs/heads/baz $A &&
- git update-ref refs/heads/next $A &&
- git push --porcelain --force origin \
- main \
- :refs/heads/foo \
- $B:bar \
- baz \
- next
- ) >out &&
+ test_expect_success ".. git-push --porcelain ($PROTOCOL)" '
+ test_when_finished "setup_upstream \"$upstream\"" &&
+ test_must_fail git -C workbench push --porcelain origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
make_user_friendly_and_stable_output <out >actual &&
- format_and_save_expect <<-EOF &&
+ format_and_save_expect <<-\EOF &&
> To <URL/of/upstream.git>
> = refs/heads/baz:refs/heads/baz [up to date]
> <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
> - :refs/heads/foo [deleted]
- > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
> * refs/heads/next:refs/heads/next [new branch]
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
> Done
EOF
test_cmp expect actual &&
@@ -125,34 +158,32 @@ run_git_push_porcelain_output_test() {
cat >expect <<-EOF &&
<COMMIT-B> refs/heads/bar
<COMMIT-A> refs/heads/baz
- <COMMIT-A> refs/heads/main
+ <COMMIT-B> refs/heads/main
<COMMIT-A> refs/heads/next
EOF
test_cmp expect actual
'
- # Refs of upstream : main(A) bar(B) baz(A) next(A)
- # Refs of workbench: main(B) bar(A) baz(A) next(A)
- # git-push : main(B) bar(A) NULL next(A)
- test_expect_success "atomic push failed ($PROTOCOL)" '
- (
- cd workbench &&
- git update-ref refs/heads/main $B &&
- git update-ref refs/heads/bar $A &&
- test_must_fail git push --atomic --porcelain origin \
- main \
- bar \
- :baz \
- next
- ) >out &&
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --force ($PROTOCOL)" '
+ test_when_finished "setup_upstream \"$upstream\"" &&
+ git -C workbench push --porcelain --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
make_user_friendly_and_stable_output <out >actual &&
format_and_save_expect <<-EOF &&
- To <URL/of/upstream.git>
- > = refs/heads/next:refs/heads/next [up to date]
- > ! refs/heads/bar:refs/heads/bar [rejected] (non-fast-forward)
- > ! (delete):refs/heads/baz [rejected] (atomic push failed)
- > ! refs/heads/main:refs/heads/main [rejected] (atomic push failed)
- Done
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
+ > * refs/heads/next:refs/heads/next [new branch]
+ > Done
EOF
test_cmp expect actual &&
@@ -167,34 +198,129 @@ run_git_push_porcelain_output_test() {
test_cmp expect actual
'
- test_expect_success "prepare pre-receive hook ($PROTOCOL)" '
- test_hook --setup -C "$upstream" pre-receive <<-EOF
- exit 1
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git push --porcelain --atomic ($PROTOCOL)" '
+ test_when_finished "setup_upstream \"$upstream\"" &&
+ test_must_fail git -C workbench push --porcelain --atomic origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > ! <COMMIT-B>:refs/heads/bar [rejected] (atomic push failed)
+ > ! (delete):refs/heads/foo [rejected] (atomic push failed)
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
+ > ! refs/heads/next:refs/heads/next [rejected] (atomic push failed)
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ EOF
+ test_cmp expect actual
+ '
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. pre-receive hook declined ($PROTOCOL)" '
+ test_when_finished "rm -f \"$upstream/hooks/pre-receive\" &&
+ setup_upstream \"$upstream\"" &&
+ test_hook --setup -C "$upstream" pre-receive <<-EOF &&
+ exit 1
+ EOF
+ test_must_fail git -C workbench push --porcelain --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > ! <COMMIT-B>:refs/heads/bar [remote rejected] (pre-receive hook declined)
+ > ! :refs/heads/foo [remote rejected] (pre-receive hook declined)
+ > ! refs/heads/main:refs/heads/main [remote rejected] (pre-receive hook declined)
+ > ! refs/heads/next:refs/heads/next [remote rejected] (pre-receive hook declined)
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
EOF
+ test_cmp expect actual
'
- # Refs of upstream : main(A) bar(B) baz(A) next(A)
- # Refs of workbench: main(B) bar(A) baz(A) next(A)
- # git-push : main(B) bar(A) NULL next(A)
- test_expect_success "pre-receive hook declined ($PROTOCOL)" '
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) next(A)
+ test_expect_success ".. non-fastforward push ($PROTOCOL)" '
+ test_when_finished "setup_upstream \"$upstream\"" &&
(
cd workbench &&
- git update-ref refs/heads/main $B &&
- git update-ref refs/heads/bar $A &&
- test_must_fail git push --porcelain --force origin \
+ test_must_fail git push --porcelain origin \
main \
- bar \
- :baz \
next
) >out &&
make_user_friendly_and_stable_output <out >actual &&
format_and_save_expect <<-EOF &&
- To <URL/of/upstream.git>
- > = refs/heads/next:refs/heads/next [up to date]
- > ! refs/heads/bar:refs/heads/bar [remote rejected] (pre-receive hook declined)
- > ! :refs/heads/baz [remote rejected] (pre-receive hook declined)
- > ! refs/heads/main:refs/heads/main [remote rejected] (pre-receive hook declined)
- Done
+ > To <URL/of/upstream.git>
+ > * refs/heads/next:refs/heads/next [new branch]
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ <COMMIT-A> refs/heads/next
+ EOF
+ test_cmp expect actual
+ '
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git push --porcelain --atomic --force ($PROTOCOL)" '
+ git -C workbench push --porcelain --atomic --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-\EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
+ > * refs/heads/next:refs/heads/next [new branch]
+ > Done
EOF
test_cmp expect actual &&
@@ -208,71 +334,174 @@ run_git_push_porcelain_output_test() {
EOF
test_cmp expect actual
'
+}
- test_expect_success "remove pre-receive hook ($PROTOCOL)" '
- rm "$upstream/hooks/pre-receive"
+run_git_push_dry_run_porcelain_output_test() {
+ case $1 in
+ http)
+ PROTOCOL="HTTP protocol"
+ URL_PREFIX="http://.*"
+ ;;
+ file)
+ PROTOCOL="builtin protocol"
+ URL_PREFIX=".*"
+ ;;
+ esac
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --dry-run ($PROTOCOL)" '
+ test_must_fail git -C workbench push --porcelain --dry-run origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > * refs/heads/next:refs/heads/next [new branch]
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ EOF
+ test_cmp expect actual
'
- # Refs of upstream : main(A) bar(B) baz(A) next(A)
- # Refs of workbench: main(B) bar(A) baz(A) next(A)
- # git-push : main(B) bar(A) NULL next(A)
- test_expect_success "non-fastforward push ($PROTOCOL)" '
- (
- cd workbench &&
- test_must_fail git push --porcelain origin \
- main \
- bar \
- :baz \
- next
- ) >out &&
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --dry-run --force ($PROTOCOL)" '
+ git -C workbench push --porcelain --dry-run --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
+ > * refs/heads/next:refs/heads/next [new branch]
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ EOF
+ test_cmp expect actual
+ '
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # git-push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --dry-run --atomic ($PROTOCOL)" '
+ test_must_fail git -C workbench push --porcelain --dry-run --atomic origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
make_user_friendly_and_stable_output <out >actual &&
format_and_save_expect <<-EOF &&
- To <URL/of/upstream.git>
- > = refs/heads/next:refs/heads/next [up to date]
- > - :refs/heads/baz [deleted]
- > refs/heads/main:refs/heads/main <COMMIT-A>..<COMMIT-B>
- > ! refs/heads/bar:refs/heads/bar [rejected] (non-fast-forward)
- Done
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > ! <COMMIT-B>:refs/heads/bar [rejected] (atomic push failed)
+ > ! (delete):refs/heads/foo [rejected] (atomic push failed)
+ > ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
+ > ! refs/heads/next:refs/heads/next [rejected] (atomic push failed)
+ > Done
EOF
test_cmp expect actual &&
git -C "$upstream" show-ref >out &&
make_user_friendly_and_stable_output <out >actual &&
cat >expect <<-EOF &&
- <COMMIT-B> refs/heads/bar
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
+ <COMMIT-B> refs/heads/main
+ EOF
+ test_cmp expect actual
+ '
+
+ # Refs of upstream : main(B) foo(A) bar(A) baz(A)
+ # Refs of workbench: main(A) baz(A) next(A)
+ # push : main(A) NULL (B) baz(A) next(A)
+ test_expect_success ".. git-push --porcelain --dry-run --atomic --force ($PROTOCOL)" '
+ git -C workbench push --porcelain --dry-run --atomic --force origin \
+ main \
+ :refs/heads/foo \
+ $B:bar \
+ baz \
+ next >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ format_and_save_expect <<-EOF &&
+ > To <URL/of/upstream.git>
+ > = refs/heads/baz:refs/heads/baz [up to date]
+ > <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
+ > - :refs/heads/foo [deleted]
+ > + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
+ > * refs/heads/next:refs/heads/next [new branch]
+ > Done
+ EOF
+ test_cmp expect actual &&
+
+ git -C "$upstream" show-ref >out &&
+ make_user_friendly_and_stable_output <out >actual &&
+ cat >expect <<-EOF &&
+ <COMMIT-A> refs/heads/bar
+ <COMMIT-A> refs/heads/baz
+ <COMMIT-A> refs/heads/foo
<COMMIT-B> refs/heads/main
- <COMMIT-A> refs/heads/next
EOF
test_cmp expect actual
'
}
-# Initialize the upstream repository and local workbench.
-setup_upstream_and_workbench
+setup_upstream_and_workbench upstream.git
-# Run git-push porcelain test on builtin protocol
run_git_push_porcelain_output_test file
+setup_upstream_and_workbench upstream.git
+
+run_git_push_dry_run_porcelain_output_test file
+
ROOT_PATH="$PWD"
. "$TEST_DIRECTORY"/lib-gpg.sh
. "$TEST_DIRECTORY"/lib-httpd.sh
. "$TEST_DIRECTORY"/lib-terminal.sh
start_httpd
+setup_askpass_helper
-# Re-initialize the upstream repository and local workbench.
-setup_upstream_and_workbench
-
-test_expect_success "setup for http" '
- git -C upstream.git config http.receivepack true &&
- upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
- mv upstream.git "$upstream" &&
+setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
- git -C workbench remote set-url origin $HTTPD_URL/smart/upstream.git
-'
+run_git_push_porcelain_output_test http
-setup_askpass_helper
+setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
-# Run git-push porcelain test on HTTP protocol
-run_git_push_porcelain_output_test http
+run_git_push_dry_run_porcelain_output_test http
test_done
diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
index 761fdfcfe6..b0d4ea7801 100755
--- a/t/t5551-http-fetch-smart.sh
+++ b/t/t5551-http-fetch-smart.sh
@@ -7,6 +7,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-httpd.sh
+
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping http fetch smart tests; Perl not available'
+ test_done
+fi
+
test "$HTTP_PROTO" = "HTTP/2" && enable_http2
start_httpd
diff --git a/t/t5558-clone-bundle-uri.sh b/t/t5558-clone-bundle-uri.sh
index a14134b396..7a0943bd36 100755
--- a/t/t5558-clone-bundle-uri.sh
+++ b/t/t5558-clone-bundle-uri.sh
@@ -58,7 +58,7 @@ test_expect_success 'create bundle' '
test_expect_success 'clone with path bundle' '
git clone --bundle-uri="clone-from/B.bundle" \
clone-from clone-path &&
- git -C clone-path rev-parse refs/bundles/topic >actual &&
+ git -C clone-path rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual
'
@@ -68,9 +68,9 @@ test_expect_success 'clone with bundle that has bad header' '
git clone --bundle-uri="clone-from/bad-header.bundle" \
clone-from clone-bad-header 2>err &&
commit_b=$(git -C clone-from rev-parse B) &&
- test_grep "trying to write ref '\''refs/bundles/topic'\'' with nonexistent object $commit_b" err &&
+ test_grep "trying to write ref '\''refs/bundles/heads/topic'\'' with nonexistent object $commit_b" err &&
git -C clone-bad-header for-each-ref --format="%(refname)" >refs &&
- test_grep ! "refs/bundles/" refs
+ test_grep ! "refs/bundles/heads/" refs
'
test_expect_success 'clone with bundle that has bad object' '
@@ -78,8 +78,8 @@ test_expect_success 'clone with bundle that has bad object' '
git clone --bundle-uri="clone-from/bad-object.bundle" \
clone-from clone-bad-object-no-fsck &&
git -C clone-bad-object-no-fsck for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
- test_write_lines refs/bundles/bad >expect &&
+ grep "refs/bundles/heads/" refs >actual &&
+ test_write_lines refs/bundles/heads/bad >expect &&
test_cmp expect actual &&
# Unbundle fails with fsckObjects set true, but clone can still proceed.
@@ -87,14 +87,14 @@ test_expect_success 'clone with bundle that has bad object' '
clone-from clone-bad-object-fsck 2>err &&
test_grep "missingEmail" err &&
git -C clone-bad-object-fsck for-each-ref --format="%(refname)" >refs &&
- test_grep ! "refs/bundles/" refs
+ test_grep ! "refs/bundles/heads/" refs
'
test_expect_success 'clone with path bundle and non-default hash' '
test_when_finished "rm -rf clone-path-non-default-hash" &&
GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="clone-from/B.bundle" \
clone-from clone-path-non-default-hash &&
- git -C clone-path-non-default-hash rev-parse refs/bundles/topic >actual &&
+ git -C clone-path-non-default-hash rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual
'
@@ -102,11 +102,41 @@ test_expect_success 'clone with path bundle and non-default hash' '
test_expect_success 'clone with file:// bundle' '
git clone --bundle-uri="file://$(pwd)/clone-from/B.bundle" \
clone-from clone-file &&
- git -C clone-file rev-parse refs/bundles/topic >actual &&
+ git -C clone-file rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual
'
+test_expect_success 'create bundle with tags' '
+ git init clone-from-tags &&
+ (
+ cd clone-from-tags &&
+ git checkout -b base &&
+ git checkout -b topic &&
+
+ test_commit A &&
+ git tag tag-A &&
+ git checkout -b base &&
+ git branch -d topic &&
+ test_commit B &&
+
+ git bundle create ALL.bundle --all &&
+ git bundle verify ALL.bundle
+ )
+'
+
+test_expect_success 'clone with tags bundle' '
+ git clone --bundle-uri="clone-from-tags/ALL.bundle" \
+ clone-from-tags clone-tags-path &&
+
+ git -C clone-from-tags for-each-ref --format="%(refname:lstrip=1)" \
+ >expect &&
+ git -C clone-tags-path for-each-ref --format="%(refname:lstrip=2)" \
+ refs/bundles >actual &&
+
+ test_cmp expect actual
+'
+
# To get interesting tests for bundle lists, we need to construct a
# somewhat-interesting commit history.
#
@@ -173,12 +203,12 @@ test_expect_success 'clone bundle list (file, no heuristic)' '
git -C clone-list-file cat-file --batch-check <oids &&
git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
EOF
test_cmp expect actual
'
@@ -220,10 +250,10 @@ test_expect_success 'clone bundle list (file, all mode, some failures)' '
git -C clone-all-some cat-file --batch-check <oids &&
git -C clone-all-some for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect actual
'
@@ -253,7 +283,7 @@ test_expect_success 'clone bundle list (file, all mode, all failures)' '
git -C clone-all-fail cat-file --batch-check <oids &&
git -C clone-all-fail for-each-ref --format="%(refname)" >refs &&
- ! grep "refs/bundles/" refs
+ ! grep "refs/bundles/heads/" refs
'
test_expect_success 'clone bundle list (file, any mode)' '
@@ -282,9 +312,9 @@ test_expect_success 'clone bundle list (file, any mode)' '
git -C clone-any-file cat-file --batch-check <oids &&
git -C clone-any-file for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
+ refs/bundles/heads/base
EOF
test_cmp expect actual
'
@@ -313,7 +343,7 @@ test_expect_success 'clone bundle list (file, any mode, all failures)' '
git -C clone-any-fail cat-file --batch-check <oids &&
git -C clone-any-fail for-each-ref --format="%(refname)" >refs &&
- ! grep "refs/bundles/" refs
+ ! grep "refs/bundles/heads/" refs
'
test_expect_success 'negotiation: bundle with part of wanted commits' '
@@ -322,10 +352,10 @@ test_expect_success 'negotiation: bundle with part of wanted commits' '
git clone --no-local --bundle-uri="clone-from/A.bundle" \
clone-from nego-bundle-part &&
git -C nego-bundle-part for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
- test_write_lines refs/bundles/topic >expect &&
+ grep "refs/bundles/heads/" refs >actual &&
+ test_write_lines refs/bundles/heads/topic >expect &&
test_cmp expect actual &&
- # Ensure that refs/bundles/topic are sent as "have".
+ # Ensure that refs/bundles/heads/topic are sent as "have".
tip=$(git -C clone-from rev-parse A) &&
test_grep "clone> have $tip" trace-packet.txt
'
@@ -337,8 +367,8 @@ test_expect_success 'negotiation: bundle with all wanted commits' '
--bundle-uri="clone-from/B.bundle" \
clone-from nego-bundle-all &&
git -C nego-bundle-all for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
- test_write_lines refs/bundles/topic >expect &&
+ grep "refs/bundles/heads/" refs >actual &&
+ test_write_lines refs/bundles/heads/topic >expect &&
test_cmp expect actual &&
# We already have all needed commits so no "want" needed.
test_grep ! "clone> want " trace-packet.txt
@@ -363,13 +393,13 @@ test_expect_success 'negotiation: bundle list (no heuristic)' '
clone-from nego-bundle-list-no-heuristic &&
git -C nego-bundle-list-no-heuristic for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect actual &&
- tip=$(git -C nego-bundle-list-no-heuristic rev-parse refs/bundles/left) &&
+ tip=$(git -C nego-bundle-list-no-heuristic rev-parse refs/bundles/heads/left) &&
test_grep "clone> have $tip" trace-packet.txt
'
@@ -395,13 +425,13 @@ test_expect_success 'negotiation: bundle list (creationToken)' '
clone-from nego-bundle-list-heuristic &&
git -C nego-bundle-list-heuristic for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect actual &&
- tip=$(git -C nego-bundle-list-heuristic rev-parse refs/bundles/left) &&
+ tip=$(git -C nego-bundle-list-heuristic rev-parse refs/bundles/heads/left) &&
test_grep "clone> have $tip" trace-packet.txt
'
@@ -428,10 +458,10 @@ test_expect_success 'negotiation: bundle list with all wanted commits' '
clone-from nego-bundle-list-all &&
git -C nego-bundle-list-all for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect actual &&
# We already have all needed commits so no "want" needed.
@@ -465,7 +495,7 @@ test_expect_success 'clone HTTP bundle' '
git clone --bundle-uri="$HTTPD_URL/B.bundle" \
"$HTTPD_URL/smart/fetch.git" clone-http &&
- git -C clone-http rev-parse refs/bundles/topic >actual &&
+ git -C clone-http rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual &&
@@ -476,7 +506,7 @@ test_expect_success 'clone HTTP bundle with non-default hash' '
test_when_finished "rm -rf clone-http-non-default-hash" &&
GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="$HTTPD_URL/B.bundle" \
"$HTTPD_URL/smart/fetch.git" clone-http-non-default-hash &&
- git -C clone-http-non-default-hash rev-parse refs/bundles/topic >actual &&
+ git -C clone-http-non-default-hash rev-parse refs/bundles/heads/topic >actual &&
git -C clone-from rev-parse topic >expect &&
test_cmp expect actual
'
@@ -553,12 +583,12 @@ test_expect_success 'clone bundle list (HTTP, any mode)' '
git -C clone-any-http cat-file --batch-check <oids &&
git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
- grep "refs/bundles/" refs >actual &&
+ grep "refs/bundles/heads/" refs >actual &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
EOF
test_cmp expect actual
'
@@ -641,9 +671,9 @@ test_expect_success 'clone incomplete bundle list (http, creationToken)' '
test_cmp expect actual &&
# We now have only one bundle ref.
- git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
+ refs/bundles/heads/base
EOF
test_cmp expect refs &&
@@ -679,13 +709,13 @@ test_expect_success 'clone incomplete bundle list (http, creationToken)' '
test_cmp expect actual &&
# We now have all bundle refs.
- git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
EOF
test_cmp expect refs
'
@@ -721,9 +751,9 @@ test_expect_success 'http clone with bundle.heuristic creates fetch.bundleURI' '
test_cmp expect actual &&
# only received base ref from bundle-1
- git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
+ refs/bundles/heads/base
EOF
test_cmp expect refs &&
@@ -749,10 +779,10 @@ test_expect_success 'http clone with bundle.heuristic creates fetch.bundleURI' '
test_cmp expect actual &&
# received left from bundle-2
- git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
+ refs/bundles/heads/base
+ refs/bundles/heads/left
EOF
test_cmp expect refs &&
@@ -795,12 +825,12 @@ test_expect_success 'http clone with bundle.heuristic creates fetch.bundleURI' '
# received merge ref from bundle-4, but right is missing
# because we did not download bundle-3.
- git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-\EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
EOF
test_cmp expect refs &&
@@ -862,7 +892,7 @@ test_expect_success 'creationToken heuristic with failed downloads (clone)' '
test_cmp expect actual &&
# All bundles failed to unbundle
- git -C download-1 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C download-1 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
test_must_be_empty refs &&
# Case 2: middle bundle does not exist, only two bundles can unbundle
@@ -909,10 +939,10 @@ test_expect_success 'creationToken heuristic with failed downloads (clone)' '
test_cmp expect actual &&
# bundle-1 and bundle-3 could unbundle, but bundle-4 could not
- git -C download-2 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C download-2 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/right
EOF
test_cmp expect refs &&
@@ -961,11 +991,11 @@ test_expect_success 'creationToken heuristic with failed downloads (clone)' '
test_cmp expect actual &&
# fake.bundle did not unbundle, but the others did.
- git -C download-3 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C download-3 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/right
EOF
test_cmp expect refs
'
@@ -1083,15 +1113,15 @@ test_expect_success 'creationToken heuristic with failed downloads (fetch)' '
test_cmp expect actual &&
# Check which bundles have unbundled by refs
- git -C fetch-1 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-1 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/lefter
- refs/bundles/merge
- refs/bundles/right
- refs/bundles/righter
- refs/bundles/top
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/lefter
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
+ refs/bundles/heads/righter
+ refs/bundles/heads/top
EOF
test_cmp expect refs &&
@@ -1144,12 +1174,12 @@ test_expect_success 'creationToken heuristic with failed downloads (fetch)' '
test_cmp expect actual &&
# Check which bundles have unbundled by refs
- git -C fetch-2 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-2 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/merge
- refs/bundles/right
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/merge
+ refs/bundles/heads/right
EOF
test_cmp expect refs &&
@@ -1204,13 +1234,13 @@ test_expect_success 'creationToken heuristic with failed downloads (fetch)' '
test_cmp expect actual &&
# Check which bundles have unbundled by refs
- git -C fetch-3 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
+ git -C fetch-3 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs &&
cat >expect <<-EOF &&
- refs/bundles/base
- refs/bundles/left
- refs/bundles/lefter
- refs/bundles/right
- refs/bundles/righter
+ refs/bundles/heads/base
+ refs/bundles/heads/left
+ refs/bundles/heads/lefter
+ refs/bundles/heads/right
+ refs/bundles/heads/righter
EOF
test_cmp expect refs
'
diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh
index f3b158274c..b6ee06f5c8 100755
--- a/t/t5562-http-backend-content-length.sh
+++ b/t/t5562-http-backend-content-length.sh
@@ -4,6 +4,12 @@ test_description='test git-http-backend respects CONTENT_LENGTH'
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping http backend content tests; Perl not available'
+ test_done
+fi
+
test_lazy_prereq GZIP 'gzip --version'
verify_http_result() {
diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh
index f7650e8475..45f384dd32 100755
--- a/t/t5572-pull-submodule.sh
+++ b/t/t5572-pull-submodule.sh
@@ -45,11 +45,6 @@ git_pull_noff () {
$2 git pull --no-ff
}
-if test "$GIT_TEST_MERGE_ALGORITHM" != ort
-then
- KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
- KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
-fi
test_submodule_switch_func "git_pull_noff"
test_expect_success 'setup' '
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index d0c18660e3..d743d986c4 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -649,7 +649,7 @@ test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
git -C replay.git index-pack -v --stdin <tmp.pack
'
-test_expect_success 'clone on case-insensitive fs' '
+test_expect_success PERL_TEST_HELPERS 'clone on case-insensitive fs' '
git init icasefs &&
(
cd icasefs &&
@@ -662,7 +662,7 @@ test_expect_success 'clone on case-insensitive fs' '
)
'
-test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' '
+test_expect_success PERL_TEST_HELPERS,CASE_INSENSITIVE_FS 'colliding file detection' '
grep X icasefs/warning &&
grep x icasefs/warning &&
test_grep "the following paths have collided" icasefs/warning
diff --git a/t/t5605-clone-local.sh b/t/t5605-clone-local.sh
index 4605703496..2397f8fa61 100755
--- a/t/t5605-clone-local.sh
+++ b/t/t5605-clone-local.sh
@@ -156,11 +156,10 @@ test_expect_success 'cloning a local path with --no-local does not hardlink' '
test_expect_success 'cloning a local path with --no-local from a different user succeeds' '
git clone --upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
--no-local a nonlocal-otheruser 2>err &&
- ! repo_is_hardlinked nonlocal-otheruser &&
+ ! repo_is_hardlinked nonlocal-otheruser/.git &&
# Verify that this is a git repository.
git -C nonlocal-otheruser rev-parse --show-toplevel &&
- ! test_grep "detected dubious ownership" err
-
+ test_grep ! "detected dubious ownership" err
'
test_expect_success 'cloning locally respects "-u" for fetching refs' '
diff --git a/t/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh
index 82e3621ec5..d709bea753 100755
--- a/t/t5607-clone-bundle.sh
+++ b/t/t5607-clone-bundle.sh
@@ -211,4 +211,16 @@ test_expect_success 'git bundle v3 rejects unknown capabilities' '
test_grep "unknown capability .unknown=silly." output
'
+test_expect_success 'cloning bundle suppresses default branch name advice' '
+ test_when_finished "rm -rf bundle-repo clone-repo" &&
+
+ git init bundle-repo &&
+ git -C bundle-repo commit --allow-empty -m init &&
+ git -C bundle-repo bundle create repo.bundle --all &&
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git clone --single-branch bundle-repo/repo.bundle clone-repo 2>err &&
+
+ test_grep ! "hint: " err
+'
+
test_done
diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh
index 4650451964..1e354e057f 100755
--- a/t/t5616-partial-clone.sh
+++ b/t/t5616-partial-clone.sh
@@ -737,18 +737,22 @@ intersperse () {
sed 's/\(..\)/'$1'\1/g'
}
-# Create a one-time-perl command to replace the existing packfile with $1.
+# Create a one-time-script command to replace the existing packfile with $1.
replace_packfile () {
- # The protocol requires that the packfile be sent in sideband 1, hence
- # the extra \x01 byte at the beginning.
- cp $1 "$HTTPD_ROOT_PATH/one-time-pack" &&
- echo 'if (/packfile/) {
- print;
- my $length = -s "one-time-pack";
- printf "%04x\x01", $length + 5;
- print `cat one-time-pack` . "0000";
- last
- }' >"$HTTPD_ROOT_PATH/one-time-perl"
+ cp "$1" one-time-pack &&
+ write_script "$HTTPD_ROOT_PATH/one-time-script" <<-EOF
+ if grep packfile "\$1" >/dev/null
+ then
+ sed '/packfile/q' "\$1" &&
+ # The protocol requires that the packfile be sent in sideband
+ # 1, hence the extra \001 byte at the beginning.
+ printf "%04x\001" \$((\$(wc -c <"$PWD/one-time-pack") + 5)) &&
+ cat "$PWD/one-time-pack" &&
+ printf "0000"
+ else
+ cat "\$1"
+ fi
+ EOF
}
test_expect_success 'upon cloning, check that all refs point to objects' '
@@ -776,12 +780,12 @@ test_expect_success 'upon cloning, check that all refs point to objects' '
# section header.
test_config -C "$SERVER" protocol.version 2 &&
test_must_fail git -c protocol.version=2 clone \
- --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2>err &&
+ --filter=blob:none $HTTPD_URL/one_time_script/server repo 2>err &&
test_grep "did not send all necessary objects" err &&
- # Ensure that the one-time-perl script was used.
- ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
+ # Ensure that the one-time-script script was used.
+ ! test -e "$HTTPD_ROOT_PATH/one-time-script"
'
test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
@@ -818,14 +822,14 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
# Exercise to make sure it works.
git -c protocol.version=2 clone \
- --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2> err &&
+ --filter=blob:none $HTTPD_URL/one_time_script/server repo 2> err &&
! grep "missing object referenced by" err &&
- # Ensure that the one-time-perl script was used.
- ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
+ # Ensure that the one-time-script script was used.
+ ! test -e "$HTTPD_ROOT_PATH/one-time-script"
'
-test_expect_success 'tolerate server sending REF_DELTA against missing promisor objects' '
+test_expect_success PERL_TEST_HELPERS 'tolerate server sending REF_DELTA against missing promisor objects' '
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
rm -rf "$SERVER" repo &&
test_create_repo "$SERVER" &&
@@ -845,7 +849,7 @@ test_expect_success 'tolerate server sending REF_DELTA against missing promisor
# Clone. The client has deltabase_have but not deltabase_missing.
git -c protocol.version=2 clone --no-checkout \
- --filter=blob:none $HTTPD_URL/one_time_perl/server repo &&
+ --filter=blob:none $HTTPD_URL/one_time_script/server repo &&
git -C repo hash-object -w -- "$SERVER/have.txt" &&
# Sanity check to ensure that the client does not have
@@ -899,8 +903,8 @@ test_expect_success 'tolerate server sending REF_DELTA against missing promisor
grep "want $(cat deltabase_missing)" trace &&
! grep "want $(cat deltabase_have)" trace &&
- # Ensure that the one-time-perl script was used.
- ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
+ # Ensure that the one-time-script script was used.
+ ! test -e "$HTTPD_ROOT_PATH/one-time-script"
'
# DO NOT add non-httpd-specific tests here, because the last part of this
diff --git a/t/t5620-backfill.sh b/t/t5620-backfill.sh
new file mode 100755
index 0000000000..58c81556e7
--- /dev/null
+++ b/t/t5620-backfill.sh
@@ -0,0 +1,211 @@
+#!/bin/sh
+
+test_description='git backfill on partial clones'
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+. ./test-lib.sh
+
+# We create objects in the 'src' repo.
+test_expect_success 'setup repo for object creation' '
+ echo "{print \$1}" >print_1.awk &&
+ echo "{print \$2}" >print_2.awk &&
+
+ git init src &&
+
+ mkdir -p src/a/b/c &&
+ mkdir -p src/d/e &&
+
+ for i in 1 2
+ do
+ for n in 1 2 3 4
+ do
+ echo "Version $i of file $n" > src/file.$n.txt &&
+ echo "Version $i of file a/$n" > src/a/file.$n.txt &&
+ echo "Version $i of file a/b/$n" > src/a/b/file.$n.txt &&
+ echo "Version $i of file a/b/c/$n" > src/a/b/c/file.$n.txt &&
+ echo "Version $i of file d/$n" > src/d/file.$n.txt &&
+ echo "Version $i of file d/e/$n" > src/d/e/file.$n.txt &&
+ git -C src add . &&
+ git -C src commit -m "Iteration $n" || return 1
+ done
+ done
+'
+
+# Clone 'src' into 'srv.bare' so we have a bare repo to be our origin
+# server for the partial clone.
+test_expect_success 'setup bare clone for server' '
+ git clone --bare "file://$(pwd)/src" srv.bare &&
+ git -C srv.bare config --local uploadpack.allowfilter 1 &&
+ git -C srv.bare config --local uploadpack.allowanysha1inwant 1
+'
+
+# do basic partial clone from "srv.bare"
+test_expect_success 'do partial clone 1, backfill gets all objects' '
+ git clone --no-checkout --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill1 &&
+
+ # Backfill with no options gets everything reachable from HEAD.
+ GIT_TRACE2_EVENT="$(pwd)/backfill-file-trace" git \
+ -C backfill1 backfill &&
+
+ # We should have engaged the partial clone machinery
+ test_trace2_data promisor fetch_count 48 <backfill-file-trace &&
+
+ # No more missing objects!
+ git -C backfill1 rev-list --quiet --objects --missing=print HEAD >revs2 &&
+ test_line_count = 0 revs2
+'
+
+test_expect_success 'do partial clone 2, backfill min batch size' '
+ git clone --no-checkout --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill2 &&
+
+ GIT_TRACE2_EVENT="$(pwd)/batch-trace" git \
+ -C backfill2 backfill --min-batch-size=20 &&
+
+ # Batches were used
+ test_trace2_data promisor fetch_count 20 <batch-trace >matches &&
+ test_line_count = 2 matches &&
+ test_trace2_data promisor fetch_count 8 <batch-trace &&
+
+ # No more missing objects!
+ git -C backfill2 rev-list --quiet --objects --missing=print HEAD >revs2 &&
+ test_line_count = 0 revs2
+'
+
+test_expect_success 'backfill --sparse without sparse-checkout fails' '
+ git init not-sparse &&
+ test_must_fail git -C not-sparse backfill --sparse 2>err &&
+ grep "problem loading sparse-checkout" err
+'
+
+test_expect_success 'backfill --sparse' '
+ git clone --sparse --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill3 &&
+
+ # Initial checkout includes four files at root.
+ git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 44 missing &&
+
+ # Initial sparse-checkout is just the files at root, so we get the
+ # older versions of the four files at tip.
+ GIT_TRACE2_EVENT="$(pwd)/sparse-trace1" git \
+ -C backfill3 backfill --sparse &&
+ test_trace2_data promisor fetch_count 4 <sparse-trace1 &&
+ test_trace2_data path-walk paths 5 <sparse-trace1 &&
+ git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 40 missing &&
+
+ # Expand the sparse-checkout to include 'd' recursively. This
+ # engages the algorithm to skip the trees for 'a'. Note that
+ # the "sparse-checkout set" command downloads the objects at tip
+ # to satisfy the current checkout.
+ git -C backfill3 sparse-checkout set d &&
+ GIT_TRACE2_EVENT="$(pwd)/sparse-trace2" git \
+ -C backfill3 backfill --sparse &&
+ test_trace2_data promisor fetch_count 8 <sparse-trace2 &&
+ test_trace2_data path-walk paths 15 <sparse-trace2 &&
+ git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 24 missing &&
+
+ # Disabling the --sparse option (on by default) will download everything
+ git -C backfill3 backfill --no-sparse &&
+ git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 0 missing
+'
+
+test_expect_success 'backfill --sparse without cone mode (positive)' '
+ git clone --no-checkout --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill4 &&
+
+ # No blobs yet
+ git -C backfill4 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 48 missing &&
+
+ # Define sparse-checkout by filename regardless of parent directory.
+ # This downloads 6 blobs to satisfy the checkout.
+ git -C backfill4 sparse-checkout set --no-cone "**/file.1.txt" &&
+ git -C backfill4 checkout main &&
+
+ # Track new blob count
+ git -C backfill4 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 42 missing &&
+
+ GIT_TRACE2_EVENT="$(pwd)/no-cone-trace1" git \
+ -C backfill4 backfill --sparse &&
+ test_trace2_data promisor fetch_count 6 <no-cone-trace1 &&
+
+ # This walk needed to visit all directories to search for these paths.
+ test_trace2_data path-walk paths 12 <no-cone-trace1 &&
+ git -C backfill4 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 36 missing
+'
+
+test_expect_success 'backfill --sparse without cone mode (negative)' '
+ git clone --no-checkout --filter=blob:none \
+ --single-branch --branch=main \
+ "file://$(pwd)/srv.bare" backfill5 &&
+
+ # No blobs yet
+ git -C backfill5 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 48 missing &&
+
+ # Define sparse-checkout by filename regardless of parent directory.
+ # This downloads 18 blobs to satisfy the checkout
+ git -C backfill5 sparse-checkout set --no-cone "**/file*" "!**/file.1.txt" &&
+ git -C backfill5 checkout main &&
+
+ # Track new blob count
+ git -C backfill5 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 30 missing &&
+
+ GIT_TRACE2_EVENT="$(pwd)/no-cone-trace2" git \
+ -C backfill5 backfill --sparse &&
+ test_trace2_data promisor fetch_count 18 <no-cone-trace2 &&
+
+ # This walk needed to visit all directories to search for these paths, plus
+ # 12 extra "file.?.txt" paths than the previous test.
+ test_trace2_data path-walk paths 24 <no-cone-trace2 &&
+ git -C backfill5 rev-list --quiet --objects --missing=print HEAD >missing &&
+ test_line_count = 12 missing
+'
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+start_httpd
+
+test_expect_success 'create a partial clone over HTTP' '
+ SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
+ rm -rf "$SERVER" repo &&
+ git clone --bare "file://$(pwd)/src" "$SERVER" &&
+ test_config -C "$SERVER" uploadpack.allowfilter 1 &&
+ test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
+
+ git clone --no-checkout --filter=blob:none \
+ "$HTTPD_URL/smart/server" backfill-http
+'
+
+test_expect_success 'backfilling over HTTP succeeds' '
+ GIT_TRACE2_EVENT="$(pwd)/backfill-http-trace" git \
+ -C backfill-http backfill &&
+
+ # We should have engaged the partial clone machinery
+ test_trace2_data promisor fetch_count 48 <backfill-http-trace &&
+
+ # Confirm all objects are present, none missing.
+ git -C backfill-http rev-list --objects --all >rev-list-out &&
+ awk "{print \$1;}" <rev-list-out >oids &&
+ GIT_TRACE2_EVENT="$(pwd)/walk-trace" git -C backfill-http \
+ cat-file --batch-check <oids >batch-out &&
+ ! grep missing batch-out
+'
+
+# DO NOT add non-httpd-specific tests here, because the last part of this
+# test script is only executed when httpd is available and enabled.
+
+test_done
diff --git a/t/t5621-clone-revision.sh b/t/t5621-clone-revision.sh
new file mode 100755
index 0000000000..db3b8cff55
--- /dev/null
+++ b/t/t5621-clone-revision.sh
@@ -0,0 +1,122 @@
+#!/bin/sh
+
+test_description='tests for git clone --revision'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ test_commit --no-tag "initial commit" README "Hello" &&
+ test_commit --annotate "second commit" README "Hello world" v1.0 &&
+ test_commit --no-tag "third commit" README "Hello world!" &&
+ git switch -c feature v1.0 &&
+ test_commit --no-tag "feature commit" README "Hello world!" &&
+ git switch main
+'
+
+test_expect_success 'clone with --revision being a branch' '
+ test_when_finished "rm -rf dst" &&
+ git clone --revision=refs/heads/feature . dst &&
+ git rev-parse refs/heads/feature >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --depth and --revision being a branch' '
+ test_when_finished "rm -rf dst" &&
+ git clone --no-local --depth=1 --revision=refs/heads/feature . dst &&
+ git rev-parse refs/heads/feature >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch &&
+ git -C dst rev-list HEAD >actual &&
+ test_line_count = 1 actual
+'
+
+test_expect_success 'clone with --revision being a tag' '
+ test_when_finished "rm -rf dst" &&
+ git clone --revision=refs/tags/v1.0 . dst &&
+ git rev-parse refs/tags/v1.0^{} >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --revision being HEAD' '
+ test_when_finished "rm -rf dst" &&
+ git clone --revision=HEAD . dst &&
+ git rev-parse HEAD >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --revision being a raw commit hash' '
+ test_when_finished "rm -rf dst" &&
+ oid=$(git rev-parse refs/heads/feature) &&
+ git clone --revision=$oid . dst &&
+ echo $oid >expect &&
+ git -C dst rev-parse HEAD >actual &&
+ test_must_fail git -C dst symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --revision and --bare' '
+ test_when_finished "rm -rf dst" &&
+ git clone --revision=refs/heads/main --bare . dst &&
+ oid=$(git rev-parse refs/heads/main) &&
+ git -C dst cat-file -t $oid >actual &&
+ echo "commit" >expect &&
+ test_cmp expect actual &&
+ git -C dst for-each-ref refs >expect &&
+ test_must_be_empty expect &&
+ test_must_fail git -C dst config remote.origin.fetch
+'
+
+test_expect_success 'clone with --revision being a short raw commit hash' '
+ test_when_finished "rm -rf dst" &&
+ oid=$(git rev-parse --short refs/heads/feature) &&
+ test_must_fail git clone --revision=$oid . dst 2>err &&
+ test_grep "fatal: Remote revision $oid not found in upstream origin" err
+'
+
+test_expect_success 'clone with --revision being a tree hash' '
+ test_when_finished "rm -rf dst" &&
+ oid=$(git rev-parse refs/heads/feature^{tree}) &&
+ test_must_fail git clone --revision=$oid . dst 2>err &&
+ test_grep "error: object $oid is a tree, not a commit" err
+'
+
+test_expect_success 'clone with --revision being the parent of a ref fails' '
+ test_when_finished "rm -rf dst" &&
+ test_must_fail git clone --revision=refs/heads/main^ . dst
+'
+
+test_expect_success 'clone with --revision and --branch fails' '
+ test_when_finished "rm -rf dst" &&
+ test_must_fail git clone --revision=refs/heads/main --branch=main . dst
+'
+
+test_expect_success 'clone with --revision and --mirror fails' '
+ test_when_finished "rm -rf dst" &&
+ test_must_fail git clone --revision=refs/heads/main --mirror . dst
+'
+
+test_done
diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh
index de904c1655..d4c28bae39 100755
--- a/t/t5701-git-serve.sh
+++ b/t/t5701-git-serve.sh
@@ -7,24 +7,40 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
-test_expect_success 'test capability advertisement' '
+test_expect_success 'setup to generate files with expected content' '
+ printf "agent=git/%s" "$(git version | cut -d" " -f3)" >agent_capability &&
+
test_oid_cache <<-EOF &&
wrong_algo sha1:sha256
wrong_algo sha256:sha1
EOF
+
+ if test_have_prereq WINDOWS
+ then
+ printf "agent=FAKE\n" >agent_capability
+ else
+ printf -- "-%s\n" $(uname -s | test_redact_non_printables) >>agent_capability
+ fi &&
cat >expect.base <<-EOF &&
version 2
- agent=git/$(git version | cut -d" " -f3)
+ $(cat agent_capability)
ls-refs=unborn
fetch=shallow wait-for-done
server-option
object-format=$(test_oid algo)
EOF
- cat >expect.trailer <<-EOF &&
+ cat >expect.trailer <<-EOF
0000
EOF
+'
+
+test_expect_success 'test capability advertisement' '
cat expect.base expect.trailer >expect &&
+ if test_have_prereq WINDOWS
+ then
+ GIT_USER_AGENT=FAKE && export GIT_USER_AGENT
+ fi &&
GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
--advertise-capabilities >out &&
test-tool pkt-line unpack <out >actual &&
@@ -212,7 +228,10 @@ test_expect_success 'ignore very large set of prefixes' '
echo command=ls-refs &&
echo object-format=$(test_oid algo) &&
echo 0001 &&
- perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
+ awk "{
+ for (i = 1; i <= 65536; i++)
+ print \"ref-prefix refs/heads/\", \$i
+ }" &&
echo 0000
} |
test-tool pkt-line pack >in &&
@@ -355,6 +374,10 @@ test_expect_success 'test capability advertisement with uploadpack.advertiseBund
expect.extra \
expect.trailer >expect &&
+ if test_have_prereq WINDOWS
+ then
+ GIT_USER_AGENT=FAKE && export GIT_USER_AGENT
+ fi &&
GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
--advertise-capabilities >out &&
test-tool pkt-line unpack <out >actual &&
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index d3df81e785..f826ac46a5 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -665,7 +665,7 @@ test_expect_success 'even with handcrafted request, filter does not work if not
test-tool -C server serve-v2 --stateless-rpc <in >/dev/null
'
-test_expect_success 'default refspec is used to filter ref when fetchcing' '
+test_expect_success 'default refspec is used to filter ref when fetching' '
test_when_finished "rm -f log" &&
GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
@@ -679,6 +679,48 @@ test_expect_success 'default refspec is used to filter ref when fetchcing' '
grep "ref-prefix refs/tags/" log
'
+test_expect_success 'set up parent for prefix tests' '
+ git init prefix-parent &&
+ git -C prefix-parent commit --allow-empty -m foo &&
+ git -C prefix-parent tag my-tag &&
+ git -C prefix-parent branch unrelated-branch
+'
+
+test_expect_success 'empty refspec filters refs when fetching' '
+ git init configless-child &&
+
+ test_when_finished "rm -f log" &&
+ GIT_TRACE_PACKET="$(pwd)/log" \
+ git -C configless-child fetch ../prefix-parent &&
+ test_grep ! unrelated-branch log
+'
+
+test_expect_success 'exact oid fetch with tag following' '
+ git init exact-oid-tags &&
+
+ commit=$(git -C prefix-parent rev-parse --verify HEAD) &&
+
+ test_when_finished "rm -f log" &&
+ GIT_TRACE_PACKET="$(pwd)/log" \
+ git -C exact-oid-tags fetch ../prefix-parent \
+ $commit:refs/heads/exact &&
+ test_grep ! unrelated-branch log &&
+ git -C exact-oid-tags rev-parse --verify my-tag
+'
+
+test_expect_success 'exact oid fetch avoids pointless HEAD request' '
+ git init exact-oid-head &&
+ git -C exact-oid-head remote add origin ../prefix-parent &&
+
+ commit=$(git -C prefix-parent rev-parse --verify HEAD) &&
+
+ test_when_finished "rm -f log" &&
+ GIT_TRACE_PACKET="$(pwd)/log" \
+ git -C exact-oid-head fetch --no-tags origin \
+ $commit:refs/heads/exact &&
+ test_grep ! command=ls-refs log
+'
+
test_expect_success 'fetch supports various ways of have lines' '
rm -rf server client trace &&
git init server &&
@@ -1132,11 +1174,12 @@ test_expect_success 'when server sends "ready", expect DELIM' '
# After "ready" in the acknowledgments section, pretend that a FLUSH
# (0000) was sent instead of a DELIM (0001).
- printf "\$ready = 1 if /ready/; \$ready && s/0001/0000/" \
- >"$HTTPD_ROOT_PATH/one-time-perl" &&
+ write_script "$HTTPD_ROOT_PATH/one-time-script" <<-\EOF &&
+ sed "/ready/{n;s/0001/0000/;}" "$1"
+ EOF
test_must_fail git -C http_child -c protocol.version=2 \
- fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
+ fetch "$HTTPD_URL/one_time_script/http_parent" 2> err &&
test_grep "expected packfile to be sent after .ready." err
'
@@ -1157,12 +1200,13 @@ test_expect_success 'when server does not send "ready", expect FLUSH' '
# After the acknowledgments section, pretend that a DELIM
# (0001) was sent instead of a FLUSH (0000).
- printf "\$ack = 1 if /acknowledgments/; \$ack && s/0000/0001/" \
- >"$HTTPD_ROOT_PATH/one-time-perl" &&
+ write_script "$HTTPD_ROOT_PATH/one-time-script" <<-\EOF &&
+ sed "/acknowledgments/,//{s/0000/0001/;}" "$1"
+ EOF
test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" git -C http_child \
-c protocol.version=2 \
- fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
+ fetch "$HTTPD_URL/one_time_script/http_parent" 2> err &&
grep "fetch< .*acknowledgments" log &&
! grep "fetch< .*ready" log &&
test_grep "expected no other sections to be sent after no .ready." err
@@ -1448,12 +1492,13 @@ test_expect_success 'http:// --negotiate-only' '
test_expect_success 'http:// --negotiate-only without wait-for-done support' '
SERVER="server" &&
- URI="$HTTPD_URL/one_time_perl/server" &&
+ URI="$HTTPD_URL/one_time_script/server" &&
setup_negotiate_only "$SERVER" "$URI" &&
- echo "s/ wait-for-done/ xxxx-xxx-xxxx/" \
- >"$HTTPD_ROOT_PATH/one-time-perl" &&
+ write_script "$HTTPD_ROOT_PATH/one-time-script" <<-\EOF &&
+ sed "s/ wait-for-done/ xxxx-xxx-xxxx/" "$1"
+ EOF
test_must_fail git -c protocol.version=2 -C client fetch \
--no-tags \
diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index 191097171b..249137b467 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -83,18 +83,15 @@ test_expect_success 'setup repository' '
test_expect_success 'config controls ref-in-want advertisement' '
test-tool serve-v2 --advertise-capabilities >out &&
- perl -ne "/ref-in-want/ and print" out >out.filter &&
- test_must_be_empty out.filter &&
+ test_grep ! "ref-in-want" out &&
git config uploadpack.allowRefInWant false &&
test-tool serve-v2 --advertise-capabilities >out &&
- perl -ne "/ref-in-want/ and print" out >out.filter &&
- test_must_be_empty out.filter &&
+ test_grep ! "ref-in-want" out &&
git config uploadpack.allowRefInWant true &&
test-tool serve-v2 --advertise-capabilities >out &&
- perl -ne "/ref-in-want/ and print" out >out.filter &&
- test_file_not_empty out.filter
+ test_grep "ref-in-want" out
'
test_expect_success 'invalid want-ref line' '
@@ -462,7 +459,7 @@ test_expect_success 'setup repos for change-while-negotiating test' '
test_commit m3 &&
git tag -d m2 m3
) &&
- git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_perl/repo" &&
+ git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_script/repo" &&
git -C "$LOCAL_PRISTINE" config protocol.version 2
'
@@ -475,10 +472,12 @@ inconsistency () {
# RPCs during a single negotiation.
oid1=$(git -C "$REPO" rev-parse $1) &&
oid2=$(git -C "$REPO" rev-parse $2) &&
- echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-perl"
+ write_script "$HTTPD_ROOT_PATH/one-time-script" <<-EOF
+ sed "s/$oid1/$oid2/" "\$1"
+ EOF
}
-test_expect_success 'server is initially ahead - no ref in want' '
+test_expect_success PERL_TEST_HELPERS 'server is initially ahead - no ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant false &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
@@ -487,7 +486,7 @@ test_expect_success 'server is initially ahead - no ref in want' '
test_grep "fatal: remote error: upload-pack: not our ref" err
'
-test_expect_success 'server is initially ahead - ref in want' '
+test_expect_success PERL_TEST_HELPERS 'server is initially ahead - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
@@ -499,7 +498,7 @@ test_expect_success 'server is initially ahead - ref in want' '
test_cmp expected actual
'
-test_expect_success 'server is initially behind - no ref in want' '
+test_expect_success PERL_TEST_HELPERS 'server is initially behind - no ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant false &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
@@ -511,7 +510,7 @@ test_expect_success 'server is initially behind - no ref in want' '
test_cmp expected actual
'
-test_expect_success 'server is initially behind - ref in want' '
+test_expect_success PERL_TEST_HELPERS 'server is initially behind - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
@@ -523,11 +522,13 @@ test_expect_success 'server is initially behind - ref in want' '
test_cmp expected actual
'
-test_expect_success 'server loses a ref - ref in want' '
+test_expect_success PERL_TEST_HELPERS 'server loses a ref - ref in want' '
git -C "$REPO" config uploadpack.allowRefInWant true &&
rm -rf local &&
cp -r "$LOCAL_PRISTINE" local &&
- echo "s/main/rain/" >"$HTTPD_ROOT_PATH/one-time-perl" &&
+ write_script "$HTTPD_ROOT_PATH/one-time-script" <<-\EOF &&
+ sed "s/main/rain/" "$1"
+ EOF
test_must_fail git -C local fetch 2>err &&
test_grep "fatal: remote error: unknown ref refs/heads/rain" err
diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh
new file mode 100755
index 0000000000..cb061b1f35
--- /dev/null
+++ b/t/t5710-promisor-remote-capability.sh
@@ -0,0 +1,379 @@
+#!/bin/sh
+
+test_description='handling of promisor remote advertisement'
+
+. ./test-lib.sh
+
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping promisor remote capabilities tests; Perl not available'
+ test_done
+fi
+
+GIT_TEST_MULTI_PACK_INDEX=0
+GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0
+
+# Setup the repository with three commits, this way HEAD is always
+# available and we can hide commit 1 or 2.
+test_expect_success 'setup: create "template" repository' '
+ git init template &&
+ test_commit -C template 1 &&
+ test_commit -C template 2 &&
+ test_commit -C template 3 &&
+ test-tool genrandom foo 10240 >template/foo &&
+ git -C template add foo &&
+ git -C template commit -m foo
+'
+
+# A bare repo will act as a server repo with unpacked objects.
+test_expect_success 'setup: create bare "server" repository' '
+ git clone --bare --no-local template server &&
+ mv server/objects/pack/pack-* . &&
+ packfile=$(ls pack-*.pack) &&
+ git -C server unpack-objects --strict <"$packfile"
+'
+
+check_missing_objects () {
+ git -C "$1" rev-list --objects --all --missing=print > all.txt &&
+ perl -ne 'print if s/^[?]//' all.txt >missing.txt &&
+ test_line_count = "$2" missing.txt &&
+ if test "$2" -lt 2
+ then
+ test "$3" = "$(cat missing.txt)"
+ else
+ test -f "$3" &&
+ sort <"$3" >expected_sorted &&
+ sort <missing.txt >actual_sorted &&
+ test_cmp expected_sorted actual_sorted
+ fi
+}
+
+initialize_server () {
+ count="$1"
+ missing_oids="$2"
+
+ # Repack everything first
+ git -C server -c repack.writebitmaps=false repack -a -d &&
+
+ # Remove promisor file in case they exist, useful when reinitializing
+ rm -rf server/objects/pack/*.promisor &&
+
+ # Repack without the largest object and create a promisor pack on server
+ git -C server -c repack.writebitmaps=false repack -a -d \
+ --filter=blob:limit=5k --filter-to="$(pwd)/pack" &&
+ promisor_file=$(ls server/objects/pack/*.pack | sed "s/\.pack/.promisor/") &&
+ >"$promisor_file" &&
+
+ # Check objects missing on the server
+ check_missing_objects server "$count" "$missing_oids"
+}
+
+copy_to_lop () {
+ oid_path="$(test_oid_to_path $1)" &&
+ path="server/objects/$oid_path" &&
+ path2="lop/objects/$oid_path" &&
+ mkdir -p $(dirname "$path2") &&
+ cp "$path" "$path2"
+}
+
+test_expect_success "setup for testing promisor remote advertisement" '
+ # Create another bare repo called "lop" (for Large Object Promisor)
+ git init --bare lop &&
+
+ # Copy the largest object from server to lop
+ obj="HEAD:foo" &&
+ oid="$(git -C server rev-parse $obj)" &&
+ copy_to_lop "$oid" &&
+
+ initialize_server 1 "$oid" &&
+
+ # Configure lop as promisor remote for server
+ git -C server remote add lop "file://$(pwd)/lop" &&
+ git -C server config remote.lop.promisor true &&
+
+ git -C lop config uploadpack.allowFilter true &&
+ git -C lop config uploadpack.allowAnySHA1InWant true &&
+ git -C server config uploadpack.allowFilter true &&
+ git -C server config uploadpack.allowAnySHA1InWant true
+'
+
+test_expect_success "clone with promisor.advertise set to 'true'" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ # Clone from server to create a client
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=All \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "clone with promisor.advertise set to 'false'" '
+ git -C server config promisor.advertise false &&
+ test_when_finished "rm -rf client" &&
+
+ # Clone from server to create a client
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=All \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is not missing on the server
+ check_missing_objects server 0 "" &&
+
+ # Reinitialize server so that the largest object is missing again
+ initialize_server 1 "$oid"
+'
+
+test_expect_success "clone with promisor.acceptfromserver set to 'None'" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ # Clone from server to create a client
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=None \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is not missing on the server
+ check_missing_objects server 0 "" &&
+
+ # Reinitialize server so that the largest object is missing again
+ initialize_server 1 "$oid"
+'
+
+test_expect_success "init + fetch with promisor.advertise set to 'true'" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ mkdir client &&
+ git -C client init &&
+ git -C client config remote.lop.promisor true &&
+ git -C client config remote.lop.fetch "+refs/heads/*:refs/remotes/lop/*" &&
+ git -C client config remote.lop.url "file://$(pwd)/lop" &&
+ git -C client config remote.server.url "file://$(pwd)/server" &&
+ git -C client config remote.server.fetch "+refs/heads/*:refs/remotes/server/*" &&
+ git -C client config promisor.acceptfromserver All &&
+ GIT_NO_LAZY_FETCH=0 git -C client fetch --filter="blob:limit=5k" server &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ # Clone from server to create a client
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=KnownName \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "clone with 'KnownName' and different remote names" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ # Clone from server to create a client
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.serverTwo.promisor=true \
+ -c remote.serverTwo.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.serverTwo.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=KnownName \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is not missing on the server
+ check_missing_objects server 0 "" &&
+
+ # Reinitialize server so that the largest object is missing again
+ initialize_server 1 "$oid"
+'
+
+test_expect_success "clone with 'KnownName' and missing URL in the config" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ # Clone from server to create a client
+ # Lazy fetching by the client from the LOP will fail because of the
+ # missing URL in the client config, so the server will have to lazy
+ # fetch from the LOP.
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c promisor.acceptfromserver=KnownName \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is not missing on the server
+ check_missing_objects server 0 "" &&
+
+ # Reinitialize server so that the largest object is missing again
+ initialize_server 1 "$oid"
+'
+
+test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ # Clone from server to create a client
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=KnownUrl \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "clone with 'KnownUrl' and different remote urls" '
+ ln -s lop serverTwo &&
+
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ # Clone from server to create a client
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/serverTwo" \
+ -c promisor.acceptfromserver=KnownUrl \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is not missing on the server
+ check_missing_objects server 0 "" &&
+
+ # Reinitialize server so that the largest object is missing again
+ initialize_server 1 "$oid"
+'
+
+test_expect_success "clone with 'KnownUrl' and url not configured on the server" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" &&
+ git -C server config unset remote.lop.url &&
+
+ # Clone from server to create a client
+ # It should fail because the client will reject the LOP as URLs are
+ # different, and the server cannot lazy fetch as the LOP URL is
+ # missing, so the remote name will be used instead which will fail.
+ test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=KnownUrl \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" '
+ git -C server config promisor.advertise true &&
+ test_when_finished "rm -rf client" &&
+
+ test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" &&
+ git -C server config set remote.lop.url "" &&
+
+ # Clone from server to create a client
+ # It should fail because the client will reject the LOP as an empty URL is
+ # not advertised, and the server cannot lazy fetch as the LOP URL is empty,
+ # so the remote name will be used instead which will fail.
+ test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=KnownUrl \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "clone with promisor.advertise set to 'true' but don't delete the client" '
+ git -C server config promisor.advertise true &&
+
+ # Clone from server to create a client
+ GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+ -c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
+ -c remote.lop.url="file://$(pwd)/lop" \
+ -c promisor.acceptfromserver=All \
+ --no-local --filter="blob:limit=5k" server client &&
+
+ # Check that the largest object is still missing on the server
+ check_missing_objects server 1 "$oid"
+'
+
+test_expect_success "setup for subsequent fetches" '
+ # Generate new commit with large blob
+ test-tool genrandom bar 10240 >template/bar &&
+ git -C template add bar &&
+ git -C template commit -m bar &&
+
+ # Fetch new commit with large blob
+ git -C server fetch origin &&
+ git -C server update-ref HEAD FETCH_HEAD &&
+ git -C server rev-parse HEAD >expected_head &&
+
+ # Repack everything twice and remove .promisor files before
+ # each repack. This makes sure everything gets repacked
+ # into a single packfile. The second repack is necessary
+ # because the first one fetches from lop and creates a new
+ # packfile and its associated .promisor file.
+
+ rm -f server/objects/pack/*.promisor &&
+ git -C server -c repack.writebitmaps=false repack -a -d &&
+ rm -f server/objects/pack/*.promisor &&
+ git -C server -c repack.writebitmaps=false repack -a -d &&
+
+ # Unpack everything
+ rm pack-* &&
+ mv server/objects/pack/pack-* . &&
+ packfile=$(ls pack-*.pack) &&
+ git -C server unpack-objects --strict <"$packfile" &&
+
+ # Copy new large object to lop
+ obj_bar="HEAD:bar" &&
+ oid_bar="$(git -C server rev-parse $obj_bar)" &&
+ copy_to_lop "$oid_bar" &&
+
+ # Reinitialize server so that the 2 largest objects are missing
+ printf "%s\n" "$oid" "$oid_bar" >expected_missing.txt &&
+ initialize_server 2 expected_missing.txt &&
+
+ # Create one more client
+ cp -r client client2
+'
+
+test_expect_success "subsequent fetch from a client when promisor.advertise is true" '
+ git -C server config promisor.advertise true &&
+
+ GIT_NO_LAZY_FETCH=0 git -C client pull origin &&
+
+ git -C client rev-parse HEAD >actual &&
+ test_cmp expected_head actual &&
+
+ cat client/bar >/dev/null &&
+
+ check_missing_objects server 2 expected_missing.txt
+'
+
+test_expect_success "subsequent fetch from a client when promisor.advertise is false" '
+ git -C server config promisor.advertise false &&
+
+ GIT_NO_LAZY_FETCH=0 git -C client2 pull origin &&
+
+ git -C client2 rev-parse HEAD >actual &&
+ test_cmp expected_head actual &&
+
+ cat client2/bar >/dev/null &&
+
+ check_missing_objects server 1 "$oid"
+'
+
+test_done
diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh
index 6289a2e8b0..fec16448cf 100755
--- a/t/t6000-rev-list-misc.sh
+++ b/t/t6000-rev-list-misc.sh
@@ -182,4 +182,70 @@ test_expect_success 'rev-list --unpacked' '
test_cmp expect actual
'
+test_expect_success 'rev-list one-sided unrelated symmetric diff' '
+ test_tick &&
+ git commit --allow-empty -m xyz &&
+ git branch cmp &&
+ git rebase --force-rebase --root &&
+
+ git rev-list --left-only HEAD...cmp >head &&
+ git rev-list --right-only HEAD...cmp >cmp &&
+
+ sort head >head.sorted &&
+ sort cmp >cmp.sorted &&
+ comm -12 head.sorted cmp.sorted >actual &&
+ test_line_count = 0 actual
+'
+
+test_expect_success 'rev-list -z' '
+ test_when_finished rm -rf repo &&
+
+ git init repo &&
+ test_commit -C repo 1 &&
+ test_commit -C repo 2 &&
+
+ oid1=$(git -C repo rev-parse HEAD~) &&
+ oid2=$(git -C repo rev-parse HEAD) &&
+
+ printf "%s\0%s\0" "$oid2" "$oid1" >expect &&
+ git -C repo rev-list -z HEAD >actual &&
+
+ test_cmp expect actual
+'
+
+test_expect_success 'rev-list -z --objects' '
+ test_when_finished rm -rf repo &&
+
+ git init repo &&
+ test_commit -C repo 1 &&
+ test_commit -C repo 2 &&
+
+ oid1=$(git -C repo rev-parse HEAD:1.t) &&
+ oid2=$(git -C repo rev-parse HEAD:2.t) &&
+ path1=1.t &&
+ path2=2.t &&
+
+ printf "%s\0path=%s\0%s\0path=%s\0" "$oid1" "$path1" "$oid2" "$path2" \
+ >expect &&
+ git -C repo rev-list -z --objects HEAD:1.t HEAD:2.t >actual &&
+
+ test_cmp expect actual
+'
+
+test_expect_success 'rev-list -z --boundary' '
+ test_when_finished rm -rf repo &&
+
+ git init repo &&
+ test_commit -C repo 1 &&
+ test_commit -C repo 2 &&
+
+ oid1=$(git -C repo rev-parse HEAD~) &&
+ oid2=$(git -C repo rev-parse HEAD) &&
+
+ printf "%s\0%s\0boundary=yes\0" "$oid2" "$oid1" >expect &&
+ git -C repo rev-list -z --boundary HEAD~.. >actual &&
+
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t6011-rev-list-with-bad-commit.sh b/t/t6011-rev-list-with-bad-commit.sh
index bad02cf5b8..1dd1e50d21 100755
--- a/t/t6011-rev-list-with-bad-commit.sh
+++ b/t/t6011-rev-list-with-bad-commit.sh
@@ -35,11 +35,16 @@ test_expect_success 'verify number of revisions' \
first_commit=$(git rev-parse HEAD~3)
'
-test_expect_success 'corrupt second commit object' \
- '
- perl -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack &&
- test_must_fail git fsck --full
- '
+test_expect_success 'corrupt second commit object' '
+ for p in .git/objects/pack/*.pack
+ do
+ chmod +w "$p" &&
+ sed "s/second commit/socond commit/" "$p" >"$p.munged" &&
+ mv "$p.munged" "$p" ||
+ return 1
+ done &&
+ test_must_fail git fsck --full
+'
test_expect_success 'rev-list should fail' '
test_must_fail env GIT_TEST_COMMIT_GRAPH=0 git -c core.commitGraph=false rev-list --all > /dev/null
diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh
index de1e87f162..4cecb6224c 100755
--- a/t/t6012-rev-list-simplify.sh
+++ b/t/t6012-rev-list-simplify.sh
@@ -177,7 +177,7 @@ test_expect_success '--full-diff is not affected by --parents' '
# \ / /\ /
# `---X--' `---Y--'
#
-# This example is explained in Documentation/rev-list-options.txt
+# This example is explained in Documentation/rev-list-options.adoc
test_expect_success 'setup rebuild repo' '
rm -rf .git * &&
diff --git a/t/t6013-rev-list-reverse-parents.sh b/t/t6013-rev-list-reverse-parents.sh
index 39793cbbd6..273196f52b 100755
--- a/t/t6013-rev-list-reverse-parents.sh
+++ b/t/t6013-rev-list-reverse-parents.sh
@@ -26,17 +26,19 @@ test_expect_success 'set up --reverse example' '
commit five
'
+reverse () {
+ awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }'
+}
+
test_expect_success '--reverse --parents --full-history combines correctly' '
- git rev-list --parents --full-history main -- foo |
- perl -e "print reverse <>" > expected &&
+ git rev-list --parents --full-history main -- foo | reverse >expected &&
git rev-list --reverse --parents --full-history main -- foo \
> actual &&
test_cmp expected actual
'
test_expect_success '--boundary does too' '
- git rev-list --boundary --parents --full-history main ^root -- foo |
- perl -e "print reverse <>" > expected &&
+ git rev-list --boundary --parents --full-history main ^root -- foo | reverse >expected &&
git rev-list --boundary --reverse --parents --full-history \
main ^root -- foo > actual &&
test_cmp expected actual
diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh
index 4ce62feaa2..500c81b8a1 100755
--- a/t/t6020-bundle-misc.sh
+++ b/t/t6020-bundle-misc.sh
@@ -246,7 +246,11 @@ test_expect_success 'create bundle with --since option' '
EOF
test_cmp expect actual &&
- git bundle create since.bdl \
+ # If a different name hash function is used, then one fewer
+ # delta base is found and this counts a different number
+ # of objects after performing --fix-thin.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git bundle create since.bdl \
--since "Thu Apr 7 15:27:00 2005 -0700" \
--all &&
@@ -669,6 +673,59 @@ test_expect_success 'bundle progress with --no-quiet' '
grep "%" err
'
+test_expect_success 'create bundle with duplicate refnames' '
+ git bundle create out.bdl "main" "main" &&
+
+ git bundle list-heads out.bdl |
+ make_user_friendly_and_stable_output >actual &&
+ cat >expect <<-\EOF &&
+ <COMMIT-P> refs/heads/main
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'create bundle with duplicate refnames and --all' '
+ git bundle create out.bdl --all "main" "main" &&
+
+ git bundle list-heads out.bdl |
+ make_user_friendly_and_stable_output >actual &&
+ cat >expect <<-\EOF &&
+ <COMMIT-P> refs/heads/main
+ <COMMIT-N> refs/heads/release
+ <COMMIT-D> refs/heads/topic/1
+ <COMMIT-H> refs/heads/topic/2
+ <COMMIT-D> refs/pull/1/head
+ <COMMIT-G> refs/pull/2/head
+ <TAG-1> refs/tags/v1
+ <TAG-2> refs/tags/v2
+ <TAG-3> refs/tags/v3
+ <COMMIT-P> HEAD
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'create bundle with duplicate exlusion refnames' '
+ git bundle create out.bdl "main" "main^!" &&
+
+ git bundle list-heads out.bdl |
+ make_user_friendly_and_stable_output >actual &&
+ cat >expect <<-\EOF &&
+ <COMMIT-P> refs/heads/main
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'create bundle with duplicate refname short-form' '
+ git bundle create out.bdl "main" "main" "refs/heads/main" "refs/heads/main" &&
+
+ git bundle list-heads out.bdl |
+ make_user_friendly_and_stable_output >actual &&
+ cat >expect <<-\EOF &&
+ <COMMIT-P> refs/heads/main
+ EOF
+ test_cmp expect actual
+'
+
test_expect_success 'read bundle over stdin' '
git bundle create some.bundle HEAD &&
diff --git a/t/t6022-rev-list-missing.sh b/t/t6022-rev-list-missing.sh
index 7553a9cca2..08e92dd002 100755
--- a/t/t6022-rev-list-missing.sh
+++ b/t/t6022-rev-list-missing.sh
@@ -145,4 +145,88 @@ do
done
done
+for obj in "HEAD~1" "HEAD^{tree}" "HEAD:foo" "HEAD:foo/bar" "HEAD:baz baz"
+do
+ test_expect_success "--missing=print-info with missing '$obj'" '
+ test_when_finished rm -rf missing-info &&
+
+ git init missing-info &&
+ (
+ cd missing-info &&
+ git commit --allow-empty -m first &&
+
+ mkdir foo &&
+ echo bar >foo/bar &&
+ echo baz >"baz baz" &&
+ echo bat >bat\" &&
+ git add -A &&
+ git commit -m second &&
+
+ oid="$(git rev-parse "$obj")" &&
+ path=".git/objects/$(test_oid_to_path $oid)" &&
+ type_info=" type=$(git cat-file -t $oid)" &&
+
+ case $obj in
+ HEAD:foo)
+ path_info=" path=foo"
+ ;;
+ HEAD:foo/bar)
+ path_info=" path=foo/bar"
+ ;;
+ "HEAD:baz baz")
+ path_info=" path=\"baz baz\""
+ ;;
+ "HEAD:bat\"")
+ path_info=" path=\"bat\\\"\""
+ ;;
+ esac &&
+
+ # Before the object is made missing, we use rev-list to
+ # get the expected oids.
+ git rev-list --objects --no-object-names \
+ HEAD ^"$obj" >expect.raw &&
+ echo "?$oid$path_info$type_info" >>expect.raw &&
+
+ mv "$path" "$path.hidden" &&
+ git rev-list --objects --no-object-names \
+ --missing=print-info HEAD >actual.raw &&
+
+ sort actual.raw >actual &&
+ sort expect.raw >expect &&
+ test_cmp expect actual
+ )
+ '
+done
+
+test_expect_success "-z nul-delimited --missing" '
+ test_when_finished rm -rf repo &&
+
+ git init repo &&
+ (
+ cd repo &&
+ git commit --allow-empty -m first &&
+
+ path="foo bar" &&
+ echo foobar >"$path" &&
+ git add -A &&
+ git commit -m second &&
+
+ oid=$(git rev-parse "HEAD:$path") &&
+ type="$(git cat-file -t $oid)" &&
+
+ obj_path=".git/objects/$(test_oid_to_path $oid)" &&
+
+ git rev-list -z --objects --no-object-names \
+ HEAD ^"$oid" >expect &&
+ printf "%s\0missing=yes\0path=%s\0type=%s\0" "$oid" "$path" \
+ "$type" >>expect &&
+
+ mv "$obj_path" "$obj_path.hidden" &&
+ git rev-list -z --objects --no-object-names \
+ --missing=print-info HEAD >actual &&
+
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/t/t6102-rev-list-unexpected-objects.sh b/t/t6102-rev-list-unexpected-objects.sh
index 22dfd6d978..eb98b3919c 100755
--- a/t/t6102-rev-list-unexpected-objects.sh
+++ b/t/t6102-rev-list-unexpected-objects.sh
@@ -4,6 +4,12 @@ test_description='git rev-list should handle unexpected object types'
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping rev-list unexpected objects tests; Perl not available'
+ test_done
+fi
+
test_expect_success 'setup well-formed objects' '
blob="$(printf "foo" | git hash-object -w --stdin)" &&
tree="$(printf "100644 blob $blob\tfoo" | git mktree)" &&
diff --git a/t/t6115-rev-list-du.sh b/t/t6115-rev-list-du.sh
index 3385fe9f13..04c577dad6 100755
--- a/t/t6115-rev-list-du.sh
+++ b/t/t6115-rev-list-du.sh
@@ -22,7 +22,7 @@ test_expect_success 'set up repository' '
disk_usage_slow () {
git rev-list --no-object-names "$@" |
git cat-file --batch-check="%(objectsize:disk)" |
- perl -lne '$total += $_; END { print $total}'
+ awk '{ i += $1 } END { print i }'
}
# check behavior with given rev-list options; note that
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index 3f6160d702..2c70cc561a 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -82,11 +82,13 @@ check_describe R-2-gHASH HEAD^^
check_describe A-3-gHASH HEAD^^2
check_describe B HEAD^^2^
check_describe R-1-gHASH HEAD^^^
+check_describe R-1-gHASH R-1-g$(git rev-parse --short HEAD^^)~1
check_describe c-7-gHASH --tags HEAD
check_describe c-6-gHASH --tags HEAD^
check_describe e-1-gHASH --tags HEAD^^
check_describe c-2-gHASH --tags HEAD^^2
+check_describe c-2-gHASH --tags c-2-g$(git rev-parse --short HEAD^^2)^0
check_describe B --tags HEAD^^2^
check_describe e --tags HEAD^^^
check_describe e --tags --exact-match HEAD^^^
@@ -290,15 +292,23 @@ test_expect_success 'name-rev --annotate-stdin' '
echo "$rev ($name)" >>expect.unsorted || return 1
done &&
sort <expect.unsorted >expect &&
- git rev-list --all | git name-rev --annotate-stdin >actual.unsorted &&
+ git rev-list --all >list &&
+ git name-rev --annotate-stdin <list >actual.unsorted &&
sort <actual.unsorted >actual &&
test_cmp expect actual
'
-test_expect_success 'name-rev --stdin deprecated' "
- git rev-list --all | git name-rev --stdin 2>actual &&
- grep -E 'warning: --stdin is deprecated' actual
-"
+test_expect_success 'name-rev --stdin deprecated' '
+ git rev-list --all >list &&
+ if ! test_have_prereq WITH_BREAKING_CHANGES
+ then
+ git name-rev --stdin <list 2>actual &&
+ test_grep "warning: --stdin is deprecated" actual
+ else
+ test_must_fail git name-rev --stdin <list 2>actual &&
+ test_grep "unknown option .stdin." actual
+ fi
+'
test_expect_success 'describe --contains with the exact tags' '
echo "A^0" >expect &&
@@ -399,6 +409,36 @@ test_expect_success 'describe tag object' '
test_grep "fatal: test-blob-1 is neither a commit nor blob" actual
'
+test_expect_success 'describe an unreachable blob' '
+ blob=$(echo not-found-anywhere | git hash-object -w --stdin) &&
+ test_must_fail git describe $blob 2>actual &&
+ test_grep "blob .$blob. not reachable from HEAD" actual
+'
+
+test_expect_success 'describe blob on an unborn branch' '
+ oldbranch=$(git symbolic-ref HEAD) &&
+ test_when_finished "git symbolic-ref HEAD $oldbranch" &&
+ git symbolic-ref HEAD refs/heads/does-not-exist &&
+ test_must_fail git describe test-blob 2>actual &&
+ test_grep "cannot search .* on an unborn branch" actual
+'
+
+# This test creates a repository state that we generally try to disallow: HEAD
+# is pointing to an object that is not a commit. The ref update code forbids
+# non-commit writes directly to HEAD or to any branch in refs/heads/. But we
+# can use the loophole of pointing HEAD to another non-branch ref (something we
+# should forbid, but don't for historical reasons).
+#
+# Do not take this test as an endorsement of the loophole! If we ever tighten
+# it, it is reasonable to just drop this test entirely.
+test_expect_success 'describe blob on a non-commit HEAD' '
+ oldbranch=$(git symbolic-ref HEAD) &&
+ test_when_finished "git symbolic-ref HEAD $oldbranch" &&
+ git symbolic-ref HEAD refs/tags/test-blob &&
+ test_must_fail git describe test-blob 2>actual &&
+ test_grep "blob .* not reachable from HEAD" actual
+'
+
test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' '
i=1 &&
while test $i -lt 8000
@@ -725,4 +765,26 @@ test_expect_success '--exact-match does not show --always fallback' '
test_must_fail git describe --exact-match --always
'
+test_expect_success 'avoid being fooled by describe-like filename' '
+ test_when_finished rm out &&
+
+ git rev-parse --short HEAD >out &&
+ FILENAME=filename-g$(cat out) &&
+ touch $FILENAME &&
+ git add $FILENAME &&
+ git commit -m "Add $FILENAME" &&
+
+ git cat-file -t HEAD:$FILENAME >actual &&
+
+ echo blob >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'do not be fooled by invalid describe format ' '
+ test_when_finished rm out &&
+
+ git rev-parse --short HEAD >out &&
+ test_must_fail git cat-file -t "refs/tags/super-invalid/./../...../ ~^:/?*[////\\\\\\&}/busted.lock-42-g"$(cat out)
+'
+
test_done
diff --git a/t/t6137-pathspec-wildcards-literal.sh b/t/t6137-pathspec-wildcards-literal.sh
new file mode 100755
index 0000000000..17a03085ef
--- /dev/null
+++ b/t/t6137-pathspec-wildcards-literal.sh
@@ -0,0 +1,429 @@
+#!/bin/sh
+test_description='test wildcards and literals with git add/commit (subshell style)'
+
+. ./test-lib.sh
+
+test_have_prereq BSLASHPSPEC || {
+ skip_all='skipping: needs BSLASHPSPEC (backslashes in pathspecs)'
+ test_done
+}
+
+prepare_test_files () {
+ for f in "*" "**" "?" "[abc]" "a" "f*" "f**" "f?z" "foo*bar" "hello?world" "hello_world"
+ do
+ >"$f" || return
+ done
+}
+
+test_expect_success 'add wildcard *' '
+ git init test-asterisk &&
+ (
+ cd test-asterisk &&
+ prepare_test_files &&
+ git add "*" &&
+ cat >expect <<-EOF &&
+ *
+ **
+ ?
+ [abc]
+ a
+ f*
+ f**
+ f?z
+ foo*bar
+ hello?world
+ hello_world
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add literal \*' '
+ git init test-asterisk-literal &&
+ (
+ cd test-asterisk-literal &&
+ prepare_test_files &&
+ git add "\*" &&
+ cat >expect <<-EOF &&
+ *
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add wildcard **' '
+ git init test-dstar &&
+ (
+ cd test-dstar &&
+ prepare_test_files &&
+ git add "**" &&
+ cat >expect <<-EOF &&
+ *
+ **
+ ?
+ [abc]
+ a
+ f*
+ f**
+ f?z
+ foo*bar
+ hello?world
+ hello_world
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add wildcard ?' '
+ git init test-qmark &&
+ (
+ cd test-qmark &&
+ prepare_test_files &&
+ git add "?" &&
+ cat >expect <<-\EOF | sort &&
+ *
+ ?
+ a
+ EOF
+ git ls-files | sort >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add wildcard [abc]' '
+ git init test-brackets &&
+ (
+ cd test-brackets &&
+ prepare_test_files &&
+ git add "[abc]" &&
+ cat >expect <<-\EOF | sort &&
+ [abc]
+ a
+ EOF
+ git ls-files | sort >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add wildcard f*' '
+ git init test-f-wild &&
+ (
+ cd test-f-wild &&
+ prepare_test_files &&
+ git add "f*" &&
+ cat >expect <<-\EOF | sort &&
+ f*
+ f**
+ f?z
+ foo*bar
+ EOF
+ git ls-files | sort >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add literal f\*' '
+ git init test-f-lit &&
+ (
+ cd test-f-lit &&
+ prepare_test_files &&
+ git add "f\*" &&
+ cat >expect <<-\EOF &&
+ f*
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add wildcard f**' '
+ git init test-fdstar &&
+ (
+ cd test-fdstar &&
+ prepare_test_files &&
+ git add "f**" &&
+ cat >expect <<-\EOF | sort &&
+ f*
+ f**
+ f?z
+ foo*bar
+ EOF
+ git ls-files | sort >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add literal f\*\*' '
+ git init test-fdstar-lit &&
+ (
+ cd test-fdstar-lit &&
+ prepare_test_files &&
+ git add "f\*\*" &&
+ cat >expect <<-\EOF &&
+ f**
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add wildcard f?z' '
+ git init test-fqz &&
+ (
+ cd test-fqz &&
+ prepare_test_files &&
+ git add "f?z" &&
+ cat >expect <<-\EOF &&
+ f?z
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add literal \?' '
+ git init test-q-lit &&
+ (
+ cd test-q-lit &&
+ prepare_test_files &&
+ git add "\?" &&
+ cat >expect <<-\EOF &&
+ ?
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add wildcard foo*bar' '
+ git init test-foobar &&
+ (
+ cd test-foobar &&
+ prepare_test_files &&
+ git add "foo*bar" &&
+ cat >expect <<-\EOF &&
+ foo*bar
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add wildcard hello?world' '
+ git init test-hellowild &&
+ (
+ cd test-hellowild &&
+ prepare_test_files &&
+ git add "hello?world" &&
+ cat >expect <<-\EOF &&
+ hello?world
+ hello_world
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add literal hello\?world' '
+ git init test-hellolit &&
+ (
+ cd test-hellolit &&
+ prepare_test_files &&
+ git add "hello\?world" &&
+ cat >expect <<-\EOF &&
+ hello?world
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'add literal \[abc\]' '
+ git init test-brackets-lit &&
+ (
+ cd test-brackets-lit &&
+ prepare_test_files &&
+ git add "\[abc\]" &&
+ cat >expect <<-\EOF &&
+ [abc]
+ EOF
+ git ls-files >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'commit: wildcard *' '
+ git init test-c-asterisk &&
+ (
+ cd test-c-asterisk &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c1" -- "*" &&
+ cat >expect <<-EOF &&
+ *
+ **
+ ?
+ [abc]
+ a
+ f*
+ f**
+ f?z
+ foo*bar
+ hello?world
+ hello_world
+ EOF
+ git ls-tree -r --name-only HEAD >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'commit: literal \*' '
+ git init test-c-asterisk-lit &&
+ (
+ cd test-c-asterisk-lit &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c2" -- "\*" &&
+ cat >expect <<-EOF &&
+ *
+ EOF
+ git ls-tree -r --name-only HEAD >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'commit: wildcard f*' '
+ git init test-c-fwild &&
+ (
+ cd test-c-fwild &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c3" -- "f*" &&
+ cat >expect <<-EOF &&
+ f*
+ f**
+ f?z
+ foo*bar
+ EOF
+ git ls-tree -r --name-only HEAD >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'commit: literal f\*' '
+ git init test-c-flit &&
+ (
+ cd test-c-flit &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c4" -- "f\*" &&
+ cat >expect <<-EOF &&
+ f*
+ EOF
+ git ls-tree -r --name-only HEAD >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'commit: wildcard f**' '
+ git init test-c-pathlimit &&
+ (
+ cd test-c-pathlimit &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c5" -- "f**" &&
+ cat >expect <<-EOF &&
+ f*
+ f**
+ f?z
+ foo*bar
+ EOF
+ git ls-tree -r --name-only HEAD >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'commit: literal f\*\*' '
+ git init test-c-fdstar-lit &&
+ (
+ cd test-c-fdstar-lit &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c6" -- "f\*\*" &&
+ cat >expect <<-EOF &&
+ f**
+ EOF
+ git ls-tree -r --name-only HEAD >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'commit: wildcard ?' '
+ git init test-c-qwild &&
+ (
+ cd test-c-qwild &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c7" -- "?" &&
+ cat >expect <<-EOF &&
+ *
+ ?
+ a
+ EOF
+ git ls-tree -r --name-only HEAD | sort >actual &&
+ sort expect >expect.sorted &&
+ test_cmp expect.sorted actual
+ )
+'
+
+test_expect_success 'commit: literal \?' '
+ git init test-c-qlit &&
+ (
+ cd test-c-qlit &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c8" -- "\?" &&
+ cat >expect <<-EOF &&
+ ?
+ EOF
+ git ls-tree -r --name-only HEAD >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'commit: wildcard hello?world' '
+ git init test-c-hellowild &&
+ (
+ cd test-c-hellowild &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c9" -- "hello?world" &&
+ cat >expect <<-EOF &&
+ hello?world
+ hello_world
+ EOF
+ git ls-tree -r --name-only HEAD | sort >actual &&
+ sort expect >expect.sorted &&
+ test_cmp expect.sorted actual
+ )
+'
+
+test_expect_success 'commit: literal hello\?world' '
+ git init test-c-hellolit &&
+ (
+ cd test-c-hellolit &&
+ prepare_test_files &&
+ git add . &&
+ git commit -m "c10" -- "hello\?world" &&
+ cat >expect <<-EOF &&
+ hello?world
+ EOF
+ git ls-tree -r --name-only HEAD >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_done
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index a5c7794385..1d9809114d 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -6,2138 +6,14 @@
test_description='for-each-ref test'
. ./test-lib.sh
-GNUPGHOME_NOT_USED=$GNUPGHOME
-. "$TEST_DIRECTORY"/lib-gpg.sh
-. "$TEST_DIRECTORY"/lib-terminal.sh
-# Mon Jul 3 23:18:43 2006 +0000
-datestamp=1151968723
-setdate_and_increment () {
- GIT_COMMITTER_DATE="$datestamp +0200"
- datestamp=$(expr "$datestamp" + 1)
- GIT_AUTHOR_DATE="$datestamp +0200"
- datestamp=$(expr "$datestamp" + 1)
- export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
-}
-
-test_object_file_size () {
- oid=$(git rev-parse "$1")
- path=".git/objects/$(test_oid_to_path $oid)"
- test_file_size "$path"
-}
-
-test_expect_success setup '
- # setup .mailmap
- cat >.mailmap <<-EOF &&
- A Thor <athor@example.com> A U Thor <author@example.com>
- C Mitter <cmitter@example.com> C O Mitter <committer@example.com>
- EOF
-
- setdate_and_increment &&
- echo "Using $datestamp" > one &&
- git add one &&
- git commit -m "Initial" &&
- git branch -M main &&
- setdate_and_increment &&
- git tag -a -m "Tagging at $datestamp" testtag &&
- git update-ref refs/remotes/origin/main main &&
- git remote add origin nowhere &&
- git config branch.main.remote origin &&
- git config branch.main.merge refs/heads/main &&
- git remote add myfork elsewhere &&
- git config remote.pushdefault myfork &&
- git config push.default current
-'
-
-test_atom () {
- case "$1" in
- head) ref=refs/heads/main ;;
- tag) ref=refs/tags/testtag ;;
- sym) ref=refs/heads/sym ;;
- *) ref=$1 ;;
- esac
- format=$2
- test_do=test_expect_${4:-success}
-
- printf '%s\n' "$3" >expected
- $test_do $PREREQ "basic atom: $ref $format" '
- git for-each-ref --format="%($format)" "$ref" >actual &&
- sanitize_pgp <actual >actual.clean &&
- test_cmp expected actual.clean
- '
-
- # Automatically test "contents:size" atom after testing "contents"
- if test "$format" = "contents"
- then
- # for commit leg, $3 is changed there
- expect=$(printf '%s' "$3" | wc -c)
- $test_do $PREREQ "basic atom: $ref contents:size" '
- type=$(git cat-file -t "$ref") &&
- case $type in
- tag)
- # We cannot use $3 as it expects sanitize_pgp to run
- git cat-file tag $ref >out &&
- expect=$(tail -n +6 out | wc -c) &&
- rm -f out ;;
- tree | blob)
- expect="" ;;
- commit)
- : "use the calculated expect" ;;
- *)
- BUG "unknown object type" ;;
- esac &&
- # Leave $expect unquoted to lose possible leading whitespaces
- echo $expect >expected &&
- git for-each-ref --format="%(contents:size)" "$ref" >actual &&
- test_cmp expected actual
- '
- fi
-}
-
-hexlen=$(test_oid hexsz)
-
-test_atom head refname refs/heads/main
-test_atom head refname: refs/heads/main
-test_atom head refname:short main
-test_atom head refname:lstrip=1 heads/main
-test_atom head refname:lstrip=2 main
-test_atom head refname:lstrip=-1 main
-test_atom head refname:lstrip=-2 heads/main
-test_atom head refname:rstrip=1 refs/heads
-test_atom head refname:rstrip=2 refs
-test_atom head refname:rstrip=-1 refs
-test_atom head refname:rstrip=-2 refs/heads
-test_atom head refname:strip=1 heads/main
-test_atom head refname:strip=2 main
-test_atom head refname:strip=-1 main
-test_atom head refname:strip=-2 heads/main
-test_atom head upstream refs/remotes/origin/main
-test_atom head upstream:short origin/main
-test_atom head upstream:lstrip=2 origin/main
-test_atom head upstream:lstrip=-2 origin/main
-test_atom head upstream:rstrip=2 refs/remotes
-test_atom head upstream:rstrip=-2 refs/remotes
-test_atom head upstream:strip=2 origin/main
-test_atom head upstream:strip=-2 origin/main
-test_atom head push refs/remotes/myfork/main
-test_atom head push:short myfork/main
-test_atom head push:lstrip=1 remotes/myfork/main
-test_atom head push:lstrip=-1 main
-test_atom head push:rstrip=1 refs/remotes/myfork
-test_atom head push:rstrip=-1 refs
-test_atom head push:strip=1 remotes/myfork/main
-test_atom head push:strip=-1 main
-test_atom head objecttype commit
-test_atom head objectsize $((131 + hexlen))
-test_atom head objectsize:disk $(test_object_file_size refs/heads/main)
-test_atom head deltabase $ZERO_OID
-test_atom head objectname $(git rev-parse refs/heads/main)
-test_atom head objectname:short $(git rev-parse --short refs/heads/main)
-test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
-test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
-test_atom head tree $(git rev-parse refs/heads/main^{tree})
-test_atom head tree:short $(git rev-parse --short refs/heads/main^{tree})
-test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/main^{tree})
-test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/main^{tree})
-test_atom head parent ''
-test_atom head parent:short ''
-test_atom head parent:short=1 ''
-test_atom head parent:short=10 ''
-test_atom head numparent 0
-test_atom head object ''
-test_atom head type ''
-test_atom head raw "$(git cat-file commit refs/heads/main)
-"
-test_atom head '*objectname' ''
-test_atom head '*objecttype' ''
-test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
-test_atom head authorname 'A U Thor'
-test_atom head authorname:mailmap 'A Thor'
-test_atom head authoremail '<author@example.com>'
-test_atom head authoremail:trim 'author@example.com'
-test_atom head authoremail:localpart 'author'
-test_atom head authoremail:trim,localpart 'author'
-test_atom head authoremail:mailmap '<athor@example.com>'
-test_atom head authoremail:mailmap,trim 'athor@example.com'
-test_atom head authoremail:trim,mailmap 'athor@example.com'
-test_atom head authoremail:mailmap,localpart 'athor'
-test_atom head authoremail:localpart,mailmap 'athor'
-test_atom head authoremail:mailmap,trim,localpart,mailmap,trim 'athor'
-test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
-test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
-test_atom head committername 'C O Mitter'
-test_atom head committername:mailmap 'C Mitter'
-test_atom head committeremail '<committer@example.com>'
-test_atom head committeremail:trim 'committer@example.com'
-test_atom head committeremail:localpart 'committer'
-test_atom head committeremail:localpart,trim 'committer'
-test_atom head committeremail:mailmap '<cmitter@example.com>'
-test_atom head committeremail:mailmap,trim 'cmitter@example.com'
-test_atom head committeremail:trim,mailmap 'cmitter@example.com'
-test_atom head committeremail:mailmap,localpart 'cmitter'
-test_atom head committeremail:localpart,mailmap 'cmitter'
-test_atom head committeremail:trim,mailmap,trim,trim,localpart 'cmitter'
-test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
-test_atom head tag ''
-test_atom head tagger ''
-test_atom head taggername ''
-test_atom head taggeremail ''
-test_atom head taggeremail:trim ''
-test_atom head taggeremail:localpart ''
-test_atom head taggerdate ''
-test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
-test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
-test_atom head subject 'Initial'
-test_atom head subject:sanitize 'Initial'
-test_atom head contents:subject 'Initial'
-test_atom head body ''
-test_atom head contents:body ''
-test_atom head contents:signature ''
-test_atom head contents 'Initial
-'
-test_atom head HEAD '*'
-
-test_atom tag refname refs/tags/testtag
-test_atom tag refname:short testtag
-test_atom tag upstream ''
-test_atom tag push ''
-test_atom tag objecttype tag
-test_atom tag objectsize $((114 + hexlen))
-test_atom tag objectsize:disk $(test_object_file_size refs/tags/testtag)
-test_atom tag '*objectsize:disk' $(test_object_file_size refs/heads/main)
-test_atom tag deltabase $ZERO_OID
-test_atom tag '*deltabase' $ZERO_OID
-test_atom tag objectname $(git rev-parse refs/tags/testtag)
-test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
-test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
-test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
-test_atom tag tree ''
-test_atom tag tree:short ''
-test_atom tag tree:short=1 ''
-test_atom tag tree:short=10 ''
-test_atom tag parent ''
-test_atom tag parent:short ''
-test_atom tag parent:short=1 ''
-test_atom tag parent:short=10 ''
-test_atom tag numparent ''
-test_atom tag object $(git rev-parse refs/tags/testtag^0)
-test_atom tag type 'commit'
-test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{})
-test_atom tag '*objecttype' 'commit'
-test_atom tag author ''
-test_atom tag authorname ''
-test_atom tag authorname:mailmap ''
-test_atom tag authoremail ''
-test_atom tag authoremail:trim ''
-test_atom tag authoremail:localpart ''
-test_atom tag authoremail:trim,localpart ''
-test_atom tag authoremail:mailmap ''
-test_atom tag authoremail:mailmap,trim ''
-test_atom tag authoremail:trim,mailmap ''
-test_atom tag authoremail:mailmap,localpart ''
-test_atom tag authoremail:localpart,mailmap ''
-test_atom tag authoremail:mailmap,trim,localpart,mailmap,trim ''
-test_atom tag authordate ''
-test_atom tag committer ''
-test_atom tag committername ''
-test_atom tag committername:mailmap ''
-test_atom tag committeremail ''
-test_atom tag committeremail:trim ''
-test_atom tag committeremail:localpart ''
-test_atom tag committeremail:localpart,trim ''
-test_atom tag committeremail:mailmap ''
-test_atom tag committeremail:mailmap,trim ''
-test_atom tag committeremail:trim,mailmap ''
-test_atom tag committeremail:mailmap,localpart ''
-test_atom tag committeremail:localpart,mailmap ''
-test_atom tag committeremail:trim,mailmap,trim,trim,localpart ''
-test_atom tag committerdate ''
-test_atom tag tag 'testtag'
-test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
-test_atom tag taggername 'C O Mitter'
-test_atom tag taggername:mailmap 'C Mitter'
-test_atom tag taggeremail '<committer@example.com>'
-test_atom tag taggeremail:trim 'committer@example.com'
-test_atom tag taggeremail:localpart 'committer'
-test_atom tag taggeremail:trim,localpart 'committer'
-test_atom tag taggeremail:mailmap '<cmitter@example.com>'
-test_atom tag taggeremail:mailmap,trim 'cmitter@example.com'
-test_atom tag taggeremail:trim,mailmap 'cmitter@example.com'
-test_atom tag taggeremail:mailmap,localpart 'cmitter'
-test_atom tag taggeremail:localpart,mailmap 'cmitter'
-test_atom tag taggeremail:trim,mailmap,trim,localpart,localpart 'cmitter'
-test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
-test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
-test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
-test_atom tag subject 'Tagging at 1151968727'
-test_atom tag subject:sanitize 'Tagging-at-1151968727'
-test_atom tag contents:subject 'Tagging at 1151968727'
-test_atom tag body ''
-test_atom tag contents:body ''
-test_atom tag contents:signature ''
-test_atom tag contents 'Tagging at 1151968727
-'
-test_atom tag HEAD ' '
-
-test_expect_success 'basic atom: refs/tags/testtag *raw' '
- git cat-file commit refs/tags/testtag^{} >expected &&
- git for-each-ref --format="%(*raw)" refs/tags/testtag >actual &&
- sanitize_pgp <expected >expected.clean &&
- echo >>expected.clean &&
- sanitize_pgp <actual >actual.clean &&
- test_cmp expected.clean actual.clean
-'
-
-test_expect_success 'Check invalid atoms names are errors' '
- test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
-'
-
-test_expect_success 'Check format specifiers are ignored in naming date atoms' '
- git for-each-ref --format="%(authordate)" refs/heads &&
- git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
- git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
- git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
-'
-
-test_expect_success 'Check valid format specifiers for date fields' '
- git for-each-ref --format="%(authordate:default)" refs/heads &&
- git for-each-ref --format="%(authordate:relative)" refs/heads &&
- git for-each-ref --format="%(authordate:short)" refs/heads &&
- git for-each-ref --format="%(authordate:local)" refs/heads &&
- git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
- git for-each-ref --format="%(authordate:rfc2822)" refs/heads
-'
-
-test_expect_success 'Check invalid format specifiers are errors' '
- test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
-'
-
-test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
- test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
- test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
- test_must_fail git for-each-ref --format="%(objectname:short=foo)"
-'
-
-test_bad_atom () {
- case "$1" in
- head) ref=refs/heads/main ;;
- tag) ref=refs/tags/testtag ;;
- sym) ref=refs/heads/sym ;;
- *) ref=$1 ;;
- esac
- format=$2
- test_do=test_expect_${4:-success}
-
- printf '%s\n' "$3" >expect
- $test_do $PREREQ "err basic atom: $ref $format" '
- test_must_fail git for-each-ref \
- --format="%($format)" "$ref" 2>error &&
- test_cmp expect error
- '
-}
-
-test_bad_atom head 'authoremail:foo' \
- 'fatal: unrecognized %(authoremail) argument: foo'
-
-test_bad_atom head 'authoremail:mailmap,trim,bar' \
- 'fatal: unrecognized %(authoremail) argument: bar'
-
-test_bad_atom head 'authoremail:trim,' \
- 'fatal: unrecognized %(authoremail) argument: '
-
-test_bad_atom head 'authoremail:mailmaptrim' \
- 'fatal: unrecognized %(authoremail) argument: trim'
-
-test_bad_atom head 'committeremail: ' \
- 'fatal: unrecognized %(committeremail) argument: '
-
-test_bad_atom head 'committeremail: trim,foo' \
- 'fatal: unrecognized %(committeremail) argument: trim,foo'
-
-test_bad_atom head 'committeremail:mailmap,localpart ' \
- 'fatal: unrecognized %(committeremail) argument: '
-
-test_bad_atom head 'committeremail:trim_localpart' \
- 'fatal: unrecognized %(committeremail) argument: _localpart'
-
-test_bad_atom head 'committeremail:localpart,,,trim' \
- 'fatal: unrecognized %(committeremail) argument: ,,trim'
-
-test_bad_atom tag 'taggeremail:mailmap,trim, foo ' \
- 'fatal: unrecognized %(taggeremail) argument: foo '
-
-test_bad_atom tag 'taggeremail:trim,localpart,' \
- 'fatal: unrecognized %(taggeremail) argument: '
-
-test_bad_atom tag 'taggeremail:mailmap;localpart trim' \
- 'fatal: unrecognized %(taggeremail) argument: ;localpart trim'
-
-test_bad_atom tag 'taggeremail:localpart trim' \
- 'fatal: unrecognized %(taggeremail) argument: trim'
-
-test_bad_atom tag 'taggeremail:mailmap,mailmap,trim,qux,localpart,trim' \
- 'fatal: unrecognized %(taggeremail) argument: qux,localpart,trim'
-
-test_date () {
- f=$1 &&
- committer_date=$2 &&
- author_date=$3 &&
- tagger_date=$4 &&
- cat >expected <<-EOF &&
- 'refs/heads/main' '$committer_date' '$author_date'
- 'refs/tags/testtag' '$tagger_date'
- EOF
- (
- git for-each-ref --shell \
- --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
- refs/heads &&
- git for-each-ref --shell \
- --format="%(refname) %(taggerdate${f:+:$f})" \
- refs/tags
- ) >actual &&
- test_cmp expected actual
-}
-
-test_expect_success 'Check unformatted date fields output' '
- test_date "" \
- "Tue Jul 4 01:18:43 2006 +0200" \
- "Tue Jul 4 01:18:44 2006 +0200" \
- "Tue Jul 4 01:18:45 2006 +0200"
-'
-
-test_expect_success 'Check format "default" formatted date fields output' '
- test_date default \
- "Tue Jul 4 01:18:43 2006 +0200" \
- "Tue Jul 4 01:18:44 2006 +0200" \
- "Tue Jul 4 01:18:45 2006 +0200"
-'
-
-test_expect_success 'Check format "default-local" date fields output' '
- test_date default-local "Mon Jul 3 23:18:43 2006" "Mon Jul 3 23:18:44 2006" "Mon Jul 3 23:18:45 2006"
-'
-
-# Don't know how to do relative check because I can't know when this script
-# is going to be run and can't fake the current time to git, and hence can't
-# provide expected output. Instead, I'll just make sure that "relative"
-# doesn't exit in error
-test_expect_success 'Check format "relative" date fields output' '
- f=relative &&
- (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
- git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
-'
-
-# We just check that this is the same as "relative" for now.
-test_expect_success 'Check format "relative-local" date fields output' '
- test_date relative-local \
- "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
- "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
- "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
-'
-
-test_expect_success 'Check format "short" date fields output' '
- test_date short 2006-07-04 2006-07-04 2006-07-04
-'
-
-test_expect_success 'Check format "short-local" date fields output' '
- test_date short-local 2006-07-03 2006-07-03 2006-07-03
-'
-
-test_expect_success 'Check format "local" date fields output' '
- test_date local \
- "Mon Jul 3 23:18:43 2006" \
- "Mon Jul 3 23:18:44 2006" \
- "Mon Jul 3 23:18:45 2006"
-'
-
-test_expect_success 'Check format "iso8601" date fields output' '
- test_date iso8601 \
- "2006-07-04 01:18:43 +0200" \
- "2006-07-04 01:18:44 +0200" \
- "2006-07-04 01:18:45 +0200"
-'
-
-test_expect_success 'Check format "iso8601-local" date fields output' '
- test_date iso8601-local "2006-07-03 23:18:43 +0000" "2006-07-03 23:18:44 +0000" "2006-07-03 23:18:45 +0000"
-'
-
-test_expect_success 'Check format "rfc2822" date fields output' '
- test_date rfc2822 \
- "Tue, 4 Jul 2006 01:18:43 +0200" \
- "Tue, 4 Jul 2006 01:18:44 +0200" \
- "Tue, 4 Jul 2006 01:18:45 +0200"
-'
-
-test_expect_success 'Check format "rfc2822-local" date fields output' '
- test_date rfc2822-local "Mon, 3 Jul 2006 23:18:43 +0000" "Mon, 3 Jul 2006 23:18:44 +0000" "Mon, 3 Jul 2006 23:18:45 +0000"
-'
-
-test_expect_success 'Check format "raw" date fields output' '
- test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
-'
-
-test_expect_success 'Check format "raw-local" date fields output' '
- test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
-'
-
-test_expect_success 'Check format of strftime date fields' '
- echo "my date is 2006-07-04" >expected &&
- git for-each-ref \
- --format="%(authordate:format:my date is %Y-%m-%d)" \
- refs/heads >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'Check format of strftime-local date fields' '
- echo "my date is 2006-07-03" >expected &&
- git for-each-ref \
- --format="%(authordate:format-local:my date is %Y-%m-%d)" \
- refs/heads >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'exercise strftime with odd fields' '
- echo >expected &&
- git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
- test_cmp expected actual &&
- long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
- echo $long >expected &&
- git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<\EOF
-refs/heads/main
-refs/remotes/origin/main
-refs/tags/testtag
-EOF
-
-test_expect_success 'Verify ascending sort' '
- git for-each-ref --format="%(refname)" --sort=refname >actual &&
- test_cmp expected actual
-'
-
-
-cat >expected <<\EOF
-refs/tags/testtag
-refs/remotes/origin/main
-refs/heads/main
-EOF
-
-test_expect_success 'Verify descending sort' '
- git for-each-ref --format="%(refname)" --sort=-refname >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'Give help even with invalid sort atoms' '
- test_expect_code 129 git for-each-ref --sort=bogus -h >actual 2>&1 &&
- grep "^usage: git for-each-ref" actual
-'
-
-cat >expected <<\EOF
-refs/tags/testtag
-refs/tags/testtag-2
-EOF
-
-test_expect_success 'exercise patterns with prefixes' '
- git tag testtag-2 &&
- test_when_finished "git tag -d testtag-2" &&
- git for-each-ref --format="%(refname)" \
- refs/tags/testtag refs/tags/testtag-2 >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<\EOF
-refs/tags/testtag
-refs/tags/testtag-2
-EOF
-
-test_expect_success 'exercise glob patterns with prefixes' '
- git tag testtag-2 &&
- test_when_finished "git tag -d testtag-2" &&
- git for-each-ref --format="%(refname)" \
- refs/tags/testtag "refs/tags/testtag-*" >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<\EOF
-refs/tags/bar
-refs/tags/baz
-refs/tags/testtag
-EOF
-
-test_expect_success 'exercise patterns with prefix exclusions' '
- for tag in foo/one foo/two foo/three bar baz
- do
- git tag "$tag" || return 1
- done &&
- test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
- git for-each-ref --format="%(refname)" \
- refs/tags/ --exclude=refs/tags/foo >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<\EOF
-refs/tags/bar
-refs/tags/baz
-refs/tags/foo/one
-refs/tags/testtag
-EOF
-
-test_expect_success 'exercise patterns with pattern exclusions' '
- for tag in foo/one foo/two foo/three bar baz
- do
- git tag "$tag" || return 1
- done &&
- test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
- git for-each-ref --format="%(refname)" \
- refs/tags/ --exclude="refs/tags/foo/t*" >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<\EOF
-'refs/heads/main'
-'refs/remotes/origin/main'
-'refs/tags/testtag'
-EOF
-
-test_expect_success 'Quoting style: shell' '
- git for-each-ref --shell --format="%(refname)" >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'Quoting style: perl' '
- git for-each-ref --perl --format="%(refname)" >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'Quoting style: python' '
- git for-each-ref --python --format="%(refname)" >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<\EOF
-"refs/heads/main"
-"refs/remotes/origin/main"
-"refs/tags/testtag"
-EOF
-
-test_expect_success 'Quoting style: tcl' '
- git for-each-ref --tcl --format="%(refname)" >actual &&
- test_cmp expected actual
-'
-
-for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
- test_expect_success "more than one quoting style: $i" "
- test_must_fail git for-each-ref $i 2>err &&
- grep '^error: more than one quoting style' err
- "
-done
-
-test_expect_success 'setup for upstream:track[short]' '
- test_commit two
-'
-
-test_atom head upstream:track '[ahead 1]'
-test_atom head upstream:trackshort '>'
-test_atom head upstream:track,nobracket 'ahead 1'
-test_atom head upstream:nobracket,track 'ahead 1'
-
-test_expect_success 'setup for push:track[short]' '
- test_commit third &&
- git update-ref refs/remotes/myfork/main main &&
- git reset main~1
-'
-
-test_atom head push:track '[behind 1]'
-test_atom head push:trackshort '<'
-
-test_expect_success 'Check that :track[short] cannot be used with other atoms' '
- test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
- test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
-'
-
-test_expect_success 'Check that :track[short] works when upstream is invalid' '
- cat >expected <<-\EOF &&
- [gone]
-
- EOF
- test_when_finished "git config branch.main.merge refs/heads/main" &&
- git config branch.main.merge refs/heads/does-not-exist &&
- git for-each-ref \
- --format="%(upstream:track)$LF%(upstream:trackshort)" \
- refs/heads >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'Check for invalid refname format' '
- test_must_fail git for-each-ref --format="%(refname:INVALID)"
-'
-
-test_expect_success 'set up color tests' '
- cat >expected.color <<-EOF &&
- $(git rev-parse --short refs/heads/main) <GREEN>main<RESET>
- $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET>
- $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET>
- $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
- $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
- $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
- EOF
- sed "s/<[^>]*>//g" <expected.color >expected.bare &&
- color_format="%(objectname:short) %(color:green)%(refname:short)"
-'
-
-test_expect_success TTY '%(color) shows color with a tty' '
- test_terminal git for-each-ref --format="$color_format" >actual.raw &&
- test_decode_color <actual.raw >actual &&
- test_cmp expected.color actual
-'
-
-test_expect_success '%(color) does not show color without tty' '
- TERM=vt100 git for-each-ref --format="$color_format" >actual &&
- test_cmp expected.bare actual
-'
-
-test_expect_success '--color can override tty check' '
- git for-each-ref --color --format="$color_format" >actual.raw &&
- test_decode_color <actual.raw >actual &&
- test_cmp expected.color actual
-'
-
-test_expect_success 'color.ui=always does not override tty check' '
- git -c color.ui=always for-each-ref --format="$color_format" >actual &&
- test_cmp expected.bare actual
-'
-
-test_expect_success 'setup for describe atom tests' '
- git init -b master describe-repo &&
- (
- cd describe-repo &&
-
- test_commit --no-tag one &&
- git tag tagone &&
-
- test_commit --no-tag two &&
- git tag -a -m "tag two" tagtwo
- )
-'
-
-test_expect_success 'describe atom vs git describe' '
- (
- cd describe-repo &&
-
- git for-each-ref --format="%(objectname)" \
- refs/tags/ >obj &&
- while read hash
- do
- if desc=$(git describe $hash)
- then
- : >expect-contains-good
- else
- : >expect-contains-bad
- fi &&
- echo "$hash $desc" || return 1
- done <obj >expect &&
- test_path_exists expect-contains-good &&
- test_path_exists expect-contains-bad &&
-
- git for-each-ref --format="%(objectname) %(describe)" \
- refs/tags/ >actual 2>err &&
- test_cmp expect actual &&
- test_must_be_empty err
- )
-'
-
-test_expect_success 'describe:tags vs describe --tags' '
- (
- cd describe-repo &&
- git describe --tags >expect &&
- git for-each-ref --format="%(describe:tags)" \
- refs/heads/master >actual &&
- test_cmp expect actual
- )
-'
-
-test_expect_success 'describe:abbrev=... vs describe --abbrev=...' '
- (
- cd describe-repo &&
-
- # Case 1: We have commits between HEAD and the most
- # recent tag reachable from it
- test_commit --no-tag file &&
- git describe --abbrev=14 >expect &&
- git for-each-ref --format="%(describe:abbrev=14)" \
- refs/heads/master >actual &&
- test_cmp expect actual &&
-
- # Make sure the hash used is at least 14 digits long
- sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart &&
- test 15 -le $(wc -c <hexpart) &&
-
- # Case 2: We have a tag at HEAD, describe directly gives
- # the name of the tag
- git tag -a -m tagged tagname &&
- git describe --abbrev=14 >expect &&
- git for-each-ref --format="%(describe:abbrev=14)" \
- refs/heads/master >actual &&
- test_cmp expect actual &&
- test tagname = $(cat actual)
- )
-'
-
-test_expect_success 'describe:match=... vs describe --match ...' '
- (
- cd describe-repo &&
- git tag -a -m "tag foo" tag-foo &&
- git describe --match "*-foo" >expect &&
- git for-each-ref --format="%(describe:match="*-foo")" \
- refs/heads/master >actual &&
- test_cmp expect actual
- )
-'
-
-test_expect_success 'describe:exclude:... vs describe --exclude ...' '
- (
- cd describe-repo &&
- git tag -a -m "tag bar" tag-bar &&
- git describe --exclude "*-bar" >expect &&
- git for-each-ref --format="%(describe:exclude="*-bar")" \
- refs/heads/master >actual &&
- test_cmp expect actual
- )
-'
-
-test_expect_success 'deref with describe atom' '
- (
- cd describe-repo &&
- cat >expect <<-\EOF &&
-
- tagname
- tagname
- tagname
-
- tagtwo
- EOF
- git for-each-ref --format="%(*describe)" >actual &&
- test_cmp expect actual
- )
-'
-
-test_expect_success 'err on bad describe atom arg' '
- (
- cd describe-repo &&
-
- # The bad arg is the only arg passed to describe atom
- cat >expect <<-\EOF &&
- fatal: unrecognized %(describe) argument: baz
- EOF
- test_must_fail git for-each-ref --format="%(describe:baz)" \
- refs/heads/master 2>actual &&
- test_cmp expect actual &&
-
- # The bad arg is in the middle of the option string
- # passed to the describe atom
- cat >expect <<-\EOF &&
- fatal: unrecognized %(describe) argument: qux=1,abbrev=14
- EOF
- test_must_fail git for-each-ref \
- --format="%(describe:tags,qux=1,abbrev=14)" \
- ref/heads/master 2>actual &&
- test_cmp expect actual
- )
-'
-
-cat >expected <<\EOF
-heads/main
-tags/main
-EOF
-
-test_expect_success 'Check ambiguous head and tag refs (strict)' '
- git config --bool core.warnambiguousrefs true &&
- git checkout -b newtag &&
- echo "Using $datestamp" > one &&
- git add one &&
- git commit -m "Branch" &&
- setdate_and_increment &&
- git tag -m "Tagging at $datestamp" main &&
- git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<\EOF
-heads/main
-main
-EOF
-
-test_expect_success 'Check ambiguous head and tag refs (loose)' '
- git config --bool core.warnambiguousrefs false &&
- git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<\EOF
-heads/ambiguous
-ambiguous
-EOF
-
-test_expect_success 'Check ambiguous head and tag refs II (loose)' '
- git checkout main &&
- git tag ambiguous testtag^0 &&
- git branch ambiguous testtag^0 &&
- git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'create tag without tagger' '
- git tag -a -m "Broken tag" taggerless &&
- git tag -f taggerless $(git cat-file tag taggerless |
- sed -e "/^tagger /d" |
- git hash-object --literally --stdin -w -t tag)
-'
-
-test_atom refs/tags/taggerless type 'commit'
-test_atom refs/tags/taggerless tag 'taggerless'
-test_atom refs/tags/taggerless tagger ''
-test_atom refs/tags/taggerless taggername ''
-test_atom refs/tags/taggerless taggeremail ''
-test_atom refs/tags/taggerless taggeremail:trim ''
-test_atom refs/tags/taggerless taggeremail:localpart ''
-test_atom refs/tags/taggerless taggerdate ''
-test_atom refs/tags/taggerless committer ''
-test_atom refs/tags/taggerless committername ''
-test_atom refs/tags/taggerless committeremail ''
-test_atom refs/tags/taggerless committeremail:trim ''
-test_atom refs/tags/taggerless committeremail:localpart ''
-test_atom refs/tags/taggerless committerdate ''
-test_atom refs/tags/taggerless subject 'Broken tag'
-
-test_expect_success 'an unusual tag with an incomplete line' '
-
- git tag -m "bogo" bogo &&
- bogo=$(git cat-file tag bogo) &&
- bogo=$(printf "%s" "$bogo" | git mktag) &&
- git tag -f bogo "$bogo" &&
- git for-each-ref --format "%(body)" refs/tags/bogo
-
-'
-
-test_expect_success 'create tag with subject and body content' '
- cat >>msg <<-\EOF &&
- the subject line
-
- first body line
- second body line
- EOF
- git tag -F msg subject-body
-'
-test_atom refs/tags/subject-body subject 'the subject line'
-test_atom refs/tags/subject-body subject:sanitize 'the-subject-line'
-test_atom refs/tags/subject-body body 'first body line
-second body line
-'
-test_atom refs/tags/subject-body contents 'the subject line
-
-first body line
-second body line
-'
-
-test_expect_success 'create tag with multiline subject' '
- cat >msg <<-\EOF &&
- first subject line
- second subject line
-
- first body line
- second body line
- EOF
- git tag -F msg multiline
-'
-test_atom refs/tags/multiline subject 'first subject line second subject line'
-test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line'
-test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
-test_atom refs/tags/multiline body 'first body line
-second body line
-'
-test_atom refs/tags/multiline contents:body 'first body line
-second body line
-'
-test_atom refs/tags/multiline contents:signature ''
-test_atom refs/tags/multiline contents 'first subject line
-second subject line
-
-first body line
-second body line
-'
-
-test_expect_success GPG 'create signed tags' '
- git tag -s -m "" signed-empty &&
- git tag -s -m "subject line" signed-short &&
- cat >msg <<-\EOF &&
- subject line
-
- body contents
- EOF
- git tag -s -F msg signed-long
-'
-
-sig='-----BEGIN PGP SIGNATURE-----
------END PGP SIGNATURE-----
-'
-
-PREREQ=GPG
-test_atom refs/tags/signed-empty subject ''
-test_atom refs/tags/signed-empty subject:sanitize ''
-test_atom refs/tags/signed-empty contents:subject ''
-test_atom refs/tags/signed-empty body "$sig"
-test_atom refs/tags/signed-empty contents:body ''
-test_atom refs/tags/signed-empty contents:signature "$sig"
-test_atom refs/tags/signed-empty contents "$sig"
-
-test_expect_success GPG 'basic atom: refs/tags/signed-empty raw' '
- git cat-file tag refs/tags/signed-empty >expected &&
- git for-each-ref --format="%(raw)" refs/tags/signed-empty >actual &&
- sanitize_pgp <expected >expected.clean &&
- echo >>expected.clean &&
- sanitize_pgp <actual >actual.clean &&
- test_cmp expected.clean actual.clean
-'
-
-test_atom refs/tags/signed-short subject 'subject line'
-test_atom refs/tags/signed-short subject:sanitize 'subject-line'
-test_atom refs/tags/signed-short contents:subject 'subject line'
-test_atom refs/tags/signed-short body "$sig"
-test_atom refs/tags/signed-short contents:body ''
-test_atom refs/tags/signed-short contents:signature "$sig"
-test_atom refs/tags/signed-short contents "subject line
-$sig"
-
-test_expect_success GPG 'basic atom: refs/tags/signed-short raw' '
- git cat-file tag refs/tags/signed-short >expected &&
- git for-each-ref --format="%(raw)" refs/tags/signed-short >actual &&
- sanitize_pgp <expected >expected.clean &&
- echo >>expected.clean &&
- sanitize_pgp <actual >actual.clean &&
- test_cmp expected.clean actual.clean
-'
-
-test_atom refs/tags/signed-long subject 'subject line'
-test_atom refs/tags/signed-long subject:sanitize 'subject-line'
-test_atom refs/tags/signed-long contents:subject 'subject line'
-test_atom refs/tags/signed-long body "body contents
-$sig"
-test_atom refs/tags/signed-long contents:body 'body contents
-'
-test_atom refs/tags/signed-long contents:signature "$sig"
-test_atom refs/tags/signed-long contents "subject line
-
-body contents
-$sig"
-
-test_expect_success GPG 'basic atom: refs/tags/signed-long raw' '
- git cat-file tag refs/tags/signed-long >expected &&
- git for-each-ref --format="%(raw)" refs/tags/signed-long >actual &&
- sanitize_pgp <expected >expected.clean &&
- echo >>expected.clean &&
- sanitize_pgp <actual >actual.clean &&
- test_cmp expected.clean actual.clean
-'
-
-test_expect_success 'set up refs pointing to tree and blob' '
- git update-ref refs/mytrees/first refs/heads/main^{tree} &&
- git update-ref refs/myblobs/first refs/heads/main:one
-'
-
-test_atom refs/mytrees/first subject ""
-test_atom refs/mytrees/first contents:subject ""
-test_atom refs/mytrees/first body ""
-test_atom refs/mytrees/first contents:body ""
-test_atom refs/mytrees/first contents:signature ""
-test_atom refs/mytrees/first contents ""
-
-test_expect_success 'basic atom: refs/mytrees/first raw' '
- git cat-file tree refs/mytrees/first >expected &&
- echo >>expected &&
- git for-each-ref --format="%(raw)" refs/mytrees/first >actual &&
- test_cmp expected actual &&
- git cat-file -s refs/mytrees/first >expected &&
- git for-each-ref --format="%(raw:size)" refs/mytrees/first >actual &&
- test_cmp expected actual
-'
-
-test_atom refs/myblobs/first subject ""
-test_atom refs/myblobs/first contents:subject ""
-test_atom refs/myblobs/first body ""
-test_atom refs/myblobs/first contents:body ""
-test_atom refs/myblobs/first contents:signature ""
-test_atom refs/myblobs/first contents ""
-
-test_expect_success 'basic atom: refs/myblobs/first raw' '
- git cat-file blob refs/myblobs/first >expected &&
- echo >>expected &&
- git for-each-ref --format="%(raw)" refs/myblobs/first >actual &&
- test_cmp expected actual &&
- git cat-file -s refs/myblobs/first >expected &&
- git for-each-ref --format="%(raw:size)" refs/myblobs/first >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'set up refs pointing to binary blob' '
- printf "a\0b\0c" >blob1 &&
- printf "a\0c\0b" >blob2 &&
- printf "\0a\0b\0c" >blob3 &&
- printf "abc" >blob4 &&
- printf "\0 \0 \0 " >blob5 &&
- printf "\0 \0a\0 " >blob6 &&
- printf " " >blob7 &&
- >blob8 &&
- obj=$(git hash-object -w blob1) &&
- git update-ref refs/myblobs/blob1 "$obj" &&
- obj=$(git hash-object -w blob2) &&
- git update-ref refs/myblobs/blob2 "$obj" &&
- obj=$(git hash-object -w blob3) &&
- git update-ref refs/myblobs/blob3 "$obj" &&
- obj=$(git hash-object -w blob4) &&
- git update-ref refs/myblobs/blob4 "$obj" &&
- obj=$(git hash-object -w blob5) &&
- git update-ref refs/myblobs/blob5 "$obj" &&
- obj=$(git hash-object -w blob6) &&
- git update-ref refs/myblobs/blob6 "$obj" &&
- obj=$(git hash-object -w blob7) &&
- git update-ref refs/myblobs/blob7 "$obj" &&
- obj=$(git hash-object -w blob8) &&
- git update-ref refs/myblobs/blob8 "$obj"
-'
-
-test_expect_success 'Verify sorts with raw' '
- cat >expected <<-EOF &&
- refs/myblobs/blob8
- refs/myblobs/blob5
- refs/myblobs/blob6
- refs/myblobs/blob3
- refs/myblobs/blob7
- refs/mytrees/first
- refs/myblobs/first
- refs/myblobs/blob1
- refs/myblobs/blob2
- refs/myblobs/blob4
- refs/heads/main
- EOF
- git for-each-ref --format="%(refname)" --sort=raw \
- refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'Verify sorts with raw:size' '
- cat >expected <<-EOF &&
- refs/myblobs/blob8
- refs/myblobs/blob7
- refs/myblobs/blob4
- refs/myblobs/blob1
- refs/myblobs/blob2
- refs/myblobs/blob3
- refs/myblobs/blob5
- refs/myblobs/blob6
- refs/myblobs/first
- refs/mytrees/first
- refs/heads/main
- EOF
- git for-each-ref --format="%(refname)" --sort=raw:size \
- refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
- test_cmp expected actual
+test_expect_success "for-each-ref does not crash with -h" '
+ test_expect_code 129 git for-each-ref -h >usage &&
+ test_grep "[Uu]sage: git for-each-ref " usage &&
+ test_expect_code 129 nongit git for-each-ref -h >usage &&
+ test_grep "[Uu]sage: git for-each-ref " usage
'
-test_expect_success 'validate raw atom with %(if:equals)' '
- cat >expected <<-EOF &&
- not equals
- not equals
- not equals
- not equals
- not equals
- not equals
- refs/myblobs/blob4
- not equals
- not equals
- not equals
- not equals
- not equals
- EOF
- git for-each-ref --format="%(if:equals=abc)%(raw)%(then)%(refname)%(else)not equals%(end)" \
- refs/myblobs/ refs/heads/ >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'validate raw atom with %(if:notequals)' '
- cat >expected <<-EOF &&
- refs/heads/ambiguous
- refs/heads/main
- refs/heads/newtag
- refs/myblobs/blob1
- refs/myblobs/blob2
- refs/myblobs/blob3
- equals
- refs/myblobs/blob5
- refs/myblobs/blob6
- refs/myblobs/blob7
- refs/myblobs/blob8
- refs/myblobs/first
- EOF
- git for-each-ref --format="%(if:notequals=abc)%(raw)%(then)%(refname)%(else)equals%(end)" \
- refs/myblobs/ refs/heads/ >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'empty raw refs with %(if)' '
- cat >expected <<-EOF &&
- refs/myblobs/blob1 not empty
- refs/myblobs/blob2 not empty
- refs/myblobs/blob3 not empty
- refs/myblobs/blob4 not empty
- refs/myblobs/blob5 not empty
- refs/myblobs/blob6 not empty
- refs/myblobs/blob7 empty
- refs/myblobs/blob8 empty
- refs/myblobs/first not empty
- EOF
- git for-each-ref --format="%(refname) %(if)%(raw)%(then)not empty%(else)empty%(end)" \
- refs/myblobs/ >actual &&
- test_cmp expected actual
-'
-
-test_expect_success '%(raw) with --python must fail' '
- test_must_fail git for-each-ref --format="%(raw)" --python
-'
-
-test_expect_success '%(raw) with --tcl must fail' '
- test_must_fail git for-each-ref --format="%(raw)" --tcl
-'
-
-test_expect_success '%(raw) with --perl' '
- git for-each-ref --format="\$name= %(raw);
-print \"\$name\"" refs/myblobs/blob1 --perl | perl >actual &&
- cmp blob1 actual &&
- git for-each-ref --format="\$name= %(raw);
-print \"\$name\"" refs/myblobs/blob3 --perl | perl >actual &&
- cmp blob3 actual &&
- git for-each-ref --format="\$name= %(raw);
-print \"\$name\"" refs/myblobs/blob8 --perl | perl >actual &&
- cmp blob8 actual &&
- git for-each-ref --format="\$name= %(raw);
-print \"\$name\"" refs/myblobs/first --perl | perl >actual &&
- cmp one actual &&
- git cat-file tree refs/mytrees/first > expected &&
- git for-each-ref --format="\$name= %(raw);
-print \"\$name\"" refs/mytrees/first --perl | perl >actual &&
- cmp expected actual
-'
-
-test_expect_success '%(raw) with --shell must fail' '
- test_must_fail git for-each-ref --format="%(raw)" --shell
-'
-
-test_expect_success '%(raw) with --shell and --sort=raw must fail' '
- test_must_fail git for-each-ref --format="%(raw)" --sort=raw --shell
-'
-
-test_expect_success '%(raw:size) with --shell' '
- git for-each-ref --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect &&
- git for-each-ref --format="%(raw:size)" --shell >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'for-each-ref --format compare with cat-file --batch' '
- git rev-parse refs/mytrees/first | git cat-file --batch >expected &&
- git for-each-ref --format="%(objectname) %(objecttype) %(objectsize)
-%(raw)" refs/mytrees/first >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'verify sorts with contents:size' '
- cat >expect <<-\EOF &&
- refs/heads/main
- refs/heads/newtag
- refs/heads/ambiguous
- EOF
- git for-each-ref --format="%(refname)" \
- --sort=contents:size refs/heads/ >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'set up multiple-sort tags' '
- for when in 100000 200000
- do
- for email in user1 user2
- do
- for ref in ref1 ref2
- do
- GIT_COMMITTER_DATE="@$when +0000" \
- GIT_COMMITTER_EMAIL="$email@example.com" \
- git tag -m "tag $ref-$when-$email" \
- multi-$ref-$when-$email || return 1
- done
- done
- done
-'
-
-test_expect_success 'Verify sort with multiple keys' '
- cat >expected <<-\EOF &&
- 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
- 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
- 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
- 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
- 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
- 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
- 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
- 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
- EOF
- git for-each-ref \
- --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
- --sort=-refname \
- --sort=taggeremail \
- --sort=taggerdate \
- "refs/tags/multi-*" >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'equivalent sorts fall back on refname' '
- cat >expected <<-\EOF &&
- 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
- 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
- 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
- 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
- 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
- 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
- 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
- 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
- EOF
- git for-each-ref \
- --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
- --sort=taggerdate \
- "refs/tags/multi-*" >actual &&
- test_cmp expected actual
-'
-
-test_expect_success '--no-sort cancels the previous sort keys' '
- cat >expected <<-\EOF &&
- 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
- 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
- 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
- 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
- 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
- 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
- 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
- 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
- EOF
- git for-each-ref \
- --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
- --sort=-refname \
- --sort=taggeremail \
- --no-sort \
- --sort=taggerdate \
- "refs/tags/multi-*" >actual &&
- test_cmp expected actual
-'
-
-test_expect_success '--no-sort without subsequent --sort prints expected refs' '
- cat >expected <<-\EOF &&
- refs/tags/multi-ref1-100000-user1
- refs/tags/multi-ref1-100000-user2
- refs/tags/multi-ref1-200000-user1
- refs/tags/multi-ref1-200000-user2
- refs/tags/multi-ref2-100000-user1
- refs/tags/multi-ref2-100000-user2
- refs/tags/multi-ref2-200000-user1
- refs/tags/multi-ref2-200000-user2
- EOF
-
- # Sort the results with `sort` for a consistent comparison against
- # expected
- git for-each-ref \
- --format="%(refname)" \
- --no-sort \
- "refs/tags/multi-*" | sort >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'set up custom date sorting' '
- # Dates:
- # - Wed Feb 07 2024 21:34:20 +0000
- # - Tue Dec 14 1999 00:05:22 +0000
- # - Fri Jun 04 2021 11:26:51 +0000
- # - Mon Jan 22 2007 16:44:01 GMT+0000
- i=1 &&
- for when in 1707341660 945129922 1622806011 1169484241
- do
- GIT_COMMITTER_DATE="@$when +0000" \
- GIT_COMMITTER_EMAIL="user@example.com" \
- git tag -m "tag $when" custom-dates-$i &&
- i=$(($i+1)) || return 1
- done
-'
-
-test_expect_success 'sort by date defaults to full timestamp' '
- cat >expected <<-\EOF &&
- 945129922 refs/tags/custom-dates-2
- 1169484241 refs/tags/custom-dates-4
- 1622806011 refs/tags/custom-dates-3
- 1707341660 refs/tags/custom-dates-1
- EOF
-
- git for-each-ref \
- --format="%(creatordate:unix) %(refname)" \
- --sort=creatordate \
- "refs/tags/custom-dates-*" >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'sort by custom date format' '
- cat >expected <<-\EOF &&
- 00:05:22 refs/tags/custom-dates-2
- 11:26:51 refs/tags/custom-dates-3
- 16:44:01 refs/tags/custom-dates-4
- 21:34:20 refs/tags/custom-dates-1
- EOF
-
- git for-each-ref \
- --format="%(creatordate:format:%H:%M:%S) %(refname)" \
- --sort="creatordate:format:%H:%M:%S" \
- "refs/tags/custom-dates-*" >actual &&
- test_cmp expected actual
-'
-
-test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
- test_when_finished "git checkout main" &&
- git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
- sed -e "s/^\* / /" actual >expect &&
- git checkout --orphan orphaned-branch &&
- git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
- test_cmp expect actual
-'
-
-cat >trailers <<EOF
-Reviewed-by: A U Thor <author@example.com>
-Signed-off-by: A U Thor <author@example.com>
-[ v2 updated patch description ]
-Acked-by: A U Thor
- <author@example.com>
-EOF
-
-unfold () {
- perl -0pe 's/\n\s+/ /g'
-}
-
-test_expect_success 'set up trailers for next test' '
- echo "Some contents" > two &&
- git add two &&
- git commit -F - <<-EOF
- trailers: this commit message has trailers
-
- Some message contents
-
- $(cat trailers)
- EOF
-'
-
-test_trailer_option () {
- title=$1 option=$2
- cat >expect
- test_expect_success "$title" '
- git for-each-ref --format="%($option)" refs/heads/main >actual &&
- test_cmp expect actual &&
- git for-each-ref --format="%(contents:$option)" refs/heads/main >actual &&
- test_cmp expect actual
- '
-}
-
-test_trailer_option '%(trailers:unfold) unfolds trailers' \
- 'trailers:unfold' <<-EOF
- $(unfold <trailers)
-
- EOF
-
-test_trailer_option '%(trailers:only) shows only "key: value" trailers' \
- 'trailers:only' <<-EOF
- $(grep -v patch.description <trailers)
-
- EOF
-
-test_trailer_option '%(trailers:only=no,only=true) shows only "key: value" trailers' \
- 'trailers:only=no,only=true' <<-EOF
- $(grep -v patch.description <trailers)
-
- EOF
-
-test_trailer_option '%(trailers:only=yes) shows only "key: value" trailers' \
- 'trailers:only=yes' <<-EOF
- $(grep -v patch.description <trailers)
-
- EOF
-
-test_trailer_option '%(trailers:only=no) shows all trailers' \
- 'trailers:only=no' <<-EOF
- $(cat trailers)
-
- EOF
-
-test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \
- 'trailers:only,unfold' <<-EOF
- $(grep -v patch.description <trailers | unfold)
-
- EOF
-
-test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \
- 'trailers:unfold,only' <<-EOF
- $(grep -v patch.description <trailers | unfold)
-
- EOF
-
-test_trailer_option '%(trailers:key=foo) shows that trailer' \
- 'trailers:key=Signed-off-by' <<-EOF
- Signed-off-by: A U Thor <author@example.com>
-
- EOF
-
-test_trailer_option '%(trailers:key=foo) is case insensitive' \
- 'trailers:key=SiGned-oFf-bY' <<-EOF
- Signed-off-by: A U Thor <author@example.com>
-
- EOF
-
-test_trailer_option '%(trailers:key=foo:) trailing colon also works' \
- 'trailers:key=Signed-off-by:' <<-EOF
- Signed-off-by: A U Thor <author@example.com>
-
- EOF
-
-test_trailer_option '%(trailers:key=foo) multiple keys' \
- 'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF
- Reviewed-by: A U Thor <author@example.com>
- Signed-off-by: A U Thor <author@example.com>
-
- EOF
-
-test_trailer_option '%(trailers:key=nonexistent) becomes empty' \
- 'trailers:key=Shined-off-by:' <<-EOF
-
- EOF
-
-test_trailer_option '%(trailers:key=foo) handles multiple lines even if folded' \
- 'trailers:key=Acked-by' <<-EOF
- $(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by)
-
- EOF
-
-test_trailer_option '%(trailers:key=foo,unfold) properly unfolds' \
- 'trailers:key=Signed-Off-by,unfold' <<-EOF
- $(unfold <trailers | grep Signed-off-by)
-
- EOF
-
-test_trailer_option '%(trailers:key=foo,only=no) also includes nontrailer lines' \
- 'trailers:key=Signed-off-by,only=no' <<-EOF
- Signed-off-by: A U Thor <author@example.com>
- $(grep patch.description <trailers)
-
- EOF
-
-test_trailer_option '%(trailers:key=foo,valueonly) shows only value' \
- 'trailers:key=Signed-off-by,valueonly' <<-EOF
- A U Thor <author@example.com>
-
- EOF
-
-test_trailer_option '%(trailers:separator) changes separator' \
- 'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
- Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com>
- EOF
-
-test_trailer_option '%(trailers:key_value_separator) changes key-value separator' \
- 'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
- Reviewed-by,A U Thor <author@example.com>
- Signed-off-by,A U Thor <author@example.com>
-
- EOF
-
-test_trailer_option '%(trailers:separator,key_value_separator) changes both separators' \
- 'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
- Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com>
- EOF
-
-test_expect_success 'multiple %(trailers) use their own options' '
- git tag -F - tag-with-trailers <<-\EOF &&
- body
-
- one: foo
- one: bar
- two: baz
- two: qux
- EOF
- t1="%(trailers:key=one,key_value_separator=W,separator=X)" &&
- t2="%(trailers:key=two,key_value_separator=Y,separator=Z)" &&
- git for-each-ref --format="$t1%0a$t2" refs/tags/tag-with-trailers >actual &&
- cat >expect <<-\EOF &&
- oneWfooXoneWbar
- twoYbazZtwoYqux
- EOF
- test_cmp expect actual
-'
-
-test_failing_trailer_option () {
- title=$1 option=$2
- cat >expect
- test_expect_success "$title" '
- # error message cannot be checked under i18n
- test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual &&
- test_cmp expect actual &&
- test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual &&
- test_cmp expect actual
- '
-}
-
-test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \
- 'trailers:unsupported' <<-\EOF
- fatal: unknown %(trailers) argument: unsupported
- EOF
-
-test_failing_trailer_option '%(trailers:key) without value is error' \
- 'trailers:key' <<-\EOF
- fatal: expected %(trailers:key=<value>)
- EOF
-
-test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
- cat >expect <<-EOF &&
- fatal: unrecognized %(contents) argument: trailersonly
- EOF
- test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'basic atom: head contents:trailers' '
- git for-each-ref --format="%(contents:trailers)" refs/heads/main >actual &&
- sanitize_pgp <actual >actual.clean &&
- # git for-each-ref ends with a blank line
- cat >expect <<-EOF &&
- $(cat trailers)
-
- EOF
- test_cmp expect actual.clean
-'
-
-test_expect_success 'basic atom: rest must fail' '
- test_must_fail git for-each-ref --format="%(rest)" refs/heads/main
-'
-
-test_expect_success 'HEAD atom does not take arguments' '
- test_must_fail git for-each-ref --format="%(HEAD:foo)" 2>err &&
- echo "fatal: %(HEAD) does not take arguments" >expect &&
- test_cmp expect err
-'
-
-test_expect_success 'subject atom rejects unknown arguments' '
- test_must_fail git for-each-ref --format="%(subject:foo)" 2>err &&
- echo "fatal: unrecognized %(subject) argument: foo" >expect &&
- test_cmp expect err
-'
-
-test_expect_success 'refname atom rejects unknown arguments' '
- test_must_fail git for-each-ref --format="%(refname:foo)" 2>err &&
- echo "fatal: unrecognized %(refname) argument: foo" >expect &&
- test_cmp expect err
-'
-
-test_expect_success 'trailer parsing not fooled by --- line' '
- git commit --allow-empty -F - <<-\EOF &&
- this is the subject
-
- This is the body. The message has a "---" line which would confuse a
- message+patch parser. But here we know we have only a commit message,
- so we get it right.
-
- trailer: wrong
- ---
- This is more body.
-
- trailer: right
- EOF
-
- {
- echo "trailer: right" &&
- echo
- } >expect &&
- git for-each-ref --format="%(trailers)" refs/heads/main >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'Add symbolic ref for the following tests' '
- git symbolic-ref refs/heads/sym refs/heads/main
-'
-
-cat >expected <<EOF
-refs/heads/main
-EOF
-
-test_expect_success 'Verify usage of %(symref) atom' '
- git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<EOF
-heads/main
-EOF
-
-test_expect_success 'Verify usage of %(symref:short) atom' '
- git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
- test_cmp expected actual
-'
-
-cat >expected <<EOF
-main
-heads/main
-EOF
-
-test_expect_success 'Verify usage of %(symref:lstrip) atom' '
- git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
- git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
- test_cmp expected actual &&
-
- git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
- git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
- test_cmp expected actual
-'
-
-cat >expected <<EOF
-refs
-refs/heads
-EOF
-
-test_expect_success 'Verify usage of %(symref:rstrip) atom' '
- git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
- git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
- test_cmp expected actual
-'
-
-test_expect_success ':remotename and :remoteref' '
- git init remote-tests &&
- (
- cd remote-tests &&
- test_commit initial &&
- git branch -M main &&
- git remote add from fifth.coffee:blub &&
- git config branch.main.remote from &&
- git config branch.main.merge refs/heads/stable &&
- git remote add to southridge.audio:repo &&
- git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
- git config branch.main.pushRemote to &&
- for pair in "%(upstream)=refs/remotes/from/stable" \
- "%(upstream:remotename)=from" \
- "%(upstream:remoteref)=refs/heads/stable" \
- "%(push)=refs/remotes/to/pushed/main" \
- "%(push:remotename)=to" \
- "%(push:remoteref)=refs/heads/pushed/main"
- do
- echo "${pair#*=}" >expect &&
- git for-each-ref --format="${pair%=*}" \
- refs/heads/main >actual &&
- test_cmp expect actual || exit 1
- done &&
- git branch push-simple &&
- git config branch.push-simple.pushRemote from &&
- actual="$(git for-each-ref \
- --format="%(push:remotename),%(push:remoteref)" \
- refs/heads/push-simple)" &&
- test from, = "$actual"
- )
-'
-
-test_expect_success 'for-each-ref --ignore-case ignores case' '
- git for-each-ref --format="%(refname)" refs/heads/MAIN >actual &&
- test_must_be_empty actual &&
-
- echo refs/heads/main >expect &&
- git for-each-ref --format="%(refname)" --ignore-case \
- refs/heads/MAIN >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'for-each-ref --omit-empty works' '
- git for-each-ref --format="%(refname)" >actual &&
- test_line_count -gt 1 actual &&
- git for-each-ref --format="%(if:equals=refs/heads/main)%(refname)%(then)%(refname)%(end)" --omit-empty >actual &&
- echo refs/heads/main >expect &&
- test_cmp expect actual
-'
-
-test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
- # name refs numerically to avoid case-insensitive filesystem conflicts
- nr=0 &&
- for email in a A b B
- do
- for subject in a A b B
- do
- GIT_COMMITTER_EMAIL="$email@example.com" \
- git tag -m "tag $subject" icase-$(printf %02d $nr) &&
- nr=$((nr+1))||
- return 1
- done
- done &&
- git for-each-ref --ignore-case \
- --format="%(taggeremail) %(subject) %(refname)" \
- --sort=refname \
- --sort=subject \
- --sort=taggeremail \
- refs/tags/icase-* >actual &&
- cat >expect <<-\EOF &&
- <a@example.com> tag a refs/tags/icase-00
- <a@example.com> tag A refs/tags/icase-01
- <A@example.com> tag a refs/tags/icase-04
- <A@example.com> tag A refs/tags/icase-05
- <a@example.com> tag b refs/tags/icase-02
- <a@example.com> tag B refs/tags/icase-03
- <A@example.com> tag b refs/tags/icase-06
- <A@example.com> tag B refs/tags/icase-07
- <b@example.com> tag a refs/tags/icase-08
- <b@example.com> tag A refs/tags/icase-09
- <B@example.com> tag a refs/tags/icase-12
- <B@example.com> tag A refs/tags/icase-13
- <b@example.com> tag b refs/tags/icase-10
- <b@example.com> tag B refs/tags/icase-11
- <B@example.com> tag b refs/tags/icase-14
- <B@example.com> tag B refs/tags/icase-15
- EOF
- test_cmp expect actual
-'
-
-test_expect_success 'for-each-ref reports broken tags' '
- git tag -m "good tag" broken-tag-good HEAD &&
- git cat-file tag broken-tag-good >good &&
- sed s/commit/blob/ <good >bad &&
- bad=$(git hash-object -w -t tag bad) &&
- git update-ref refs/tags/broken-tag-bad $bad &&
- test_must_fail git for-each-ref --format="%(*objectname)" \
- refs/tags/broken-tag-*
-'
-
-test_expect_success 'set up tag with signature and no blank lines' '
- git tag -F - fake-sig-no-blanks <<-\EOF
- this is the subject
- -----BEGIN PGP SIGNATURE-----
- not a real signature, but we just care about the
- subject/body parsing. It is important here that
- there are no blank lines in the signature.
- -----END PGP SIGNATURE-----
- EOF
-'
-
-test_atom refs/tags/fake-sig-no-blanks contents:subject 'this is the subject'
-test_atom refs/tags/fake-sig-no-blanks contents:body ''
-test_atom refs/tags/fake-sig-no-blanks contents:signature "$sig"
-
-test_expect_success 'set up tag with CRLF signature' '
- append_cr <<-\EOF |
- this is the subject
- -----BEGIN PGP SIGNATURE-----
-
- not a real signature, but we just care about
- the subject/body parsing. It is important here
- that there is a blank line separating this
- from the signature header.
- -----END PGP SIGNATURE-----
- EOF
- git tag -F - --cleanup=verbatim fake-sig-crlf
-'
-
-test_atom refs/tags/fake-sig-crlf contents:subject 'this is the subject'
-test_atom refs/tags/fake-sig-crlf contents:body ''
-
-# CRLF is retained in the signature, so we have to pass our expected value
-# through append_cr. But test_atom requires a shell string, which means command
-# substitution, and the shell will strip trailing newlines from the output of
-# the substitution. Hack around it by adding and then removing a dummy line.
-sig_crlf="$(printf "%s" "$sig" | append_cr; echo dummy)"
-sig_crlf=${sig_crlf%dummy}
-test_atom refs/tags/fake-sig-crlf contents:signature "$sig_crlf"
-
-test_expect_success 'set up tag with signature and trailers' '
- git tag -F - fake-sig-trailer <<-\EOF
- this is the subject
-
- this is the body
-
- My-Trailer: foo
- -----BEGIN PGP SIGNATURE-----
-
- not a real signature, but we just care about the
- subject/body/trailer parsing.
- -----END PGP SIGNATURE-----
- EOF
-'
-
-# use "separator=" here to suppress the terminating newline
-test_atom refs/tags/fake-sig-trailer trailers:separator= 'My-Trailer: foo'
-
-test_expect_success 'git for-each-ref --stdin: empty' '
- >in &&
- git for-each-ref --format="%(refname)" --stdin <in >actual &&
- git for-each-ref --format="%(refname)" >expect &&
- test_cmp expect actual
-'
-
-test_expect_success 'git for-each-ref --stdin: fails if extra args' '
- >in &&
- test_must_fail git for-each-ref --format="%(refname)" \
- --stdin refs/heads/extra <in 2>err &&
- grep "unknown arguments supplied with --stdin" err
-'
-
-test_expect_success 'git for-each-ref --stdin: matches' '
- cat >in <<-EOF &&
- refs/tags/multi*
- refs/heads/amb*
- EOF
-
- cat >expect <<-EOF &&
- refs/heads/ambiguous
- refs/tags/multi-ref1-100000-user1
- refs/tags/multi-ref1-100000-user2
- refs/tags/multi-ref1-200000-user1
- refs/tags/multi-ref1-200000-user2
- refs/tags/multi-ref2-100000-user1
- refs/tags/multi-ref2-100000-user2
- refs/tags/multi-ref2-200000-user1
- refs/tags/multi-ref2-200000-user2
- refs/tags/multiline
- EOF
-
- git for-each-ref --format="%(refname)" --stdin <in >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'git for-each-ref with non-existing refs' '
- cat >in <<-EOF &&
- refs/heads/this-ref-does-not-exist
- refs/tags/bogus
- EOF
-
- git for-each-ref --format="%(refname)" --stdin <in >actual &&
- test_must_be_empty actual &&
-
- xargs git for-each-ref --format="%(refname)" <in >actual &&
- test_must_be_empty actual
-'
-
-test_expect_success 'git for-each-ref with nested tags' '
- git tag -am "Normal tag" nested/base HEAD &&
- git tag -am "Nested tag" nested/nest1 refs/tags/nested/base &&
- git tag -am "Double nested tag" nested/nest2 refs/tags/nested/nest1 &&
-
- head_oid="$(git rev-parse HEAD)" &&
- base_tag_oid="$(git rev-parse refs/tags/nested/base)" &&
- nest1_tag_oid="$(git rev-parse refs/tags/nested/nest1)" &&
- nest2_tag_oid="$(git rev-parse refs/tags/nested/nest2)" &&
-
- cat >expect <<-EOF &&
- refs/tags/nested/base $base_tag_oid tag $head_oid commit
- refs/tags/nested/nest1 $nest1_tag_oid tag $head_oid commit
- refs/tags/nested/nest2 $nest2_tag_oid tag $head_oid commit
- EOF
-
- git for-each-ref \
- --format="%(refname) %(objectname) %(objecttype) %(*objectname) %(*objecttype)" \
- refs/tags/nested/ >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'is-base atom with non-commits' '
- git for-each-ref --format="%(is-base:HEAD) %(refname)" >out 2>err &&
- grep "(HEAD) refs/heads/main" out &&
-
- test_line_count = 2 err &&
- grep "error: object .* is a commit, not a blob" err &&
- grep "error: bad tag pointer to" err
-'
-
-GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
-TRUSTLEVEL_FORMAT="%(signature:trustlevel)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
-
-test_expect_success GPG 'setup for signature atom using gpg' '
- git checkout -b signed &&
-
- test_when_finished "test_unconfig commit.gpgSign" &&
-
- echo "1" >file &&
- git add file &&
- test_tick &&
- git commit -S -m "file: 1" &&
- git tag first-signed &&
-
- echo "2" >file &&
- test_tick &&
- git commit -a -m "file: 2" &&
- git tag second-unsigned &&
-
- git config commit.gpgSign 1 &&
- echo "3" >file &&
- test_tick &&
- git commit -a --no-gpg-sign -m "file: 3" &&
- git tag third-unsigned &&
-
- test_tick &&
- git rebase -f HEAD^^ && git tag second-signed HEAD^ &&
- git tag third-signed &&
-
- echo "4" >file &&
- test_tick &&
- git commit -a -SB7227189 -m "file: 4" &&
- git tag fourth-signed &&
-
- echo "5" >file &&
- test_tick &&
- git commit -a --no-gpg-sign -m "file: 5" &&
- git tag fifth-unsigned &&
-
- echo "6" >file &&
- test_tick &&
- git commit -a --no-gpg-sign -m "file: 6" &&
-
- test_tick &&
- git rebase -f HEAD^^ &&
- git tag fifth-signed HEAD^ &&
- git tag sixth-signed &&
-
- echo "7" >file &&
- test_tick &&
- git commit -a --no-gpg-sign -m "file: 7" &&
- git tag seventh-unsigned
-'
-
-test_expect_success GPGSSH 'setup for signature atom using ssh' '
- test_when_finished "test_unconfig gpg.format user.signingkey" &&
-
- test_config gpg.format ssh &&
- test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
- echo "8" >file &&
- test_tick &&
- git add file &&
- git commit -S -m "file: 8" &&
- git tag eighth-signed-ssh
-'
-
-test_expect_success GPG2 'bare signature atom' '
- git verify-commit first-signed 2>expect &&
- echo >>expect &&
- git for-each-ref refs/tags/first-signed \
- --format="%(signature)" >actual &&
- test_cmp expect actual
-'
-
-test_expect_success GPG 'show good signature with custom format' '
- git verify-commit first-signed &&
- cat >expect <<-\EOF &&
- G
- 13B6F51ECDDE430D
- C O Mitter <committer@example.com>
- 73D758744BE721698EC54E8713B6F51ECDDE430D
- 73D758744BE721698EC54E8713B6F51ECDDE430D
- EOF
- git for-each-ref refs/tags/first-signed \
- --format="$GRADE_FORMAT" >actual &&
- test_cmp expect actual
-'
-test_expect_success GPGSSH 'show good signature with custom format with ssh' '
- test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
- FINGERPRINT=$(ssh-keygen -lf "${GPGSSH_KEY_PRIMARY}" | awk "{print \$2;}") &&
- cat >expect.tmpl <<-\EOF &&
- G
- FINGERPRINT
- principal with number 1
- FINGERPRINT
-
- EOF
- sed "s|FINGERPRINT|$FINGERPRINT|g" expect.tmpl >expect &&
- git for-each-ref refs/tags/eighth-signed-ssh \
- --format="$GRADE_FORMAT" >actual &&
- test_cmp expect actual
-'
-
-test_expect_success GPG 'signature atom with grade option and bad signature' '
- git cat-file commit third-signed >raw &&
- sed -e "s/^file: 3/file: 3 forged/" raw >forged1 &&
- FORGED1=$(git hash-object -w -t commit forged1) &&
- git update-ref refs/tags/third-signed "$FORGED1" &&
- test_must_fail git verify-commit "$FORGED1" &&
-
- cat >expect <<-\EOF &&
- B
- 13B6F51ECDDE430D
- C O Mitter <committer@example.com>
-
-
- EOF
- git for-each-ref refs/tags/third-signed \
- --format="$GRADE_FORMAT" >actual &&
- test_cmp expect actual
-'
-
-test_expect_success GPG 'show untrusted signature with custom format' '
- cat >expect <<-\EOF &&
- U
- 65A0EEA02E30CAD7
- Eris Discordia <discord@example.net>
- F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
- D4BE22311AD3131E5EDA29A461092E85B7227189
- EOF
- git for-each-ref refs/tags/fourth-signed \
- --format="$GRADE_FORMAT" >actual &&
- test_cmp expect actual
-'
-
-test_expect_success GPG 'show untrusted signature with undefined trust level' '
- cat >expect <<-\EOF &&
- undefined
- 65A0EEA02E30CAD7
- Eris Discordia <discord@example.net>
- F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
- D4BE22311AD3131E5EDA29A461092E85B7227189
- EOF
- git for-each-ref refs/tags/fourth-signed \
- --format="$TRUSTLEVEL_FORMAT" >actual &&
- test_cmp expect actual
-'
-
-test_expect_success GPG 'show untrusted signature with ultimate trust level' '
- cat >expect <<-\EOF &&
- ultimate
- 13B6F51ECDDE430D
- C O Mitter <committer@example.com>
- 73D758744BE721698EC54E8713B6F51ECDDE430D
- 73D758744BE721698EC54E8713B6F51ECDDE430D
- EOF
- git for-each-ref refs/tags/sixth-signed \
- --format="$TRUSTLEVEL_FORMAT" >actual &&
- test_cmp expect actual
-'
-
-test_expect_success GPG 'show unknown signature with custom format' '
- cat >expect <<-\EOF &&
- E
- 13B6F51ECDDE430D
-
-
-
- EOF
- GNUPGHOME="$GNUPGHOME_NOT_USED" git for-each-ref \
- refs/tags/sixth-signed --format="$GRADE_FORMAT" >actual &&
- test_cmp expect actual
-'
-
-test_expect_success GPG 'show lack of signature with custom format' '
- cat >expect <<-\EOF &&
- N
-
-
-
-
- EOF
- git for-each-ref refs/tags/seventh-unsigned \
- --format="$GRADE_FORMAT" >actual &&
- test_cmp expect actual
-'
+. "$TEST_DIRECTORY"/for-each-ref-tests.sh
test_done
diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh
index bb02b86c16..9b80ea1e3b 100755
--- a/t/t6302-for-each-ref-filter.sh
+++ b/t/t6302-for-each-ref-filter.sh
@@ -541,4 +541,217 @@ test_expect_success 'validate worktree atom' '
test_cmp expect actual
'
+test_expect_success 'start after with empty value' '
+ cat >expect <<-\EOF &&
+ refs/heads/main
+ refs/heads/main_worktree
+ refs/heads/side
+ refs/odd/spot
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after="" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after a specific reference' '
+ cat >expect <<-\EOF &&
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/odd/spot >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after a specific reference with partial match' '
+ cat >expect <<-\EOF &&
+ refs/odd/spot
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/odd/sp >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after, just behind a specific reference' '
+ cat >expect <<-\EOF &&
+ refs/odd/spot
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/odd/parrot >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after with specific directory match' '
+ cat >expect <<-\EOF &&
+ refs/odd/spot
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/odd >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after with specific directory and trailing slash' '
+ cat >expect <<-\EOF &&
+ refs/odd/spot
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/odd/ >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after, just behind a specific directory' '
+ cat >expect <<-\EOF &&
+ refs/odd/spot
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/lost >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after, overflow specific reference length' '
+ cat >expect <<-\EOF &&
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/odd/spotnew >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after, overflow specific reference path' '
+ cat >expect <<-\EOF &&
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/odd/spot/new >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after, with exclude pattern' '
+ cat >expect <<-\EOF &&
+ refs/tags/annotated-tag
+ refs/tags/doubly-annotated-tag
+ refs/tags/doubly-signed-tag
+ refs/tags/foo1.10
+ refs/tags/foo1.3
+ refs/tags/foo1.6
+ refs/tags/four
+ refs/tags/one
+ refs/tags/signed-tag
+ refs/tags/three
+ refs/tags/two
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/odd/spot \
+ --exclude=refs/tags/foo >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after, last reference' '
+ cat >expect <<-\EOF &&
+ EOF
+ git for-each-ref --format="%(refname)" --start-after=refs/tags/two >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after used with a pattern' '
+ cat >expect <<-\EOF &&
+ fatal: cannot use --start-after with patterns
+ EOF
+ test_must_fail git for-each-ref --format="%(refname)" --start-after=refs/odd/spot refs/tags 2>actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'start after used with custom sort order' '
+ cat >expect <<-\EOF &&
+ fatal: cannot use --start-after with custom sort options
+ EOF
+ test_must_fail git for-each-ref --format="%(refname)" --start-after=refs/odd/spot --sort=author 2>actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t6400-merge-df.sh b/t/t6400-merge-df.sh
index 3de4ef6bd9..b46fe49440 100755
--- a/t/t6400-merge-df.sh
+++ b/t/t6400-merge-df.sh
@@ -84,12 +84,7 @@ test_expect_success 'modify/delete + directory/file conflict' '
test_stdout_line_count = 5 git ls-files -s &&
test_stdout_line_count = 4 git ls-files -u &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_stdout_line_count = 0 git ls-files -o
- else
- test_stdout_line_count = 1 git ls-files -o
- fi &&
+ test_stdout_line_count = 0 git ls-files -o &&
test_path_is_file letters/file &&
test_path_is_file letters.txt &&
@@ -105,12 +100,7 @@ test_expect_success 'modify/delete + directory/file conflict; other way' '
test_stdout_line_count = 5 git ls-files -s &&
test_stdout_line_count = 4 git ls-files -u &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_stdout_line_count = 0 git ls-files -o
- else
- test_stdout_line_count = 1 git ls-files -o
- fi &&
+ test_stdout_line_count = 0 git ls-files -o &&
test_path_is_file letters/file &&
test_path_is_file letters.txt &&
diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh
index 2738b50c2a..ff00b74e9c 100755
--- a/t/t6402-merge-rename.sh
+++ b/t/t6402-merge-rename.sh
@@ -313,12 +313,7 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
test_grep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
test_grep "Auto-merging dir" output &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_grep "moving it to dir~HEAD instead" output
- else
- test_grep "Adding as dir~HEAD instead" output
- fi &&
+ test_grep "moving it to dir~HEAD instead" output &&
test_stdout_line_count = 3 git ls-files -u &&
test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
@@ -340,12 +335,7 @@ test_expect_success 'Same as previous, but merged other way' '
! grep "error: refusing to lose untracked file at" errors &&
test_grep "CONFLICT (modify/delete): dir/file-in-the-way" output &&
test_grep "Auto-merging dir" output &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_grep "moving it to dir~renamed-file-has-no-conflicts instead" output
- else
- test_grep "Adding as dir~renamed-file-has-no-conflicts instead" output
- fi &&
+ test_grep "moving it to dir~renamed-file-has-no-conflicts instead" output &&
test_stdout_line_count = 3 git ls-files -u &&
test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
@@ -400,14 +390,7 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t
test_must_fail git merge --strategy=recursive dir-in-way &&
test_stdout_line_count = 5 git ls-files -u &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_stdout_line_count = 3 git ls-files -u dir~HEAD
- else
- git ls-files -u dir >out &&
- test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
- rm -f out
- fi &&
+ test_stdout_line_count = 3 git ls-files -u dir~HEAD &&
test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
test_must_fail git diff --quiet &&
@@ -425,14 +408,7 @@ test_expect_success 'Same as previous, but merged other way' '
test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
test_stdout_line_count = 5 git ls-files -u &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts
- else
- git ls-files -u dir >out &&
- test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
- rm -f out
- fi &&
+ test_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts &&
test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
test_must_fail git diff --quiet &&
@@ -488,12 +464,7 @@ test_expect_success 'both rename source and destination involved in D/F conflict
git checkout -q rename-dest^0 &&
test_must_fail git merge --strategy=recursive source-conflict &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_stdout_line_count = 2 git ls-files -u
- else
- test_stdout_line_count = 1 git ls-files -u
- fi &&
+ test_stdout_line_count = 2 git ls-files -u &&
test_must_fail git diff --quiet &&
@@ -527,63 +498,33 @@ test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
git commit -m "Rename one/file -> two"
'
-if test "$GIT_TEST_MERGE_ALGORITHM" = ort
-then
- test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
- git checkout -q rename-one^0 &&
- mkdir one &&
- test_must_fail git merge --strategy=recursive rename-two &&
-
- test_stdout_line_count = 4 git ls-files -u &&
- test_stdout_line_count = 2 git ls-files -u one &&
- test_stdout_line_count = 2 git ls-files -u two &&
-
- test_must_fail git diff --quiet &&
-
- test 3 -eq $(find . | grep -v .git | wc -l) &&
-
- test_path_is_file one &&
- test_path_is_file two &&
- test "other" = $(cat one) &&
- test "stuff" = $(cat two)
- '
-else
- test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
- git checkout -q rename-one^0 &&
- mkdir one &&
- test_must_fail git merge --strategy=recursive rename-two &&
+test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
+ git checkout -q rename-one^0 &&
+ mkdir one &&
+ test_must_fail git merge --strategy=recursive rename-two &&
- test_stdout_line_count = 2 git ls-files -u &&
- test_stdout_line_count = 1 git ls-files -u one &&
- test_stdout_line_count = 1 git ls-files -u two &&
+ test_stdout_line_count = 4 git ls-files -u &&
+ test_stdout_line_count = 2 git ls-files -u one &&
+ test_stdout_line_count = 2 git ls-files -u two &&
- test_must_fail git diff --quiet &&
+ test_must_fail git diff --quiet &&
- test 4 -eq $(find . | grep -v .git | wc -l) &&
+ test 3 -eq $(find . | grep -v .git | wc -l) &&
- test_path_is_dir one &&
- test_path_is_file one~rename-two &&
- test_path_is_file two &&
- test "other" = $(cat one~rename-two) &&
- test "stuff" = $(cat two)
- '
-fi
+ test_path_is_file one &&
+ test_path_is_file two &&
+ test "other" = $(cat one) &&
+ test "stuff" = $(cat two)
+'
test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean start' '
git reset --hard &&
git clean -fdqx &&
test_must_fail git merge --strategy=recursive rename-two &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_stdout_line_count = 4 git ls-files -u &&
- test_stdout_line_count = 2 git ls-files -u one &&
- test_stdout_line_count = 2 git ls-files -u two
- else
- test_stdout_line_count = 2 git ls-files -u &&
- test_stdout_line_count = 1 git ls-files -u one &&
- test_stdout_line_count = 1 git ls-files -u two
- fi &&
+ test_stdout_line_count = 4 git ls-files -u &&
+ test_stdout_line_count = 2 git ls-files -u one &&
+ test_stdout_line_count = 2 git ls-files -u two &&
test_must_fail git diff --quiet &&
@@ -623,22 +564,12 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
git checkout -q first-rename^0 &&
test_must_fail git merge --strategy=recursive second-rename &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_stdout_line_count = 5 git ls-files -s &&
- test_stdout_line_count = 3 git ls-files -u &&
- test_stdout_line_count = 1 git ls-files -u one~HEAD &&
- test_stdout_line_count = 1 git ls-files -u two~second-rename &&
- test_stdout_line_count = 1 git ls-files -u original &&
- test_stdout_line_count = 0 git ls-files -o
- else
- test_stdout_line_count = 5 git ls-files -s &&
- test_stdout_line_count = 3 git ls-files -u &&
- test_stdout_line_count = 1 git ls-files -u one &&
- test_stdout_line_count = 1 git ls-files -u two &&
- test_stdout_line_count = 1 git ls-files -u original &&
- test_stdout_line_count = 2 git ls-files -o
- fi &&
+ test_stdout_line_count = 5 git ls-files -s &&
+ test_stdout_line_count = 3 git ls-files -u &&
+ test_stdout_line_count = 1 git ls-files -u one~HEAD &&
+ test_stdout_line_count = 1 git ls-files -u two~second-rename &&
+ test_stdout_line_count = 1 git ls-files -u original &&
+ test_stdout_line_count = 0 git ls-files -o &&
test_path_is_file one/file &&
test_path_is_file two/file &&
diff --git a/t/t6404-recursive-merge.sh b/t/t6404-recursive-merge.sh
index ae687f2ce5..346f3608b9 100755
--- a/t/t6404-recursive-merge.sh
+++ b/t/t6404-recursive-merge.sh
@@ -108,12 +108,7 @@ test_expect_success 'refuse to merge binary files' '
printf "\0\0" >binary-file &&
git add binary-file &&
git commit -m binary2 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git merge F >merge_output
- else
- test_must_fail git merge F 2>merge_output
- fi &&
+ test_must_fail git merge F >merge_output &&
grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge_output
'
@@ -129,22 +124,12 @@ test_expect_success 'mark rename/delete as unmerged' '
test_tick &&
git commit -m rename &&
test_must_fail git merge delete &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test 2 = $(git ls-files --unmerged | wc -l)
- else
- test 1 = $(git ls-files --unmerged | wc -l)
- fi &&
+ test 2 = $(git ls-files --unmerged | wc -l) &&
git rev-parse --verify :2:a2 &&
test_must_fail git rev-parse --verify :3:a2 &&
git checkout -f delete &&
test_must_fail git merge rename &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test 2 = $(git ls-files --unmerged | wc -l)
- else
- test 1 = $(git ls-files --unmerged | wc -l)
- fi &&
+ test 2 = $(git ls-files --unmerged | wc -l) &&
test_must_fail git rev-parse --verify :2:a2 &&
git rev-parse --verify :3:a2
'
diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh
index 66e01464b5..8f6fbef002 100755
--- a/t/t6406-merge-attr.sh
+++ b/t/t6406-merge-attr.sh
@@ -259,12 +259,7 @@ test_expect_success 'binary files with union attribute' '
printf "two\0" >bin.txt &&
git commit -am two &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git merge bin-main >output
- else
- test_must_fail git merge bin-main 2>output
- fi &&
+ test_must_fail git merge bin-main >output &&
grep -i "warning.*cannot merge.*HEAD vs. bin-main" output
'
diff --git a/t/t6416-recursive-corner-cases.sh b/t/t6416-recursive-corner-cases.sh
index 17b54d625d..ed20de8ea2 100755
--- a/t/t6416-recursive-corner-cases.sh
+++ b/t/t6416-recursive-corner-cases.sh
@@ -6,7 +6,6 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-merge.sh
#
# L1 L2
@@ -529,15 +528,8 @@ test_expect_success 'setup differently handled merges of directory/file conflict
git checkout B^0 &&
test_must_fail git merge C^0 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git rm -rf a/ &&
- git rm a~HEAD
- else
- git clean -fd &&
- git rm -rf a/ &&
- git rm a
- fi &&
+ git rm -rf a/ &&
+ git rm a~HEAD &&
git cat-file -p B:a >a2 &&
git add a2 &&
git commit -m D2 &&
@@ -556,12 +548,7 @@ test_expect_success 'setup differently handled merges of directory/file conflict
git checkout C^0 &&
test_must_fail git merge B^0 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git rm a~B^0
- else
- git clean -fd
- fi &&
+ git rm a~B^0 &&
git rm -rf a/ &&
test_write_lines 1 2 3 4 5 6 7 8 >a &&
git add a &&
@@ -570,15 +557,8 @@ test_expect_success 'setup differently handled merges of directory/file conflict
git checkout C^0 &&
test_must_fail git merge B^0 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git rm -rf a/ &&
- git rm a~B^0
- else
- git clean -fd &&
- git rm -rf a/ &&
- git rm a
- fi &&
+ git rm -rf a/ &&
+ git rm a~B^0 &&
test_write_lines 1 2 3 4 5 6 7 8 >a2 &&
git add a2 &&
git commit -m E4 &&
@@ -596,34 +576,16 @@ test_expect_success 'merge of D1 & E1 fails but has appropriate contents' '
test_must_fail git merge -s recursive E1^0 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git ls-files -s >out &&
- test_line_count = 3 out &&
- git ls-files -u >out &&
- test_line_count = 2 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >expect \
- A:ignore-me B:a D1:a &&
- git rev-parse >actual \
- :0:ignore-me :1:a :2:a &&
- test_cmp expect actual
- else
- git ls-files -s >out &&
- test_line_count = 2 out &&
- git ls-files -u >out &&
- test_line_count = 1 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >expect \
- A:ignore-me B:a &&
- git rev-parse >actual \
- :0:ignore-me :2:a &&
- test_cmp expect actual
- fi
+ git ls-files -s >out &&
+ test_line_count = 3 out &&
+ git ls-files -u >out &&
+ test_line_count = 2 out &&
+ git ls-files -o >out &&
+ test_line_count = 1 out &&
+
+ git rev-parse >expect A:ignore-me B:a D1:a &&
+ git rev-parse >actual :0:ignore-me :1:a :2:a &&
+ test_cmp expect actual
)
'
@@ -637,34 +599,18 @@ test_expect_success 'merge of E1 & D1 fails but has appropriate contents' '
test_must_fail git merge -s recursive D1^0 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git ls-files -s >out &&
- test_line_count = 3 out &&
- git ls-files -u >out &&
- test_line_count = 2 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >expect \
- A:ignore-me B:a D1:a &&
- git rev-parse >actual \
- :0:ignore-me :1:a :3:a &&
- test_cmp expect actual
- else
- git ls-files -s >out &&
- test_line_count = 2 out &&
- git ls-files -u >out &&
- test_line_count = 1 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >expect \
- A:ignore-me B:a &&
- git rev-parse >actual \
- :0:ignore-me :3:a &&
- test_cmp expect actual
- fi
+ git ls-files -s >out &&
+ test_line_count = 3 out &&
+ git ls-files -u >out &&
+ test_line_count = 2 out &&
+ git ls-files -o >out &&
+ test_line_count = 1 out &&
+
+ git rev-parse >expect \
+ A:ignore-me B:a D1:a &&
+ git rev-parse >actual \
+ :0:ignore-me :1:a :3:a &&
+ test_cmp expect actual
)
'
@@ -678,32 +624,17 @@ test_expect_success 'merge of D1 & E2 fails but has appropriate contents' '
test_must_fail git merge -s recursive E2^0 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git ls-files -s >out &&
- test_line_count = 5 out &&
- git ls-files -u >out &&
- test_line_count = 4 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >expect \
- B:a D1:a E2:a/file C:a/file A:ignore-me &&
- git rev-parse >actual \
- :1:a~HEAD :2:a~HEAD :3:a/file :1:a/file :0:ignore-me
- else
- git ls-files -s >out &&
- test_line_count = 4 out &&
- git ls-files -u >out &&
- test_line_count = 3 out &&
- git ls-files -o >out &&
- test_line_count = 2 out &&
-
- git rev-parse >expect \
- B:a E2:a/file C:a/file A:ignore-me &&
- git rev-parse >actual \
- :2:a :3:a/file :1:a/file :0:ignore-me
- fi &&
+ git ls-files -s >out &&
+ test_line_count = 5 out &&
+ git ls-files -u >out &&
+ test_line_count = 4 out &&
+ git ls-files -o >out &&
+ test_line_count = 1 out &&
+
+ git rev-parse >expect \
+ B:a D1:a E2:a/file C:a/file A:ignore-me &&
+ git rev-parse >actual \
+ :1:a~HEAD :2:a~HEAD :3:a/file :1:a/file :0:ignore-me &&
test_cmp expect actual &&
test_path_is_file a~HEAD
@@ -720,32 +651,17 @@ test_expect_success 'merge of E2 & D1 fails but has appropriate contents' '
test_must_fail git merge -s recursive D1^0 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git ls-files -s >out &&
- test_line_count = 5 out &&
- git ls-files -u >out &&
- test_line_count = 4 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >expect \
- B:a D1:a E2:a/file C:a/file A:ignore-me &&
- git rev-parse >actual \
- :1:a~D1^0 :3:a~D1^0 :2:a/file :1:a/file :0:ignore-me
- else
- git ls-files -s >out &&
- test_line_count = 4 out &&
- git ls-files -u >out &&
- test_line_count = 3 out &&
- git ls-files -o >out &&
- test_line_count = 2 out &&
-
- git rev-parse >expect \
- B:a E2:a/file C:a/file A:ignore-me &&
- git rev-parse >actual \
- :3:a :2:a/file :1:a/file :0:ignore-me
- fi &&
+ git ls-files -s >out &&
+ test_line_count = 5 out &&
+ git ls-files -u >out &&
+ test_line_count = 4 out &&
+ git ls-files -o >out &&
+ test_line_count = 1 out &&
+
+ git rev-parse >expect \
+ B:a D1:a E2:a/file C:a/file A:ignore-me &&
+ git rev-parse >actual \
+ :1:a~D1^0 :3:a~D1^0 :2:a/file :1:a/file :0:ignore-me &&
test_cmp expect actual &&
test_path_is_file a~D1^0
@@ -777,7 +693,7 @@ test_expect_success 'merge of D1 & E3 succeeds' '
)
'
-test_expect_merge_algorithm failure success 'merge of D1 & E4 puts merge of a and a2 in both a and a2' '
+test_expect_success 'merge of D1 & E4 puts merge of a and a2 in both a and a2' '
test_when_finished "git -C directory-file reset --hard" &&
test_when_finished "git -C directory-file clean -fdqx" &&
(
@@ -1140,7 +1056,7 @@ test_expect_success 'setup symlink modify/modify' '
)
'
-test_expect_merge_algorithm failure success 'check symlink modify/modify' '
+test_expect_success 'check symlink modify/modify' '
(
cd symlink-modify-modify &&
@@ -1206,7 +1122,7 @@ test_expect_success 'setup symlink add/add' '
)
'
-test_expect_merge_algorithm failure success 'check symlink add/add' '
+test_expect_success 'check symlink add/add' '
(
cd symlink-add-add &&
@@ -1294,7 +1210,7 @@ test_expect_success 'setup submodule modify/modify' '
)
'
-test_expect_merge_algorithm failure success 'check submodule modify/modify' '
+test_expect_success 'check submodule modify/modify' '
(
cd submodule-modify-modify &&
@@ -1382,7 +1298,7 @@ test_expect_success 'setup submodule add/add' '
)
'
-test_expect_merge_algorithm failure success 'check submodule add/add' '
+test_expect_success 'check submodule add/add' '
(
cd submodule-add-add &&
@@ -1457,7 +1373,7 @@ test_expect_success 'setup conflicting entry types (submodule vs symlink)' '
)
'
-test_expect_merge_algorithm failure success 'check conflicting entry types (submodule vs symlink)' '
+test_expect_success 'check conflicting entry types (submodule vs symlink)' '
(
cd submodule-symlink-add-add &&
diff --git a/t/t6421-merge-partial-clone.sh b/t/t6421-merge-partial-clone.sh
index b99f29ef9b..6eb51285a0 100755
--- a/t/t6421-merge-partial-clone.sh
+++ b/t/t6421-merge-partial-clone.sh
@@ -27,7 +27,6 @@ test_description="limiting blob downloads when merging with partial clones"
# files that might be renamed into each other's paths.)
. ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-merge.sh
test_setup_repo () {
test -d server && return
@@ -207,7 +206,7 @@ test_setup_repo () {
#
# Summary: 2 fetches (1 for 2 objects, 1 for 1 object)
#
-test_expect_merge_algorithm failure success 'Objects downloaded for single relevant rename' '
+test_expect_success 'Objects downloaded for single relevant rename' '
test_setup_repo &&
git clone --sparse --filter=blob:none "file://$(pwd)/server" objects-single &&
(
@@ -297,7 +296,7 @@ test_expect_merge_algorithm failure success 'Objects downloaded for single relev
# this are not all that common.)
# Summary: 1 fetches for 6 objects
#
-test_expect_merge_algorithm failure success 'Objects downloaded when a directory rename triggered' '
+test_expect_success 'Objects downloaded when a directory rename triggered' '
test_setup_repo &&
git clone --sparse --filter=blob:none "file://$(pwd)/server" objects-dir &&
(
@@ -399,7 +398,7 @@ test_expect_merge_algorithm failure success 'Objects downloaded when a directory
#
# Summary: 4 fetches (1 for 6 objects, 1 for 8, 1 for 3, 1 for 2)
#
-test_expect_merge_algorithm failure success 'Objects downloaded with lots of renames and modifications' '
+test_expect_success 'Objects downloaded with lots of renames and modifications' '
test_setup_repo &&
git clone --sparse --filter=blob:none "file://$(pwd)/server" objects-many &&
(
diff --git a/t/t6422-merge-rename-corner-cases.sh b/t/t6422-merge-rename-corner-cases.sh
index 62b49c67e2..f14c0fb30e 100755
--- a/t/t6422-merge-rename-corner-cases.sh
+++ b/t/t6422-merge-rename-corner-cases.sh
@@ -7,7 +7,6 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-merge.sh
test_setup_rename_delete_untracked () {
git init rename-delete-untracked &&
@@ -316,12 +315,7 @@ test_expect_success 'rename/directory conflict + clean content merge' '
git ls-files -u >out &&
test_line_count = 1 out &&
git ls-files -o >out &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_line_count = 1 out
- else
- test_line_count = 2 out
- fi &&
+ test_line_count = 1 out &&
echo 0 >expect &&
git cat-file -p base:file >>expect &&
@@ -350,12 +344,7 @@ test_expect_success 'rename/directory conflict + content merge conflict' '
git ls-files -u >out &&
test_line_count = 3 out &&
git ls-files -o >out &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_line_count = 1 out
- else
- test_line_count = 2 out
- fi &&
+ test_line_count = 1 out &&
git cat-file -p left-conflict:newfile >left &&
git cat-file -p base:file >base &&
@@ -369,14 +358,8 @@ test_expect_success 'rename/directory conflict + content merge conflict' '
git rev-parse >expect \
base:file left-conflict:newfile right:file &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git rev-parse >actual \
- :1:newfile~HEAD :2:newfile~HEAD :3:newfile~HEAD
- else
- git rev-parse >actual \
- :1:newfile :2:newfile :3:newfile
- fi &&
+ git rev-parse >actual \
+ :1:newfile~HEAD :2:newfile~HEAD :3:newfile~HEAD &&
test_cmp expect actual &&
test_path_is_file newfile/realfile &&
@@ -896,7 +879,7 @@ test_setup_rad () {
)
}
-test_expect_merge_algorithm failure success 'rad-check: rename/add/delete conflict' '
+test_expect_success 'rad-check: rename/add/delete conflict' '
test_setup_rad &&
(
cd rad &&
@@ -969,7 +952,7 @@ test_setup_rrdd () {
)
}
-test_expect_merge_algorithm failure success 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
+test_expect_success 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
test_setup_rrdd &&
(
cd rrdd &&
@@ -1058,7 +1041,7 @@ test_setup_mod6 () {
)
}
-test_expect_merge_algorithm failure success 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
+test_expect_success 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
test_setup_mod6 &&
(
cd mod6 &&
@@ -1163,10 +1146,7 @@ test_conflicts_with_adds_and_renames() {
cd simple_${sideL}_${sideR} &&
# Create some related files now
- for i in $(test_seq 1 10)
- do
- echo Random base content line $i
- done >file_v1 &&
+ test_seq -f "Random base content line %d" 1 10 >file_v1 &&
cp file_v1 file_v2 &&
echo modification >>file_v2 &&
@@ -1310,10 +1290,7 @@ test_setup_nested_conflicts_from_rename_rename () {
cd nested_conflicts_from_rename_rename &&
# Create some related files now
- for i in $(test_seq 1 10)
- do
- echo Random base content line $i
- done >file_v1 &&
+ test_seq -f "Random base content line %d" 1 10 >file_v1 &&
cp file_v1 file_v2 &&
cp file_v1 file_v3 &&
diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh
index 88d1cf2cde..533ac85dc8 100755
--- a/t/t6423-merge-rename-directories.sh
+++ b/t/t6423-merge-rename-directories.sh
@@ -26,8 +26,6 @@ test_description="recursive merge with directory renames"
# files that might be renamed into each other's paths.)
. ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-merge.sh
-
###########################################################################
# SECTION 1: Basic cases we should be able to handle
@@ -302,20 +300,11 @@ test_expect_success '1d: Directory renames cause a rename/rename(2to1) conflict'
git cat-file -p :2:x/wham >expect &&
git cat-file -p :3:x/wham >other &&
>empty &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git merge-file \
- -L "HEAD:y/wham" \
- -L "" \
- -L "B^0:z/wham" \
- expect empty other
- else
- test_must_fail git merge-file \
- -L "HEAD" \
- -L "" \
- -L "B^0" \
- expect empty other
- fi &&
+ test_must_fail git merge-file \
+ -L "HEAD:y/wham" \
+ -L "" \
+ -L "B^0:z/wham" \
+ expect empty other &&
test_cmp expect x/wham
)
'
@@ -1186,18 +1175,10 @@ test_expect_success '5d: Directory/file/file conflict due to directory rename' '
git ls-files -u >out &&
test_line_count = 1 out &&
git ls-files -o >out &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_line_count = 1 out &&
-
- git rev-parse >actual \
- :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d~HEAD :0:y/d/e
- else
- test_line_count = 2 out &&
-
- git rev-parse >actual \
- :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e
- fi &&
+ test_line_count = 1 out &&
+
+ git rev-parse >actual \
+ :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d~HEAD :0:y/d/e &&
git rev-parse >expect \
O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
test_cmp expect actual &&
@@ -1280,32 +1261,17 @@ test_expect_success '6a: Tricky rename/delete' '
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
test_grep "CONFLICT (rename/delete).*z/c.*y/c" out &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git ls-files -s >out &&
- test_line_count = 3 out &&
- git ls-files -u >out &&
- test_line_count = 2 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >actual \
- :0:y/b :1:y/c :3:y/c &&
- git rev-parse >expect \
- O:z/b O:z/c O:z/c
- else
- git ls-files -s >out &&
- test_line_count = 2 out &&
- git ls-files -u >out &&
- test_line_count = 1 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >actual \
- :0:y/b :3:y/c &&
- git rev-parse >expect \
- O:z/b O:z/c
- fi &&
+ git ls-files -s >out &&
+ test_line_count = 3 out &&
+ git ls-files -u >out &&
+ test_line_count = 2 out &&
+ git ls-files -o >out &&
+ test_line_count = 1 out &&
+
+ git rev-parse >actual \
+ :0:y/b :1:y/c :3:y/c &&
+ git rev-parse >expect \
+ O:z/b O:z/c O:z/c &&
test_cmp expect actual
)
'
@@ -1372,7 +1338,7 @@ test_setup_6b1 () {
)
}
-test_expect_merge_algorithm failure success '6b1: Same renames done on both sides, plus another rename' '
+test_expect_success '6b1: Same renames done on both sides, plus another rename' '
test_setup_6b1 &&
(
cd 6b1 &&
@@ -1445,7 +1411,7 @@ test_setup_6b2 () {
)
}
-test_expect_merge_algorithm failure success '6b2: Same rename done on both sides' '
+test_expect_success '6b2: Same rename done on both sides' '
test_setup_6b2 &&
(
cd 6b2 &&
@@ -1832,20 +1798,11 @@ test_expect_success '7b: rename/rename(2to1), but only due to transitive rename'
git cat-file -p :2:y/d >expect &&
git cat-file -p :3:y/d >other &&
>empty &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git merge-file \
- -L "HEAD:y/d" \
- -L "" \
- -L "B^0:z/d" \
- expect empty other
- else
- test_must_fail git merge-file \
- -L "HEAD" \
- -L "" \
- -L "B^0" \
- expect empty other
- fi &&
+ test_must_fail git merge-file \
+ -L "HEAD:y/d" \
+ -L "" \
+ -L "B^0:z/d" \
+ expect empty other &&
test_cmp expect y/d
)
'
@@ -1967,32 +1924,17 @@ test_expect_success '7d: transitive rename involved in rename/delete; how is it
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
test_grep "CONFLICT (rename/delete).*x/d.*y/d" out &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git ls-files -s >out &&
- test_line_count = 4 out &&
- git ls-files -u >out &&
- test_line_count = 2 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >actual \
- :0:y/b :0:y/c :1:y/d :3:y/d &&
- git rev-parse >expect \
- O:z/b O:z/c O:x/d O:x/d
- else
- git ls-files -s >out &&
- test_line_count = 3 out &&
- git ls-files -u >out &&
- test_line_count = 1 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >actual \
- :0:y/b :0:y/c :3:y/d &&
- git rev-parse >expect \
- O:z/b O:z/c O:x/d
- fi &&
+ git ls-files -s >out &&
+ test_line_count = 4 out &&
+ git ls-files -u >out &&
+ test_line_count = 2 out &&
+ git ls-files -o >out &&
+ test_line_count = 1 out &&
+
+ git rev-parse >actual \
+ :0:y/b :0:y/c :1:y/d :3:y/d &&
+ git rev-parse >expect \
+ O:z/b O:z/c O:x/d O:x/d &&
test_cmp expect actual
)
'
@@ -2073,32 +2015,17 @@ test_expect_success '7e: transitive rename in rename/delete AND dirs in the way'
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
test_grep "CONFLICT (rename/delete).*x/d.*y/d" out &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git ls-files -s >out &&
- test_line_count = 6 out &&
- git ls-files -u >out &&
- test_line_count = 2 out &&
- git ls-files -o >out &&
- test_line_count = 1 out &&
-
- git rev-parse >actual \
- :0:x/d/f :0:y/d/g :0:y/b :0:y/c :1:y/d~B^0 :3:y/d~B^0 &&
- git rev-parse >expect \
- A:x/d/f A:y/d/g O:z/b O:z/c O:x/d O:x/d
- else
- git ls-files -s >out &&
- test_line_count = 5 out &&
- git ls-files -u >out &&
- test_line_count = 1 out &&
- git ls-files -o >out &&
- test_line_count = 2 out &&
-
- git rev-parse >actual \
- :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
- git rev-parse >expect \
- A:x/d/f A:y/d/g O:z/b O:z/c O:x/d
- fi &&
+ git ls-files -s >out &&
+ test_line_count = 6 out &&
+ git ls-files -u >out &&
+ test_line_count = 2 out &&
+ git ls-files -o >out &&
+ test_line_count = 1 out &&
+
+ git rev-parse >actual \
+ :0:x/d/f :0:y/d/g :0:y/b :0:y/c :1:y/d~B^0 :3:y/d~B^0 &&
+ git rev-parse >expect \
+ A:x/d/f A:y/d/g O:z/b O:z/c O:x/d O:x/d &&
test_cmp expect actual &&
git hash-object y/d~B^0 >actual &&
@@ -3284,34 +3211,15 @@ test_expect_success '10b: Overwrite untracked with dir rename + delete' '
echo contents >y/e &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
-
- git ls-files -s >out &&
- test_line_count = 1 out &&
- git ls-files -u >out &&
- test_line_count = 0 out &&
- git ls-files -o >out &&
- test_line_count = 5 out
- else
- test_grep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
- test_grep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
-
- git ls-files -s >out &&
- test_line_count = 3 out &&
- git ls-files -u >out &&
- test_line_count = 2 out &&
- git ls-files -o >out &&
- test_line_count = 5 out &&
-
- git rev-parse >actual \
- :0:y/b :3:y/d :3:y/e &&
- git rev-parse >expect \
- O:z/b O:z/c B:z/e &&
- test_cmp expect actual
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
+
+ git ls-files -s >out &&
+ test_line_count = 1 out &&
+ git ls-files -u >out &&
+ test_line_count = 0 out &&
+ git ls-files -o >out &&
+ test_line_count = 5 out &&
echo very >expect &&
test_cmp expect y/c &&
@@ -3374,38 +3282,15 @@ test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' '
echo important >y/c &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
-
- git ls-files -s >out &&
- test_line_count = 4 out &&
- git ls-files -u >out &&
- test_line_count = 0 out &&
- git ls-files -o >out &&
- test_line_count = 3 out
- else
- test_grep "CONFLICT (rename/rename)" out &&
- test_grep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
-
- git ls-files -s >out &&
- test_line_count = 6 out &&
- git ls-files -u >out &&
- test_line_count = 3 out &&
- git ls-files -o >out &&
- test_line_count = 3 out &&
-
- git rev-parse >actual \
- :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
- git rev-parse >expect \
- O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
- test_cmp expect actual &&
-
- git hash-object y/c~B^0 >actual &&
- git rev-parse O:x/c >expect &&
- test_cmp expect actual
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
+
+ git ls-files -s >out &&
+ test_line_count = 4 out &&
+ git ls-files -u >out &&
+ test_line_count = 0 out &&
+ git ls-files -o >out &&
+ test_line_count = 3 out &&
echo important >expect &&
test_cmp expect y/c
@@ -3425,38 +3310,15 @@ test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), oth
echo important >y/c &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
-
- git ls-files -s >out &&
- test_line_count = 4 out &&
- git ls-files -u >out &&
- test_line_count = 0 out &&
- git ls-files -o >out &&
- test_line_count = 3 out
- else
- test_grep "CONFLICT (rename/rename)" out &&
- test_grep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
-
- git ls-files -s >out &&
- test_line_count = 6 out &&
- git ls-files -u >out &&
- test_line_count = 3 out &&
- git ls-files -o >out &&
- test_line_count = 3 out &&
-
- git rev-parse >actual \
- :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
- git rev-parse >expect \
- O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
- test_cmp expect actual &&
-
- git hash-object y/c~HEAD >actual &&
- git rev-parse O:x/c >expect &&
- test_cmp expect actual
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
+
+ git ls-files -s >out &&
+ test_line_count = 4 out &&
+ git ls-files -u >out &&
+ test_line_count = 0 out &&
+ git ls-files -o >out &&
+ test_line_count = 3 out &&
echo important >expect &&
test_cmp expect y/c
@@ -3514,47 +3376,15 @@ test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' '
echo important >y/wham &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
-
- git ls-files -s >out &&
- test_line_count = 6 out &&
- git ls-files -u >out &&
- test_line_count = 0 out &&
- git ls-files -o >out &&
- test_line_count = 3 out
- else
- test_grep "CONFLICT (rename/rename)" out &&
- test_grep "Refusing to lose untracked file at y/wham" out &&
-
- git ls-files -s >out &&
- test_line_count = 6 out &&
- git ls-files -u >out &&
- test_line_count = 2 out &&
- git ls-files -o >out &&
- test_line_count = 3 out &&
-
- git rev-parse >actual \
- :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
- git rev-parse >expect \
- O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
- test_cmp expect actual &&
-
- test_must_fail git rev-parse :1:y/wham &&
-
- # Test that two-way merge in y/wham~merged is as expected
- git cat-file -p :2:y/wham >expect &&
- git cat-file -p :3:y/wham >other &&
- >empty &&
- test_must_fail git merge-file \
- -L "HEAD" \
- -L "" \
- -L "B^0" \
- expect empty other &&
- test_cmp expect y/wham~merged
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
+
+ git ls-files -s >out &&
+ test_line_count = 6 out &&
+ git ls-files -u >out &&
+ test_line_count = 0 out &&
+ git ls-files -o >out &&
+ test_line_count = 3 out &&
echo important >expect &&
test_cmp expect y/wham
@@ -3596,7 +3426,7 @@ test_setup_10e () {
)
}
-test_expect_merge_algorithm failure success '10e: Does git complain about untracked file that is not really in the way?' '
+test_expect_success '10e: Does git complain about untracked file that is not really in the way?' '
test_setup_10e &&
(
cd 10e &&
@@ -3687,30 +3517,8 @@ test_expect_success '11a: Avoid losing dirty contents with simple rename' '
echo stuff >>z/c &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: Your local changes to the following files would be overwritten by merge" err
- else
- test_grep "Refusing to lose dirty file at z/c" out &&
-
- git ls-files -s >out &&
- test_line_count = 2 out &&
- git ls-files -u >out &&
- test_line_count = 1 out &&
- git ls-files -o >out &&
- test_line_count = 3 out &&
-
- git rev-parse >actual \
- :0:z/a :2:z/c &&
- git rev-parse >expect \
- O:z/a B:z/b &&
- test_cmp expect actual &&
-
- git hash-object z/c~HEAD >actual &&
- git rev-parse B:z/b >expect &&
- test_cmp expect actual
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: Your local changes to the following files would be overwritten by merge" err &&
test_seq 1 10 >expected &&
echo stuff >>expected &&
@@ -3766,34 +3574,9 @@ test_expect_success '11b: Avoid losing dirty file involved in directory rename'
git checkout A^0 &&
echo stuff >>z/c &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: Your local changes to the following files would be overwritten by merge" err
- else
- git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- test_grep "Refusing to lose dirty file at z/c" out &&
-
- git ls-files -s >out &&
- test_line_count = 3 out &&
- git ls-files -u >out &&
- test_line_count = 0 out &&
- git ls-files -m >out &&
- test_line_count = 0 out &&
- git ls-files -o >out &&
- test_line_count = 3 out &&
-
- git rev-parse >actual \
- :0:x/b :0:y/a :0:y/c &&
- git rev-parse >expect \
- O:x/b O:z/a B:x/c &&
- test_cmp expect actual &&
-
- git hash-object y/c >actual &&
- git rev-parse B:x/c >expect &&
- test_cmp expect actual
- fi &&
+ test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: Your local changes to the following files would be overwritten by merge" err &&
grep -q stuff z/c &&
test_seq 1 10 >expected &&
@@ -3850,13 +3633,8 @@ test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict'
echo stuff >>y/c &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: Your local changes to the following files would be overwritten by merge" err
- else
- test_grep "following files would be overwritten by merge" err
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: Your local changes to the following files would be overwritten by merge" err &&
grep -q stuff y/c &&
test_seq 1 10 >expected &&
@@ -3924,30 +3702,8 @@ test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict'
echo stuff >>z/c &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: Your local changes to the following files would be overwritten by merge" err
- else
- test_grep "Refusing to lose dirty file at z/c" out &&
-
- git ls-files -s >out &&
- test_line_count = 4 out &&
- git ls-files -u >out &&
- test_line_count = 1 out &&
- git ls-files -o >out &&
- test_line_count = 4 out &&
-
- git rev-parse >actual \
- :0:x/b :0:y/a :0:y/c/d :3:y/c &&
- git rev-parse >expect \
- O:x/b O:z/a B:y/c/d B:x/c &&
- test_cmp expect actual &&
-
- git hash-object y/c~HEAD >actual &&
- git rev-parse B:x/c >expect &&
- test_cmp expect actual
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: Your local changes to the following files would be overwritten by merge" err &&
grep -q stuff z/c &&
test_seq 1 10 >expected &&
@@ -4010,39 +3766,8 @@ test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to
echo mods >>y/c &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: Your local changes to the following files would be overwritten by merge" err
- else
- test_grep "CONFLICT (rename/rename)" out &&
- test_grep "Refusing to lose dirty file at y/c" out &&
-
- git ls-files -s >out &&
- test_line_count = 7 out &&
- git ls-files -u >out &&
- test_line_count = 4 out &&
- git ls-files -o >out &&
- test_line_count = 3 out &&
-
- git rev-parse >actual \
- :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
- git rev-parse >expect \
- O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
- test_cmp expect actual &&
-
- # See if y/c~merged has expected contents; requires manually
- # doing the expected file merge
- git cat-file -p A:y/c >c1 &&
- git cat-file -p B:z/c >c2 &&
- >empty &&
- test_must_fail git merge-file \
- -L "HEAD" \
- -L "" \
- -L "B^0" \
- c1 empty c2 &&
- test_cmp c1 y/c~merged
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: Your local changes to the following files would be overwritten by merge" err &&
echo different >expected &&
echo mods >>expected &&
@@ -4099,40 +3824,8 @@ test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to
echo important >>y/wham &&
test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_path_is_missing .git/MERGE_HEAD &&
- test_grep "error: Your local changes to the following files would be overwritten by merge" err
- else
- test_grep "CONFLICT (rename/rename)" out &&
- test_grep "Refusing to lose dirty file at y/wham" out &&
-
- git ls-files -s >out &&
- test_line_count = 4 out &&
- git ls-files -u >out &&
- test_line_count = 2 out &&
- git ls-files -o >out &&
- test_line_count = 3 out &&
-
- test_must_fail git rev-parse :1:y/wham &&
-
- git rev-parse >actual \
- :0:y/a :0:y/b :2:y/wham :3:y/wham &&
- git rev-parse >expect \
- O:z/a O:z/b O:x/c O:x/d &&
- test_cmp expect actual &&
-
- # Test that two-way merge in y/wham~merged is as expected
- git cat-file -p :2:y/wham >expect &&
- git cat-file -p :3:y/wham >other &&
- >empty &&
- test_must_fail git merge-file \
- -L "HEAD" \
- -L "" \
- -L "B^0" \
- expect empty other &&
- test_cmp expect y/wham~merged
- fi &&
+ test_path_is_missing .git/MERGE_HEAD &&
+ test_grep "error: Your local changes to the following files would be overwritten by merge" err &&
test_seq 1 10 >expected &&
echo important >>expected &&
@@ -4267,7 +3960,7 @@ test_setup_12b1 () {
)
}
-test_expect_merge_algorithm failure success '12b1: Moving two directory hierarchies into each other' '
+test_expect_success '12b1: Moving two directory hierarchies into each other' '
test_setup_12b1 &&
(
cd 12b1 &&
@@ -4435,7 +4128,7 @@ test_setup_12c1 () {
)
}
-test_expect_merge_algorithm failure success '12c1: Moving one directory hierarchy into another w/ content merge' '
+test_expect_success '12c1: Moving one directory hierarchy into another w/ content merge' '
test_setup_12c1 &&
(
cd 12c1 &&
@@ -4797,7 +4490,7 @@ test_setup_12f () {
)
}
-test_expect_merge_algorithm failure success '12f: Trivial directory resolve, caching, all kinds of fun' '
+test_expect_success '12f: Trivial directory resolve, caching, all kinds of fun' '
test_setup_12f &&
(
cd 12f &&
@@ -5038,7 +4731,7 @@ test_setup_12i () {
mkdir -p source/subdir &&
echo foo >source/subdir/foo &&
- echo bar >source/bar &&
+ printf "%d\n" 1 2 3 4 5 6 7 >source/bar &&
echo baz >source/baz &&
git add source &&
git commit -m orig &&
@@ -5054,6 +4747,7 @@ test_setup_12i () {
git switch B &&
git mv source/bar source/subdir/bar &&
echo more baz >>source/baz &&
+ git add source/baz &&
git commit -m B
)
}
@@ -5065,19 +4759,102 @@ test_expect_success '12i: Directory rename causes rename-to-self' '
git checkout A^0 &&
+ # NOTE: A potentially better resolution would be for
+ # source/bar -> source/subdir/bar
+ # to use the directory rename to become
+ # source/bar -> source/bar
+ # (a rename to self), and thus we end up with bar with
+ # a path conflict (given merge.directoryRenames=conflict).
+ # However, since the relevant renames optimization
+ # prevents us from noticing
+ # source/bar -> source/subdir/bar
+ # as a rename and looking at it just as
+ # delete source/bar
+ # add source/subdir/bar
+ # the directory rename of source/subdir/bar -> source/bar does
+ # not look like a rename-to-self situation but a
+ # rename-on-top-of-other-file situation. We do not want
+ # stage 1 entries from an unrelated file, so we expect an
+ # error about there being a file in the way.
+
+ test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 >out &&
+
+ grep "CONFLICT (implicit dir rename).*source/bar in the way" out &&
+ test_path_is_missing source/bar &&
+ test_path_is_file source/subdir/bar &&
+ test_path_is_file source/baz &&
+
+ git ls-files >actual &&
+ uniq <actual >tracked &&
+ test_line_count = 3 tracked &&
+
+ git status --porcelain -uno >actual &&
+ cat >expect <<-\EOF &&
+ M source/baz
+ R source/bar -> source/subdir/bar
+ EOF
+ test_cmp expect actual
+ )
+'
+
+# Testcase 12i2, Identical to 12i except that source/subdir/bar modified on unrenamed side
+# Commit O: source/{subdir/foo, bar, baz_1}
+# Commit A: source/{foo, bar_2, baz_1}
+# Commit B: source/{subdir/{foo, bar}, baz_2}
+# Expected: source/{foo, bar, baz_2}, with conflicts on
+# source/bar vs. source/subdir/bar
+
+test_setup_12i2 () {
+ git init 12i2 &&
+ (
+ cd 12i2 &&
+
+ mkdir -p source/subdir &&
+ echo foo >source/subdir/foo &&
+ printf "%d\n" 1 2 3 4 5 6 7 >source/bar &&
+ echo baz >source/baz &&
+ git add source &&
+ git commit -m orig &&
+
+ git branch O &&
+ git branch A &&
+ git branch B &&
+
+ git switch A &&
+ git mv source/subdir/foo source/foo &&
+ echo 8 >> source/bar &&
+ git add source/bar &&
+ git commit -m A &&
+
+ git switch B &&
+ git mv source/bar source/subdir/bar &&
+ echo more baz >>source/baz &&
+ git add source/baz &&
+ git commit -m B
+ )
+}
+
+test_expect_success '12i2: Directory rename causes rename-to-self' '
+ test_setup_12i2 &&
+ (
+ cd 12i2 &&
+
+ git checkout A^0 &&
+
test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
test_path_is_missing source/subdir &&
test_path_is_file source/bar &&
test_path_is_file source/baz &&
- git ls-files | uniq >tracked &&
+ git ls-files >actual &&
+ uniq <actual >tracked &&
test_line_count = 3 tracked &&
git status --porcelain -uno >actual &&
cat >expect <<-\EOF &&
UU source/bar
- M source/baz
+ M source/baz
EOF
test_cmp expect actual
)
@@ -5112,6 +4889,7 @@ test_setup_12j () {
git switch B &&
git mv bar subdir/bar &&
echo more baz >>baz &&
+ git add baz &&
git commit -m B
)
}
@@ -5123,19 +4901,39 @@ test_expect_success '12j: Directory rename to root causes rename-to-self' '
git checkout A^0 &&
- test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
-
- test_path_is_missing subdir &&
- test_path_is_file bar &&
+ # NOTE: A potentially better resolution would be for
+ # bar -> subdir/bar
+ # to use the directory rename to become
+ # bar -> bar
+ # (a rename to self), and thus we end up with bar with
+ # a path conflict (given merge.directoryRenames=conflict).
+ # However, since the relevant renames optimization
+ # prevents us from noticing
+ # bar -> subdir/bar
+ # as a rename and looking at it just as
+ # delete bar
+ # add subdir/bar
+ # the directory rename of subdir/bar -> bar does not look
+ # like a rename-to-self situation but a
+ # rename-on-top-of-other-file situation. We do not want
+ # stage 1 entries from an unrelated file, so we expect an
+ # error about there being a file in the way.
+
+ test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 >out &&
+ grep "CONFLICT (implicit dir rename).*bar in the way" out &&
+
+ test_path_is_missing bar &&
+ test_path_is_file subdir/bar &&
test_path_is_file baz &&
- git ls-files | uniq >tracked &&
+ git ls-files >actual &&
+ uniq <actual >tracked &&
test_line_count = 3 tracked &&
git status --porcelain -uno >actual &&
cat >expect <<-\EOF &&
- UU bar
- M baz
+ M baz
+ R bar -> subdir/bar
EOF
test_cmp expect actual
)
@@ -5170,6 +4968,7 @@ test_setup_12k () {
git switch B &&
git mv dirA/bar dirB/bar &&
echo more baz >>dirA/baz &&
+ git add dirA/baz &&
git commit -m B
)
}
@@ -5181,19 +4980,39 @@ test_expect_success '12k: Directory rename with sibling causes rename-to-self' '
git checkout A^0 &&
- test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
-
- test_path_is_missing dirB &&
- test_path_is_file dirA/bar &&
+ # NOTE: A potentially better resolution would be for
+ # dirA/bar -> dirB/bar
+ # to use the directory rename (dirB/ -> dirA/) to become
+ # dirA/bar -> dirA/bar
+ # (a rename to self), and thus we end up with bar with
+ # a path conflict (given merge.directoryRenames=conflict).
+ # However, since the relevant renames optimization
+ # prevents us from noticing
+ # dirA/bar -> dirB/bar
+ # as a rename and looking at it just as
+ # delete dirA/bar
+ # add dirB/bar
+ # the directory rename of dirA/bar -> dirB/bar does
+ # not look like a rename-to-self situation but a
+ # rename-on-top-of-other-file situation. We do not want
+ # stage 1 entries from an unrelated file, so we expect an
+ # error about there being a file in the way.
+
+ test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 >out &&
+ grep "CONFLICT (implicit dir rename).*dirA/bar in the way" out &&
+
+ test_path_is_missing dirA/bar &&
+ test_path_is_file dirB/bar &&
test_path_is_file dirA/baz &&
- git ls-files | uniq >tracked &&
+ git ls-files >actual &&
+ uniq <actual >tracked &&
test_line_count = 3 tracked &&
git status --porcelain -uno >actual &&
cat >expect <<-\EOF &&
- UU dirA/bar
- M dirA/baz
+ M dirA/baz
+ R dirA/bar -> dirB/bar
EOF
test_cmp expect actual
)
@@ -5250,7 +5069,7 @@ test_setup_12l () {
)
}
-test_expect_merge_algorithm failure success '12l (B into A): Rename into each other + add/add conflict' '
+test_expect_success '12l (B into A): Rename into each other + add/add conflict' '
test_setup_12l BintoA &&
(
cd 12l_BintoA &&
@@ -5277,7 +5096,7 @@ test_expect_merge_algorithm failure success '12l (B into A): Rename into each ot
)
'
-test_expect_merge_algorithm failure success '12l (A into B): Rename into each other + add/add conflict' '
+test_expect_success '12l (A into B): Rename into each other + add/add conflict' '
test_setup_12l AintoB &&
(
cd 12l_AintoB &&
@@ -5345,7 +5164,7 @@ test_setup_12m () {
)
}
-test_expect_merge_algorithm failure success '12m: Change parent of renamed-dir to symlink on other side' '
+test_expect_success '12m: Change parent of renamed-dir to symlink on other side' '
test_setup_12m &&
(
cd 12m &&
@@ -5360,6 +5179,413 @@ test_expect_merge_algorithm failure success '12m: Change parent of renamed-dir t
)
'
+# Testcase 12n, Directory rename transitively makes rename back to self
+#
+# (Since this is a cherry-pick instead of merge, the labels are a bit weird.
+# O, the original commit, is A~1 rather than what branch O points to.)
+#
+# Commit O: tools/hello
+# world
+# Commit A: tools/hello
+# tools/world
+# Commit B: hello
+# In words:
+# A: world -> tools/world
+# B: tools/ -> /, i.e. rename all of tools to toplevel directory
+# delete world
+#
+# Expected:
+# CONFLICT (file location): tools/world vs. world
+#
+
+test_setup_12n () {
+ git init 12n &&
+ (
+ cd 12n &&
+
+ mkdir tools &&
+ echo hello >tools/hello &&
+ git add tools/hello &&
+ git commit -m "O" &&
+
+ git branch O &&
+ git branch A &&
+ git branch B &&
+
+ git switch A &&
+ echo world >world &&
+ git add world &&
+ git commit -q world -m 'Add world' &&
+
+ git mv world tools/world &&
+ git commit -m "Move world into tools/" &&
+
+ git switch B &&
+ git mv tools/hello hello &&
+ git commit -m "Move hello from tools/ to toplevel"
+ )
+}
+
+test_expect_success '12n: Directory rename transitively makes rename back to self' '
+ test_setup_12n &&
+ (
+ cd 12n &&
+
+ git checkout -q B^0 &&
+
+ test_must_fail git cherry-pick A^0 >out &&
+ test_grep "CONFLICT (file location).*should perhaps be moved" out &&
+
+ # Should have 1 entry for hello, and 2 for world
+ test_stdout_line_count = 3 git ls-files -s &&
+ test_stdout_line_count = 1 git ls-files -s hello &&
+ test_stdout_line_count = 2 git ls-files -s world
+ )
+'
+
+# Testcase 12n2, Directory rename transitively makes rename back to self
+#
+# Commit O: tools/hello
+# world
+# Commit A: tools/hello
+# tools/world
+# Commit B: hello
+# In words:
+# A: world -> tools/world
+# B: tools/ -> /, i.e. rename all of tools to toplevel directory
+# delete world
+#
+# Expected:
+# CONFLICT (file location): tools/world vs. world
+#
+
+test_setup_12n2 () {
+ git init 12n2 &&
+ (
+ cd 12n2 &&
+
+ mkdir tools &&
+ echo hello >tools/hello &&
+ git add tools/hello &&
+ echo world >world &&
+ git add world &&
+ git commit -m "O" &&
+
+ git branch O &&
+ git branch A &&
+ git branch B &&
+
+ git switch A &&
+ git mv world tools/world &&
+ git commit -m "Move world into tools/" &&
+
+ git switch B &&
+ git mv tools/hello hello &&
+ git rm world &&
+ git commit -m "Move hello from tools/ to toplevel"
+ )
+}
+
+test_expect_success '12n2: Directory rename transitively makes rename back to self' '
+ test_setup_12n2 &&
+ (
+ cd 12n2 &&
+
+ git checkout -q B^0 &&
+
+ test_might_fail git -c merge.directoryRenames=true merge A^0 >out &&
+
+ # Should have 1 entry for hello, and either 0 or 2 for world
+ #
+ # NOTE: Since merge.directoryRenames=true, there is no path
+ # conflict for world vs. tools/world; it should end up at
+ # world. The fact that world was unmodified on side A, means
+ # there was no content conflict; we should just take the
+ # content from side B -- i.e. delete the file. So merging
+ # could just delete world.
+ #
+ # However, rename-to-self-via-directory-rename is a bit more
+ # challenging. Relax this test to allow world to be treated
+ # as a modify/delete conflict as well, meaning it will have
+ # two higher order stages, that just so happen to match.
+ #
+ test_stdout_line_count = 1 git ls-files -s hello &&
+ test_stdout_line_count = 2 git ls-files -s world &&
+ test_grep "CONFLICT (modify/delete).*world deleted in HEAD" out
+ )
+'
+
+# Testcase 12o, Directory rename hits other rename source; file still in way on same side
+# Commit O: A/file1_1
+# A/stuff
+# B/file1_2
+# B/stuff
+# C/other
+# Commit A: A/file1_1
+# A/stuff
+# B/stuff
+# C/file1_2
+# C/other
+# Commit B: D/file2_1
+# A/stuff
+# B/file1_2
+# B/stuff
+# A/other
+# In words:
+# A: rename B/file1_2 -> C/file1_2
+# B: rename C/ -> A/
+# rename A/file1_1 -> D/file2_1
+# Rationale:
+# A/stuff is unmodified, it shows up in final output
+# B/stuff is unmodified, it shows up in final output
+# C/other touched on one side (rename to A), so A/other shows up in output
+# A/file1 is renamed to D/file2
+# B/file1 -> C/file1 and even though C/ -> A/, A/file1 is
+# "in the way" so we don't do the directory rename
+# Expected: A/stuff
+# B/stuff
+# A/other
+# D/file2
+# C/file1
+# + CONFLICT (implicit dir rename): A/file1 in way of C/file1
+#
+
+test_setup_12o () {
+ git init 12o &&
+ (
+ cd 12o &&
+
+ mkdir -p A B C &&
+ echo 1 >A/file1 &&
+ echo 2 >B/file1 &&
+ echo other >C/other &&
+ echo Astuff >A/stuff &&
+ echo Bstuff >B/stuff &&
+ git add . &&
+ git commit -m "O" &&
+
+ git branch O &&
+ git branch A &&
+ git branch B &&
+
+ git switch A &&
+ git mv B/file1 C/ &&
+ git add . &&
+ git commit -m "A" &&
+
+ git switch B &&
+ mkdir -p D &&
+ git mv A/file1 D/file2 &&
+ git mv C/other A/other &&
+ git add . &&
+ git commit -m "B"
+ )
+}
+
+test_expect_success '12o: Directory rename hits other rename source; file still in way on same side' '
+ test_setup_12o &&
+ (
+ cd 12o &&
+
+ git checkout -q A^0 &&
+
+ test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 >out &&
+
+ test_stdout_line_count = 5 git ls-files -s &&
+ test_stdout_line_count = 1 git ls-files -s A/other &&
+ test_stdout_line_count = 1 git ls-files -s A/stuff &&
+ test_stdout_line_count = 1 git ls-files -s B/stuff &&
+ test_stdout_line_count = 1 git ls-files -s D/file2 &&
+
+ grep "CONFLICT (implicit dir rename).*Existing file/dir at A/file1 in the way" out &&
+ test_stdout_line_count = 1 git ls-files -s C/file1
+ )
+'
+
+# Testcase 12p, Directory rename hits other rename source; file still in way on other side
+# Commit O: A/file1_1
+# A/stuff
+# B/file1_2
+# B/stuff
+# C/other
+# Commit A: D/file2_1
+# A/stuff
+# B/stuff
+# C/file1_2
+# C/other
+# Commit B: A/file1_1
+# A/stuff
+# B/file1_2
+# B/stuff
+# A/other
+# Short version:
+# A: rename A/file1_1 -> D/file2_1
+# rename B/file1_2 -> C/file1_2
+# B: Rename C/ -> A/
+# Rationale:
+# A/stuff is unmodified, it shows up in final output
+# B/stuff is unmodified, it shows up in final output
+# C/other touched on one side (rename to A), so A/other shows up in output
+# A/file1 is renamed to D/file2
+# B/file1 -> C/file1 and even though C/ -> A/, A/file1 is
+# "in the way" so we don't do the directory rename
+# Expected: A/stuff
+# B/stuff
+# A/other
+# D/file2
+# C/file1
+# + CONFLICT (implicit dir rename): A/file1 in way of C/file1
+#
+
+test_setup_12p () {
+ git init 12p &&
+ (
+ cd 12p &&
+
+ mkdir -p A B C &&
+ echo 1 >A/file1 &&
+ echo 2 >B/file1 &&
+ echo other >C/other &&
+ echo Astuff >A/stuff &&
+ echo Bstuff >B/stuff &&
+ git add . &&
+ git commit -m "O" &&
+
+ git branch O &&
+ git branch A &&
+ git branch B &&
+
+ git switch A &&
+ mkdir -p D &&
+ git mv A/file1 D/file2 &&
+ git mv B/file1 C/ &&
+ git add . &&
+ git commit -m "A" &&
+
+ git switch B &&
+ git mv C/other A/other &&
+ git add . &&
+ git commit -m "B"
+ )
+}
+
+test_expect_success '12p: Directory rename hits other rename source; file still in way on other side' '
+ test_setup_12p &&
+ (
+ cd 12p &&
+
+ git checkout -q A^0 &&
+
+ test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 >out &&
+
+ test_stdout_line_count = 5 git ls-files -s &&
+ test_stdout_line_count = 1 git ls-files -s A/other &&
+ test_stdout_line_count = 1 git ls-files -s A/stuff &&
+ test_stdout_line_count = 1 git ls-files -s B/stuff &&
+ test_stdout_line_count = 1 git ls-files -s D/file2 &&
+
+ grep "CONFLICT (implicit dir rename).*Existing file/dir at A/file1 in the way" out &&
+ test_stdout_line_count = 1 git ls-files -s C/file1
+ )
+'
+
+# Testcase 12q, Directory rename hits other rename source; file removed though
+# Commit O: A/file1_1
+# A/stuff
+# B/file1_2
+# B/stuff
+# C/other
+# Commit A: A/stuff
+# B/stuff
+# C/file1_2
+# C/other
+# Commit B: D/file2_1
+# A/stuff
+# B/file1_2
+# B/stuff
+# A/other
+# In words:
+# A: delete A/file1_1, rename B/file1_2 -> C/file1_2
+# B: Rename C/ -> A/, rename A/file1_1 -> D/file2_1
+# Rationale:
+# A/stuff is unmodified, it shows up in final output
+# B/stuff is unmodified, it shows up in final output
+# C/other touched on one side (rename to A), so A/other shows up in output
+# A/file1 is rename/delete to D/file2, so two stages for D/file2
+# B/file1 -> C/file1 and even though C/ -> A/, A/file1 as a source was
+# "in the way" (ish) so we don't do the directory rename
+# Expected: A/stuff
+# B/stuff
+# A/other
+# D/file2 (two stages)
+# C/file1
+# + CONFLICT (implicit dir rename): A/file1 in way of C/file1
+# + CONFLICT (rename/delete): D/file2
+#
+
+test_setup_12q () {
+ git init 12q &&
+ (
+ cd 12q &&
+
+ mkdir -p A B C &&
+ echo 1 >A/file1 &&
+ echo 2 >B/file1 &&
+ echo other >C/other &&
+ echo Astuff >A/stuff &&
+ echo Bstuff >B/stuff &&
+ git add . &&
+ git commit -m "O" &&
+
+ git branch O &&
+ git branch A &&
+ git branch B &&
+
+ git switch A &&
+ git rm A/file1 &&
+ git mv B/file1 C/ &&
+ git add . &&
+ git commit -m "A" &&
+
+ git switch B &&
+ mkdir -p D &&
+ git mv A/file1 D/file2 &&
+ git mv C/other A/other &&
+ git add . &&
+ git commit -m "B"
+ )
+}
+
+test_expect_success '12q: Directory rename hits other rename source; file removed though' '
+ test_setup_12q &&
+ (
+ cd 12q &&
+
+ git checkout -q A^0 &&
+
+ test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 >out &&
+
+ grep "CONFLICT (rename/delete).*A/file1.*D/file2" out &&
+ grep "CONFLICT (implicit dir rename).*Existing file/dir at A/file1 in the way" out &&
+
+ test_stdout_line_count = 6 git ls-files -s &&
+ test_stdout_line_count = 1 git ls-files -s A/other &&
+ test_stdout_line_count = 1 git ls-files -s A/stuff &&
+ test_stdout_line_count = 1 git ls-files -s B/stuff &&
+ test_stdout_line_count = 2 git ls-files -s D/file2 &&
+
+ # This is a slightly suboptimal resolution; allowing the
+ # rename of C/ -> A/ to affect C/file1 and further rename
+ # it to A/file1 would probably be preferable, but since
+ # A/file1 existed as the source of another rename, allowing
+ # the dir rename of C/file1 -> A/file1 would mean modifying
+ # the code so that renames do not adjust both their source
+ # and target paths in all cases.
+ ! grep "CONFLICT (file location)" out &&
+ test_stdout_line_count = 1 git ls-files -s C/file1
+ )
+'
+
###########################################################################
# SECTION 13: Checking informational and conflict messages
#
@@ -5546,9 +5772,9 @@ test_expect_success '13b(info): messages for transitive rename with conflicted c
# Commit A: y/{b,c,d}, x/e
# Commit B: z/{b,c,d}, x/e
# Expected: y/{b,c,d}, x/e, with info or conflict messages for d
-# A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
-# One could argue A had partial knowledge of what was done with
-# d and B had full knowledge, but that's a slippery slope as
+# B: renamed x/d -> z/d; A: renamed z/ -> y/ AND renamed x/d to y/d
+# One could argue B had partial knowledge of what was done with
+# d and A had full knowledge, but that's a slippery slope as
# shown in testcase 13d.
test_setup_13c () {
diff --git a/t/t6424-merge-unrelated-index-changes.sh b/t/t6424-merge-unrelated-index-changes.sh
index 7677c5f08d..ddc7524f6c 100755
--- a/t/t6424-merge-unrelated-index-changes.sh
+++ b/t/t6424-merge-unrelated-index-changes.sh
@@ -176,9 +176,11 @@ test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
# Make index match B
git diff C B -- | git apply --cached &&
test_when_finished "git clean -fd" && # Do not leave untracked around
+ git write-tree >index-before &&
# Merge B & F, with B as "head"
git merge-recursive A -- B F > out &&
- test_grep "Already up to date" out
+ git write-tree >index-after &&
+ test_cmp index-before index-after
'
test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
@@ -294,10 +296,8 @@ test_expect_success 'with multiple strategies, recursive or ort failure do not e
git add a &&
git rev-parse :a >expect &&
- sane_unset GIT_TEST_MERGE_ALGORITHM &&
- test_must_fail git merge -s recursive -s ort -s octopus C^0 >output 2>&1 &&
+ test_must_fail git merge -s ort -s octopus C^0 >output 2>&1 &&
- grep "Trying merge strategy recursive..." output &&
grep "Trying merge strategy ort..." output &&
grep "Trying merge strategy octopus..." output &&
grep "No merge strategy handled the merge." output &&
diff --git a/t/t6426-merge-skip-unneeded-updates.sh b/t/t6426-merge-skip-unneeded-updates.sh
index b059475ed0..404cd3f2ca 100755
--- a/t/t6426-merge-skip-unneeded-updates.sh
+++ b/t/t6426-merge-skip-unneeded-updates.sh
@@ -23,8 +23,6 @@ test_description="merge cases"
# files that might be renamed into each other's paths.)
. ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-merge.sh
-
###########################################################################
# SECTION 1: Cases involving no renames (one side has subset of changes of
@@ -663,7 +661,7 @@ test_setup_4a () {
# correct requires doing the merge in-memory first, then realizing that no
# updates to the file are necessary, and thus that we can just leave the path
# alone.
-test_expect_merge_algorithm failure success '4a: Change on A, change on B subset of A, dirty mods present' '
+test_expect_success '4a: Change on A, change on B subset of A, dirty mods present' '
test_setup_4a &&
(
cd 4a &&
diff --git a/t/t6427-diff3-conflict-markers.sh b/t/t6427-diff3-conflict-markers.sh
index dd5fe6a402..57569c4f4b 100755
--- a/t/t6427-diff3-conflict-markers.sh
+++ b/t/t6427-diff3-conflict-markers.sh
@@ -207,7 +207,7 @@ test_expect_success 'rebase --apply describes fake ancestor base' '
cd rebase &&
git rebase --abort &&
test_must_fail git -c merge.conflictstyle=diff3 rebase --apply main &&
- grep "||||||| constructed merge base" file
+ grep "||||||| constructed fake ancestor" file
)
'
diff --git a/t/t6428-merge-conflicts-sparse.sh b/t/t6428-merge-conflicts-sparse.sh
index 9919c3fa7c..c86e02c6e2 100755
--- a/t/t6428-merge-conflicts-sparse.sh
+++ b/t/t6428-merge-conflicts-sparse.sh
@@ -23,8 +23,6 @@ test_description="merge cases"
# files that might be renamed into each other's paths.)
. ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-merge.sh
-
# Testcase basic, conflicting changes in 'numerals'
diff --git a/t/t6430-merge-recursive.sh b/t/t6430-merge-recursive.sh
index ca15e6dd6d..e59560a5dd 100755
--- a/t/t6430-merge-recursive.sh
+++ b/t/t6430-merge-recursive.sh
@@ -6,7 +6,6 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-merge.sh
test_expect_success 'setup 1' '
@@ -373,9 +372,9 @@ test_expect_success 'merge-recursive d/f conflict result' '
git ls-files -s >actual &&
(
- echo "100644 $o0 1 a" &&
- echo "100644 $o1 2 a" &&
echo "100644 $o4 0 a/c" &&
+ echo "100644 $o0 1 a~$c1" &&
+ echo "100644 $o1 2 a~$c1" &&
echo "100644 $o0 0 b" &&
echo "100644 $o0 0 c" &&
echo "100644 $o1 0 d/e"
@@ -397,9 +396,9 @@ test_expect_success 'merge-recursive d/f conflict result the other way' '
git ls-files -s >actual &&
(
- echo "100644 $o0 1 a" &&
- echo "100644 $o1 3 a" &&
echo "100644 $o4 0 a/c" &&
+ echo "100644 $o0 1 a~$c1" &&
+ echo "100644 $o1 3 a~$c1" &&
echo "100644 $o0 0 b" &&
echo "100644 $o0 0 c" &&
echo "100644 $o1 0 d/e"
@@ -424,9 +423,9 @@ test_expect_success 'merge-recursive d/f conflict result' '
echo "100644 $o1 0 a" &&
echo "100644 $o0 0 b" &&
echo "100644 $o0 0 c" &&
- echo "100644 $o6 3 d" &&
echo "100644 $o0 1 d/e" &&
- echo "100644 $o1 2 d/e"
+ echo "100644 $o1 2 d/e" &&
+ echo "100644 $o6 3 d~$c6"
) >expected &&
test_cmp expected actual
@@ -448,9 +447,9 @@ test_expect_success 'merge-recursive d/f conflict result' '
echo "100644 $o1 0 a" &&
echo "100644 $o0 0 b" &&
echo "100644 $o0 0 c" &&
- echo "100644 $o6 2 d" &&
echo "100644 $o0 1 d/e" &&
- echo "100644 $o1 3 d/e"
+ echo "100644 $o1 3 d/e" &&
+ echo "100644 $o6 2 d~$c6"
) >expected &&
test_cmp expected actual
@@ -645,7 +644,7 @@ test_expect_success 'merge-recursive copy vs. rename' '
test_cmp expected actual
'
-test_expect_merge_algorithm failure success 'merge-recursive rename vs. rename/symlink' '
+test_expect_success 'merge-recursive rename vs. rename/symlink' '
git checkout -f rename &&
git merge rename-ln &&
@@ -696,33 +695,6 @@ test_expect_success 'merging with triple rename across D/F conflict' '
git merge other
'
-test_expect_success 'merge-recursive remembers the names of all base trees' '
- git reset --hard HEAD &&
-
- # make the index match $c1 so that merge-recursive below does not
- # fail early
- git diff --binary HEAD $c1 -- | git apply --cached &&
-
- # more trees than static slots used by oid_to_hex()
- for commit in $c0 $c2 $c4 $c5 $c6 $c7
- do
- git rev-parse "$commit^{tree}" || return 1
- done >trees &&
-
- # ignore the return code; it only fails because the input is weird...
- test_must_fail git -c merge.verbosity=5 merge-recursive $(cat trees) -- $c1 $c3 >out &&
-
- # ...but make sure it fails in the expected way
- test_grep CONFLICT.*rename/rename out &&
-
- # merge-recursive prints in reverse order, but we do not care
- sort <trees >expect &&
- sed -n "s/^virtual //p" out | sort >actual &&
- test_cmp expect actual &&
-
- git clean -fd
-'
-
test_expect_success 'merge-recursive internal merge resolves to the sameness' '
git reset --hard HEAD &&
diff --git a/t/t6434-merge-recursive-rename-options.sh b/t/t6434-merge-recursive-rename-options.sh
index a11707835b..5a6f74839c 100755
--- a/t/t6434-merge-recursive-rename-options.sh
+++ b/t/t6434-merge-recursive-rename-options.sh
@@ -22,7 +22,7 @@ R075 2-old 2-new
R100 3-old 3-new
Actual similarity indices are parsed from diff output. We rely on the fact that
-they are rounded down (see, e.g., Documentation/diff-generate-patch.txt, which
+they are rounded down (see, e.g., Documentation/diff-generate-patch.adoc, which
mentions this in a different context).
'
@@ -34,7 +34,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
get_expected_stages () {
git checkout rename -- $1-new &&
git ls-files --stage $1-new >expected-stages-undetected-$1 &&
- sed "s/ 0 / 2 /" <expected-stages-undetected-$1 \
+ git ls-tree HEAD^ $1-old >tmp &&
+ git ls-tree HEAD $1-new >>tmp &&
+ cat tmp | awk '{print $1 " " $3 " " NR "\t" '$1'"-new"}' \
>expected-stages-detected-$1 &&
git read-tree -u --reset HEAD
}
@@ -51,11 +53,11 @@ rename_undetected () {
check_common () {
git ls-files --stage >stages-actual &&
- test_line_count = 4 stages-actual
+ test_line_count = $1 stages-actual
}
check_threshold_0 () {
- check_common &&
+ check_common 8 &&
rename_detected 0 &&
rename_detected 1 &&
rename_detected 2 &&
@@ -63,7 +65,7 @@ check_threshold_0 () {
}
check_threshold_1 () {
- check_common &&
+ check_common 7 &&
rename_undetected 0 &&
rename_detected 1 &&
rename_detected 2 &&
@@ -71,7 +73,7 @@ check_threshold_1 () {
}
check_threshold_2 () {
- check_common &&
+ check_common 6 &&
rename_undetected 0 &&
rename_undetected 1 &&
rename_detected 2 &&
@@ -79,7 +81,7 @@ check_threshold_2 () {
}
check_exact_renames () {
- check_common &&
+ check_common 5 &&
rename_undetected 0 &&
rename_undetected 1 &&
rename_undetected 2 &&
@@ -87,7 +89,7 @@ check_exact_renames () {
}
check_no_renames () {
- check_common &&
+ check_common 4 &&
rename_undetected 0 &&
rename_undetected 1 &&
rename_undetected 2 &&
diff --git a/t/t6436-merge-overwrite.sh b/t/t6436-merge-overwrite.sh
index 4f4376421e..70b5d2d694 100755
--- a/t/t6436-merge-overwrite.sh
+++ b/t/t6436-merge-overwrite.sh
@@ -101,19 +101,10 @@ test_expect_success 'will not overwrite unstaged changes in renamed file' '
git mv c1.c other.c &&
git commit -m rename &&
cp important other.c &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git merge c1a >out 2>err &&
- test_grep "would be overwritten by merge" err &&
- test_cmp important other.c &&
- test_path_is_missing .git/MERGE_HEAD
- else
- test_must_fail git merge c1a >out &&
- test_grep "Refusing to lose dirty file at other.c" out &&
- test_path_is_file other.c~HEAD &&
- test $(git hash-object other.c~HEAD) = $(git rev-parse c1a:c1.c) &&
- test_cmp important other.c
- fi
+ test_must_fail git merge c1a >out 2>err &&
+ test_grep "would be overwritten by merge" err &&
+ test_cmp important other.c &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'will not overwrite untracked subtree' '
diff --git a/t/t6437-submodule-merge.sh b/t/t6437-submodule-merge.sh
index 4815559157..a564758f52 100755
--- a/t/t6437-submodule-merge.sh
+++ b/t/t6437-submodule-merge.sh
@@ -9,7 +9,6 @@ GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
. ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-merge.sh
#
# history
@@ -110,14 +109,10 @@ test_expect_success 'merging should conflict for non fast-forward' '
test_when_finished "git -C merge-search reset --hard" &&
(cd merge-search &&
git checkout -b test-nonforward-a b &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git merge c 2>actual &&
- sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
- grep "$sub_expect" actual
- else
- test_must_fail git merge c 2> actual
- fi)
+ test_must_fail git merge c 2>actual &&
+ sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
+ grep "$sub_expect" actual
+ )
'
test_expect_success 'finish setup for merge-search' '
@@ -151,14 +146,9 @@ test_expect_success 'merging should conflict for non fast-forward (resolution ex
git checkout -b test-nonforward-b b &&
(cd sub &&
git rev-parse --short sub-d > ../expect) &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git merge c >actual 2>sub-actual &&
- sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
- grep "$sub_expect" sub-actual
- else
- test_must_fail git merge c 2> actual
- fi &&
+ test_must_fail git merge c >actual 2>sub-actual &&
+ sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
+ grep "$sub_expect" sub-actual &&
grep $(cat expect) actual > /dev/null &&
git reset --hard)
'
@@ -169,23 +159,12 @@ test_expect_success 'merging should fail for ambiguous common parent' '
(cd sub &&
git checkout -b ambiguous sub-b &&
git merge sub-c &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- git rev-parse --short sub-d >../expect1 &&
- git rev-parse --short ambiguous >../expect2
- else
- git rev-parse sub-d > ../expect1 &&
- git rev-parse ambiguous > ../expect2
- fi
+ git rev-parse --short sub-d >../expect1 &&
+ git rev-parse --short ambiguous >../expect2
) &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- test_must_fail git merge c >actual 2>sub-actual &&
- sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
- grep "$sub_expect" sub-actual
- else
- test_must_fail git merge c 2> actual
- fi &&
+ test_must_fail git merge c >actual 2>sub-actual &&
+ sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-c)" &&
+ grep "$sub_expect" sub-actual &&
grep $(cat expect1) actual > /dev/null &&
grep $(cat expect2) actual > /dev/null &&
git reset --hard)
@@ -227,11 +206,9 @@ test_expect_success 'merging should fail for changes that are backwards' '
git checkout -b test-backward e &&
test_must_fail git merge f 2>actual &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-d)" &&
- grep "$sub_expect" actual
- fi)
+ sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short sub-d)" &&
+ grep "$sub_expect" actual
+ )
'
@@ -358,7 +335,7 @@ test_expect_success 'setup file/submodule conflict' '
)
'
-test_expect_merge_algorithm failure success 'file/submodule conflict' '
+test_expect_success 'file/submodule conflict' '
test_when_finished "git -C file-submodule reset --hard" &&
(
cd file-submodule &&
@@ -467,7 +444,7 @@ test_expect_failure 'directory/submodule conflict; keep submodule clean' '
)
'
-test_expect_merge_algorithm failure success !FAIL_PREREQS 'directory/submodule conflict; should not treat submodule files as untracked or in the way' '
+test_expect_success !FAIL_PREREQS 'directory/submodule conflict; should not treat submodule files as untracked or in the way' '
test_when_finished "git -C directory-submodule/path reset --hard" &&
test_when_finished "git -C directory-submodule reset --hard" &&
(
@@ -535,11 +512,9 @@ test_expect_success 'merging should fail with no merge base' '
git add sub &&
git commit -m "b" &&
test_must_fail git merge a 2>actual &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short HEAD^1)" &&
- grep "$sub_expect" actual
- fi)
+ sub_expect="go to submodule (sub), and either merge commit $(git -C sub rev-parse --short HEAD^1)" &&
+ grep "$sub_expect" actual
+ )
'
test_done
diff --git a/t/t6438-submodule-directory-file-conflicts.sh b/t/t6438-submodule-directory-file-conflicts.sh
index 8df67a0ef9..53d83c828a 100755
--- a/t/t6438-submodule-directory-file-conflicts.sh
+++ b/t/t6438-submodule-directory-file-conflicts.sh
@@ -12,11 +12,6 @@ test_submodule_switch "merge --ff"
test_submodule_switch "merge --ff-only"
-if test "$GIT_TEST_MERGE_ALGORITHM" != ort
-then
- KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
- KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
-fi
test_submodule_switch "merge --no-ff"
test_done
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 55bd744a3f..643c9368e0 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -47,7 +47,7 @@ test_expect_success 'untracked files overwritten by merge (fast and non-fast for
export GIT_MERGE_VERBOSITY &&
test_must_fail git merge branch 2>out2
) &&
- echo "Merge with strategy ${GIT_TEST_MERGE_ALGORITHM:-ort} failed." >>expect &&
+ echo "Merge with strategy ort failed." >>expect &&
test_cmp out2 expect &&
git reset --hard HEAD^
'
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index 5378455968..bef472cb8d 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -338,6 +338,39 @@ test_expect_success 'gc.maxCruftSize sets appropriate repack options' '
test_subcommand $cruft_max_size_opts --max-cruft-size=3145728 <trace2.txt
'
+test_expect_success '--expire-to sets repack --expire-to' '
+ rm -rf expired &&
+ mkdir expired &&
+ expire_to="$(pwd)/expired/pack" &&
+ GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --cruft --expire-to="$expire_to" &&
+ test_subcommand $cruft_max_size_opts --expire-to="$expire_to" <trace2.txt
+'
+
+test_expect_success '--expire-to with --prune=now sets repack --expire-to' '
+ rm -rf expired &&
+ mkdir expired &&
+ expire_to="$(pwd)/expired/pack" &&
+ GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --cruft --prune=now --expire-to="$expire_to" &&
+ test_subcommand git repack -d -l --cruft --cruft-expiration=now --expire-to="$expire_to" <trace2.txt
+'
+
+
+test_expect_success '--expire-to with --no-cruft sets repack -A' '
+ rm -rf expired &&
+ mkdir expired &&
+ expire_to="$(pwd)/expired/pack" &&
+ GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --no-cruft --expire-to="$expire_to" &&
+ test_subcommand git repack -d -l -A --unpack-unreachable=2.weeks.ago <trace2.txt
+'
+
+test_expect_success '--expire-to with --no-cruft sets repack -a' '
+ rm -rf expired &&
+ mkdir expired &&
+ expire_to="$(pwd)/expired/pack" &&
+ GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size gc --no-cruft --prune=now --expire-to="$expire_to" &&
+ test_subcommand git repack -d -l -a <trace2.txt
+'
+
run_and_wait_for_gc () {
# We read stdout from gc for the side effect of waiting until the
# background gc process exits, closing its fd 9. Furthermore, the
diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh
index 2591f8b8b3..6638d1aa1d 100755
--- a/t/t6600-test-reach.sh
+++ b/t/t6600-test-reach.sh
@@ -733,4 +733,33 @@ test_expect_success 'for-each-ref is-base:multiple' '
--format="%(refname)[%(is-base:commit-2-3)-%(is-base:commit-6-5)]" --stdin
'
+test_expect_success 'for-each-ref is-base: --sort' '
+ cat >input <<-\EOF &&
+ refs/heads/commit-1-1
+ refs/heads/commit-4-2
+ refs/heads/commit-4-4
+ refs/heads/commit-8-4
+ EOF
+
+ cat >expect <<-\EOF &&
+ refs/heads/commit-1-1
+ refs/heads/commit-4-4
+ refs/heads/commit-8-4
+ refs/heads/commit-4-2
+ EOF
+ run_all_modes git for-each-ref \
+ --format="%(refname)" --stdin \
+ --sort=refname --sort=is-base:commit-2-3 &&
+
+ cat >expect <<-\EOF &&
+ refs/heads/commit-4-2
+ refs/heads/commit-1-1
+ refs/heads/commit-4-4
+ refs/heads/commit-8-4
+ EOF
+ run_all_modes git for-each-ref \
+ --format="%(refname)" --stdin \
+ --sort=refname --sort=-is-base:commit-2-3
+'
+
test_done
diff --git a/t/t6601-path-walk.sh b/t/t6601-path-walk.sh
new file mode 100755
index 0000000000..56bd1e3c5b
--- /dev/null
+++ b/t/t6601-path-walk.sh
@@ -0,0 +1,418 @@
+#!/bin/sh
+
+test_description='direct path-walk API tests'
+
+. ./test-lib.sh
+
+test_expect_success 'setup test repository' '
+ git checkout -b base &&
+
+ # Make some objects that will only be reachable
+ # via non-commit tags.
+ mkdir child &&
+ echo file >child/file &&
+ git add child &&
+ git commit -m "will abandon" &&
+ git tag -a -m "tree" tree-tag HEAD^{tree} &&
+ echo file2 >file2 &&
+ git add file2 &&
+ git commit --amend -m "will abandon" &&
+ git tag tree-tag2 HEAD^{tree} &&
+
+ echo blob >file &&
+ blob_oid=$(git hash-object -t blob -w --stdin <file) &&
+ git tag -a -m "blob" blob-tag "$blob_oid" &&
+ echo blob2 >file2 &&
+ blob2_oid=$(git hash-object -t blob -w --stdin <file2) &&
+ git tag blob-tag2 "$blob2_oid" &&
+
+ rm -fr child file file2 &&
+
+ mkdir left &&
+ mkdir right &&
+ echo a >a &&
+ echo b >left/b &&
+ echo c >right/c &&
+ git add . &&
+ git commit --amend -m "first" &&
+ git tag -m "first" first HEAD &&
+
+ echo d >right/d &&
+ git add right &&
+ git commit -m "second" &&
+ git tag -a -m "second (under)" second.1 HEAD &&
+ git tag -a -m "second (top)" second.2 second.1 &&
+
+ # Set up file/dir collision in history.
+ rm a &&
+ mkdir a &&
+ echo a >a/a &&
+ echo bb >left/b &&
+ git add a left &&
+ git commit -m "third" &&
+ git tag -a -m "third" third &&
+
+ git checkout -b topic HEAD~1 &&
+ echo cc >right/c &&
+ git commit -a -m "topic" &&
+ git tag -a -m "fourth" fourth
+'
+
+test_expect_success 'all' '
+ test-tool path-walk -- --all >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base)
+ 0:commit::$(git rev-parse base~1)
+ 0:commit::$(git rev-parse base~2)
+ 1:tag:/tags:$(git rev-parse refs/tags/first)
+ 1:tag:/tags:$(git rev-parse refs/tags/second.1)
+ 1:tag:/tags:$(git rev-parse refs/tags/second.2)
+ 1:tag:/tags:$(git rev-parse refs/tags/third)
+ 1:tag:/tags:$(git rev-parse refs/tags/fourth)
+ 1:tag:/tags:$(git rev-parse refs/tags/tree-tag)
+ 1:tag:/tags:$(git rev-parse refs/tags/blob-tag)
+ 2:blob:/tagged-blobs:$(git rev-parse refs/tags/blob-tag^{})
+ 2:blob:/tagged-blobs:$(git rev-parse refs/tags/blob-tag2^{})
+ 3:tree::$(git rev-parse topic^{tree})
+ 3:tree::$(git rev-parse base^{tree})
+ 3:tree::$(git rev-parse base~1^{tree})
+ 3:tree::$(git rev-parse base~2^{tree})
+ 3:tree::$(git rev-parse refs/tags/tree-tag^{})
+ 3:tree::$(git rev-parse refs/tags/tree-tag2^{})
+ 4:blob:a:$(git rev-parse base~2:a)
+ 5:blob:file2:$(git rev-parse refs/tags/tree-tag2^{}:file2)
+ 6:tree:a/:$(git rev-parse base:a)
+ 7:tree:child/:$(git rev-parse refs/tags/tree-tag:child)
+ 8:blob:child/file:$(git rev-parse refs/tags/tree-tag:child/file)
+ 9:tree:left/:$(git rev-parse base:left)
+ 9:tree:left/:$(git rev-parse base~2:left)
+ 10:blob:left/b:$(git rev-parse base~2:left/b)
+ 10:blob:left/b:$(git rev-parse base:left/b)
+ 11:tree:right/:$(git rev-parse topic:right)
+ 11:tree:right/:$(git rev-parse base~1:right)
+ 11:tree:right/:$(git rev-parse base~2:right)
+ 12:blob:right/c:$(git rev-parse base~2:right/c)
+ 12:blob:right/c:$(git rev-parse topic:right/c)
+ 13:blob:right/d:$(git rev-parse base~1:right/d)
+ blobs:10
+ commits:4
+ tags:7
+ trees:13
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'indexed objects' '
+ test_when_finished git reset --hard &&
+
+ # stage change into index, adding a blob but
+ # also invalidating the cache-tree for the root
+ # and the "left" directory.
+ echo bogus >left/c &&
+ git add left &&
+
+ test-tool path-walk -- --indexed-objects >out &&
+
+ cat >expect <<-EOF &&
+ 0:blob:a:$(git rev-parse HEAD:a)
+ 1:blob:left/b:$(git rev-parse HEAD:left/b)
+ 2:blob:left/c:$(git rev-parse :left/c)
+ 3:blob:right/c:$(git rev-parse HEAD:right/c)
+ 4:blob:right/d:$(git rev-parse HEAD:right/d)
+ 5:tree:right/:$(git rev-parse topic:right)
+ blobs:5
+ commits:0
+ tags:0
+ trees:1
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'branches and indexed objects mix well' '
+ test_when_finished git reset --hard &&
+
+ # stage change into index, adding a blob but
+ # also invalidating the cache-tree for the root
+ # and the "right" directory.
+ echo fake >right/d &&
+ git add right &&
+
+ test-tool path-walk -- --indexed-objects --branches >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base)
+ 0:commit::$(git rev-parse base~1)
+ 0:commit::$(git rev-parse base~2)
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base^{tree})
+ 1:tree::$(git rev-parse base~1^{tree})
+ 1:tree::$(git rev-parse base~2^{tree})
+ 2:tree:a/:$(git rev-parse refs/tags/third:a)
+ 3:tree:left/:$(git rev-parse base:left)
+ 3:tree:left/:$(git rev-parse base~2:left)
+ 4:blob:left/b:$(git rev-parse base:left/b)
+ 4:blob:left/b:$(git rev-parse base~2:left/b)
+ 5:tree:right/:$(git rev-parse topic:right)
+ 5:tree:right/:$(git rev-parse base~1:right)
+ 5:tree:right/:$(git rev-parse base~2:right)
+ 6:blob:right/c:$(git rev-parse base~2:right/c)
+ 6:blob:right/c:$(git rev-parse topic:right/c)
+ 7:blob:right/d:$(git rev-parse base~1:right/d)
+ 7:blob:right/d:$(git rev-parse :right/d)
+ 8:blob:a:$(git rev-parse base~2:a)
+ blobs:7
+ commits:4
+ tags:0
+ trees:10
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'base & topic, sparse' '
+ cat >patterns <<-EOF &&
+ /*
+ !/*/
+ /left/
+ EOF
+
+ test-tool path-walk --stdin-pl -- base topic <patterns >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base)
+ 0:commit::$(git rev-parse base~1)
+ 0:commit::$(git rev-parse base~2)
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base^{tree})
+ 1:tree::$(git rev-parse base~1^{tree})
+ 1:tree::$(git rev-parse base~2^{tree})
+ 2:blob:a:$(git rev-parse base~2:a)
+ 3:tree:left/:$(git rev-parse base:left)
+ 3:tree:left/:$(git rev-parse base~2:left)
+ 4:blob:left/b:$(git rev-parse base~2:left/b)
+ 4:blob:left/b:$(git rev-parse base:left/b)
+ blobs:3
+ commits:4
+ tags:0
+ trees:6
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic only' '
+ test-tool path-walk -- topic >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base~1)
+ 0:commit::$(git rev-parse base~2)
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base~1^{tree})
+ 1:tree::$(git rev-parse base~2^{tree})
+ 2:blob:a:$(git rev-parse base~2:a)
+ 3:tree:left/:$(git rev-parse base~2:left)
+ 4:blob:left/b:$(git rev-parse base~2:left/b)
+ 5:tree:right/:$(git rev-parse topic:right)
+ 5:tree:right/:$(git rev-parse base~1:right)
+ 5:tree:right/:$(git rev-parse base~2:right)
+ 6:blob:right/c:$(git rev-parse base~2:right/c)
+ 6:blob:right/c:$(git rev-parse topic:right/c)
+ 7:blob:right/d:$(git rev-parse base~1:right/d)
+ blobs:5
+ commits:3
+ tags:0
+ trees:7
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic, not base' '
+ test-tool path-walk -- topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 1:tree::$(git rev-parse topic^{tree})
+ 2:blob:a:$(git rev-parse topic:a):UNINTERESTING
+ 3:tree:left/:$(git rev-parse topic:left):UNINTERESTING
+ 4:blob:left/b:$(git rev-parse topic:left/b):UNINTERESTING
+ 5:tree:right/:$(git rev-parse topic:right)
+ 6:blob:right/c:$(git rev-parse topic:right/c)
+ 7:blob:right/d:$(git rev-parse topic:right/d):UNINTERESTING
+ blobs:4
+ commits:1
+ tags:0
+ trees:3
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'fourth, blob-tag2, not base' '
+ test-tool path-walk -- fourth blob-tag2 --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 1:tag:/tags:$(git rev-parse fourth)
+ 2:blob:/tagged-blobs:$(git rev-parse refs/tags/blob-tag2^{})
+ 3:tree::$(git rev-parse topic^{tree})
+ 4:blob:a:$(git rev-parse base~1:a):UNINTERESTING
+ 5:tree:left/:$(git rev-parse base~1:left):UNINTERESTING
+ 6:blob:left/b:$(git rev-parse base~1:left/b):UNINTERESTING
+ 7:tree:right/:$(git rev-parse topic:right)
+ 8:blob:right/c:$(git rev-parse topic:right/c)
+ 9:blob:right/d:$(git rev-parse base~1:right/d):UNINTERESTING
+ blobs:5
+ commits:1
+ tags:1
+ trees:3
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic, not base, only blobs' '
+ test-tool path-walk --no-trees --no-commits \
+ -- topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:blob:a:$(git rev-parse topic:a):UNINTERESTING
+ 1:blob:left/b:$(git rev-parse topic:left/b):UNINTERESTING
+ 2:blob:right/c:$(git rev-parse topic:right/c)
+ 3:blob:right/d:$(git rev-parse topic:right/d):UNINTERESTING
+ blobs:4
+ commits:0
+ tags:0
+ trees:0
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+# No, this doesn't make a lot of sense for the path-walk API,
+# but it is possible to do.
+test_expect_success 'topic, not base, only commits' '
+ test-tool path-walk --no-blobs --no-trees \
+ -- topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ commits:1
+ blobs:0
+ tags:0
+ trees:0
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic, not base, only trees' '
+ test-tool path-walk --no-blobs --no-commits \
+ -- topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:tree::$(git rev-parse topic^{tree})
+ 1:tree:left/:$(git rev-parse topic:left):UNINTERESTING
+ 2:tree:right/:$(git rev-parse topic:right)
+ commits:0
+ blobs:0
+ tags:0
+ trees:3
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic, not base, boundary' '
+ test-tool path-walk -- --boundary topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base~1):UNINTERESTING
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base~1^{tree}):UNINTERESTING
+ 2:blob:a:$(git rev-parse base~1:a):UNINTERESTING
+ 3:tree:left/:$(git rev-parse base~1:left):UNINTERESTING
+ 4:blob:left/b:$(git rev-parse base~1:left/b):UNINTERESTING
+ 5:tree:right/:$(git rev-parse topic:right)
+ 5:tree:right/:$(git rev-parse base~1:right):UNINTERESTING
+ 6:blob:right/c:$(git rev-parse base~1:right/c):UNINTERESTING
+ 6:blob:right/c:$(git rev-parse topic:right/c)
+ 7:blob:right/d:$(git rev-parse base~1:right/d):UNINTERESTING
+ blobs:5
+ commits:2
+ tags:0
+ trees:5
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic, not base, boundary with pruning' '
+ test-tool path-walk --prune -- --boundary topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base~1):UNINTERESTING
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base~1^{tree}):UNINTERESTING
+ 2:tree:right/:$(git rev-parse topic:right)
+ 2:tree:right/:$(git rev-parse base~1:right):UNINTERESTING
+ 3:blob:right/c:$(git rev-parse base~1:right/c):UNINTERESTING
+ 3:blob:right/c:$(git rev-parse topic:right/c)
+ blobs:2
+ commits:2
+ tags:0
+ trees:4
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic, not base, --edge-aggressive with pruning' '
+ test-tool path-walk --prune --edge-aggressive -- topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base^{tree}):UNINTERESTING
+ 2:tree:right/:$(git rev-parse topic:right)
+ 2:tree:right/:$(git rev-parse base:right):UNINTERESTING
+ 3:blob:right/c:$(git rev-parse base:right/c):UNINTERESTING
+ 3:blob:right/c:$(git rev-parse topic:right/c)
+ blobs:2
+ commits:1
+ tags:0
+ trees:4
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'trees are reported exactly once' '
+ test_when_finished "rm -rf unique-trees" &&
+ test_create_repo unique-trees &&
+ (
+ cd unique-trees &&
+ mkdir initial &&
+ test_commit initial/file &&
+ git switch -c move-to-top &&
+ git mv initial/file.t ./ &&
+ test_tick &&
+ git commit -m moved &&
+ git update-ref refs/heads/other HEAD
+ ) &&
+ test-tool -C unique-trees path-walk -- --all >out &&
+ tree=$(git -C unique-trees rev-parse HEAD:) &&
+ grep "$tree" out >out-filtered &&
+ test_line_count = 1 out-filtered
+'
+
+test_done
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 25334b5062..920479e925 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -550,16 +550,32 @@ test_expect_success 'moving nested submodules' '
git status
'
-test_expect_failure 'nonsense mv triggers assertion failure and partially updated index' '
+test_expect_success 'moving file and its parent directory at the same time fails' '
test_when_finished git reset --hard HEAD &&
git reset --hard HEAD &&
mkdir -p a &&
mkdir -p b &&
>a/a.txt &&
git add a/a.txt &&
- test_must_fail git mv a/a.txt a b &&
- git status --porcelain >actual &&
- grep "^A[ ]*a/a.txt$" actual
+ cat >expect <<-EOF &&
+ fatal: cannot move both ${SQ}a/a.txt${SQ} and its parent directory ${SQ}a${SQ}
+ EOF
+ test_must_fail git mv a/a.txt a b 2>err &&
+ test_cmp expect err
+'
+
+test_expect_success 'moving nested directory and its parent directory at the same time fails' '
+ test_when_finished git reset --hard HEAD &&
+ git reset --hard HEAD &&
+ mkdir -p a/b/c &&
+ >a/b/c/file.txt &&
+ git add a &&
+ mkdir target &&
+ cat >expect <<-EOF &&
+ fatal: cannot move both ${SQ}a/b/c${SQ} and its parent directory ${SQ}a${SQ}
+ EOF
+ test_must_fail git mv a/b/c a target 2>err &&
+ test_cmp expect err
'
test_done
diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh
index 5fcf281dfb..c490e5707a 100755
--- a/t/t7005-editor.sh
+++ b/t/t7005-editor.sh
@@ -7,125 +7,96 @@ test_description='GIT_EDITOR, core.editor, and stuff'
unset EDITOR VISUAL GIT_EDITOR
test_expect_success 'determine default editor' '
-
vi=$(TERM=vt100 git var GIT_EDITOR) &&
test -n "$vi"
-
'
-if ! expr "$vi" : '[a-z]*$' >/dev/null
-then
- vi=
-fi
-
-for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
-do
- cat >e-$i.sh <<-EOF
- #!$SHELL_PATH
- echo "Edited by $i" >"\$1"
- EOF
- chmod +x e-$i.sh
-done
+test_expect_success setup '
+ if ! expr "$vi" : "[a-z]*$" >/dev/null
+ then
+ vi=
+ fi &&
-if ! test -z "$vi"
-then
- mv e-$vi.sh $vi
-fi
+ for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
+ do
+ write_script e-$i.sh <<-EOF || return 1
+ echo "Edited by $i" >"\$1"
+ EOF
+ done &&
-test_expect_success setup '
+ if ! test -z "$vi"
+ then
+ mv e-$vi.sh $vi
+ fi &&
msg="Hand-edited" &&
test_commit "$msg" &&
- echo "$msg" >expect &&
- git show -s --format=%s > actual &&
- test_cmp expect actual
-
+ test_commit_message HEAD -m "$msg"
'
-TERM=dumb
-export TERM
test_expect_success 'dumb should error out when falling back on vi' '
-
- if git commit --amend
- then
- echo "Oops?"
- false
- else
- : happy
- fi
+ test_must_fail env TERM=dumb git commit --amend
'
test_expect_success 'dumb should prefer EDITOR to VISUAL' '
-
- EDITOR=./e-EDITOR.sh &&
- VISUAL=./e-VISUAL.sh &&
- export EDITOR VISUAL &&
- git commit --amend &&
- test "$(git show -s --format=%s)" = "Edited by EDITOR"
-
+ TERM=dumb EDITOR=./e-EDITOR.sh VISUAL=./e-VISUAL.sh \
+ git commit --amend &&
+ test_commit_message HEAD -m "Edited by EDITOR"
'
-TERM=vt100
-export TERM
for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
do
- echo "Edited by $i" >expect
- unset EDITOR VISUAL GIT_EDITOR
- git config --unset-all core.editor
- case "$i" in
- core_editor)
- git config core.editor ./e-core_editor.sh
- ;;
- [A-Z]*)
- eval "$i=./e-$i.sh"
- export $i
- ;;
- esac
test_expect_success "Using $i" '
- git --exec-path=. commit --amend &&
- git show -s --pretty=oneline |
- sed -e "s/^[0-9a-f]* //" >actual &&
- test_cmp expect actual
+ if test "$i" = core_editor
+ then
+ test_config core.editor ./e-core_editor.sh
+ fi &&
+ (
+ case "$i" in
+ [A-Z]*)
+ eval "$i=./e-$i.sh" &&
+ export $i
+ ;;
+ esac &&
+ PATH="$PWD:$PATH" TERM=vt100 git commit --amend
+ ) &&
+ test_commit_message HEAD -m "Edited by $i"
'
done
-unset EDITOR VISUAL GIT_EDITOR
-git config --unset-all core.editor
-for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
-do
- echo "Edited by $i" >expect
- case "$i" in
- core_editor)
- git config core.editor ./e-core_editor.sh
- ;;
- [A-Z]*)
- eval "$i=./e-$i.sh"
- export $i
- ;;
- esac
- test_expect_success "Using $i (override)" '
- git --exec-path=. commit --amend &&
- git show -s --pretty=oneline |
- sed -e "s/^[0-9a-f]* //" >actual &&
- test_cmp expect actual
- '
-done
+test_expect_success 'Using editors with overrides' '
+ (
+ TERM=vt100 &&
+ export TERM &&
+ for i in $vi EDITOR VISUAL core_editor GIT_EDITOR
+ do
+ echo "Edited by $i" >expect &&
+ case "$i" in
+ core_editor)
+ git config core.editor ./e-core_editor.sh
+ ;;
+ [A-Z]*)
+ eval "$i=./e-$i.sh" &&
+ export $i
+ ;;
+ esac &&
+ PATH="$PWD:$PATH" git commit --amend &&
+ test_commit_message HEAD expect || exit 1
+ done
+ )
+'
test_expect_success 'editor with a space' '
echo "echo space >\"\$1\"" >"e space.sh" &&
chmod a+x "e space.sh" &&
GIT_EDITOR="./e\ space.sh" git commit --amend &&
- test space = "$(git show -s --pretty=format:%s)"
-
+ test_commit_message HEAD -m space
'
-unset GIT_EDITOR
test_expect_success 'core.editor with a space' '
-
- git config core.editor \"./e\ space.sh\" &&
+ test_config core.editor \"./e\ space.sh\" &&
git commit --amend &&
- test space = "$(git show -s --pretty=format:%s)"
-
+ test_commit_message HEAD -m space
'
test_done
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 932c26cb45..9717e825f0 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -662,9 +662,9 @@ test_expect_success 'setup trace2' '
'
test_expect_success 'setup large log output' '
- perl -e "
- print \"this is a long commit message\" x 50000
- " >commit-msg &&
+ test-tool genzeros 50000 |
+ tr "\000" "a" |
+ sed "s/a/this is a long commit message/g" >commit-msg &&
git commit --allow-empty -F commit-msg
'
diff --git a/t/t7007-show.sh b/t/t7007-show.sh
index d6cc69e0f2..2d322b53d1 100755
--- a/t/t7007-show.sh
+++ b/t/t7007-show.sh
@@ -167,4 +167,28 @@ test_expect_success 'show --graph is forbidden' '
test_must_fail git show --graph HEAD
'
+test_expect_success 'show unmerged index' '
+ git reset --hard &&
+
+ git switch -C base &&
+ echo "base" >conflicting &&
+ git add conflicting &&
+ git commit -m "base" &&
+
+ git branch hello &&
+ git branch goodbye &&
+
+ git switch hello &&
+ echo "hello" >conflicting &&
+ git commit -am "hello" &&
+
+ git switch goodbye &&
+ echo "goodbye" >conflicting &&
+ git commit -am "goodbye" &&
+
+ git switch hello &&
+ test_must_fail git merge goodbye &&
+ git show --merge HEAD
+'
+
test_done
diff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh
index 6f526c37c2..2c147072c1 100755
--- a/t/t7030-verify-tag.sh
+++ b/t/t7030-verify-tag.sh
@@ -7,6 +7,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
. "$TEST_DIRECTORY/lib-gpg.sh"
+test_expect_success GPG 'verify-tag does not crash with -h' '
+ test_expect_code 129 git verify-tag -h >usage &&
+ test_grep "[Uu]sage: git verify-tag " usage &&
+ test_expect_code 129 nongit git verify-tag -h >usage &&
+ test_grep "[Uu]sage: git verify-tag " usage
+'
+
test_expect_success GPG 'create signed tags' '
echo 1 >file && git add file &&
test_tick && git commit -m initial &&
diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh
index 61669a2d21..9a335071af 100755
--- a/t/t7110-reset-merge.sh
+++ b/t/t7110-reset-merge.sh
@@ -270,13 +270,13 @@ test_expect_success '--merge is ok with added/deleted merge' '
git reset --hard third &&
rm -f file2 &&
test_must_fail git merge branch3 &&
- ! test -f file2 &&
- test -f file3 &&
+ test_path_is_missing file2 &&
+ test_path_is_file file3 &&
git diff --exit-code file3 &&
git diff --exit-code branch3 file3 &&
git reset --merge HEAD &&
- ! test -f file3 &&
- ! test -f file2 &&
+ test_path_is_missing file3 &&
+ test_path_is_missing file2 &&
git diff --exit-code --cached
'
@@ -284,8 +284,8 @@ test_expect_success '--keep fails with added/deleted merge' '
git reset --hard third &&
rm -f file2 &&
test_must_fail git merge branch3 &&
- ! test -f file2 &&
- test -f file3 &&
+ test_path_is_missing file2 &&
+ test_path_is_file file3 &&
git diff --exit-code file3 &&
git diff --exit-code branch3 file3 &&
test_must_fail git reset --keep HEAD 2>err.log &&
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index d6a501d453..fd3e7e355e 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1482,4 +1482,27 @@ test_expect_success '`submodule init` and `init.templateDir`' '
)
'
+test_expect_success 'submodule add fails when name is reused' '
+ git init test-submodule &&
+ (
+ cd test-submodule &&
+ git commit --allow-empty -m init &&
+
+ git init ../child-origin &&
+ git -C ../child-origin commit --allow-empty -m init &&
+
+ git submodule add ../child-origin child &&
+ git commit -m "Add submodule child" &&
+
+ git mv child child_old &&
+ git commit -m "Move child to child_old" &&
+
+ # Now adding a *new* repo at the old name must fail
+ git init ../child2-origin &&
+ git -C ../child2-origin commit --allow-empty -m init &&
+ test_must_fail git submodule add ../child2-origin child 2>err &&
+ test_grep "already used for" err
+ )
+'
+
test_done
diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh
index 9c3cc4cf40..66c3ec2da2 100755
--- a/t/t7401-submodule-summary.sh
+++ b/t/t7401-submodule-summary.sh
@@ -38,10 +38,11 @@ commit_file () {
git commit "$@" -m "Commit $*" >/dev/null
}
-test_create_repo sm1 &&
-add_file . foo >/dev/null
-
-head1=$(add_file sm1 foo1 foo2)
+test_expect_success 'setup submodule' '
+ git init sm1 &&
+ add_file . foo &&
+ head1=$(add_file sm1 foo1 foo2)
+'
test_expect_success 'added submodule' "
git add sm1 &&
@@ -214,9 +215,12 @@ test_expect_success 'typechanged submodule(submodule->blob)' "
test_cmp expected actual
"
-rm -f sm1 &&
-test_create_repo sm1 &&
-head6=$(add_file sm1 foo6 foo7)
+test_expect_success 'setup submodule' '
+ rm -f sm1 &&
+ git init sm1 &&
+ head6=$(add_file sm1 foo6 foo7)
+'
+
test_expect_success 'nonexistent commit' "
git submodule summary >actual &&
cat >expected <<-EOF &&
diff --git a/t/t7402-submodule-rebase.sh b/t/t7402-submodule-rebase.sh
index 25b33a1e87..06cee3432f 100755
--- a/t/t7402-submodule-rebase.sh
+++ b/t/t7402-submodule-rebase.sh
@@ -124,11 +124,8 @@ test_expect_success 'rebasing submodule that should conflict' '
echo "160000 $(git rev-parse HEAD) 3 submodule"
) >expect &&
test_cmp expect actual &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- sub_expect="go to submodule (submodule), and either merge commit $(git -C submodule rev-parse --short HEAD^0)" &&
- grep "$sub_expect" actual_output
- fi
+ sub_expect="go to submodule (submodule), and either merge commit $(git -C submodule rev-parse --short HEAD^0)" &&
+ grep "$sub_expect" actual_output
'
test_done
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 297c6c3b5c..3adab12091 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1093,12 +1093,17 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
) &&
git clone super4 super5 &&
(cd super5 &&
- git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
+ # This test var can mess with the stderr output checked in this test.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ GIT_TEST_PACK_PATH_WALK=0 \
+ git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
test_must_be_empty out &&
test_must_be_empty err
) &&
git clone super4 super6 &&
(cd super6 &&
+ # This test variable will create a "warning" message to stderr
+ GIT_TEST_PACK_PATH_WALK=0 \
git submodule update --init --depth=1 submodule3 >out 2>err &&
test_file_not_empty out &&
test_file_not_empty err
@@ -1132,6 +1137,67 @@ test_expect_success 'setup clean recursive superproject' '
git clone --recurse-submodules top top-clean
'
+test_expect_success 'submodule update with multiple remotes' '
+ test_when_finished "rm -fr top-cloned" &&
+ cp -r top-clean top-cloned &&
+
+ # Create a commit in each repo, starting with bottom
+ test_commit -C bottom multiple_remote_commit &&
+ # Create middle commit
+ git -C middle/bottom fetch &&
+ git -C middle/bottom checkout -f FETCH_HEAD &&
+ git -C middle add bottom &&
+ git -C middle commit -m "multiple_remote_commit" &&
+ # Create top commit
+ git -C top/middle fetch &&
+ git -C top/middle checkout -f FETCH_HEAD &&
+ git -C top add middle &&
+ git -C top commit -m "multiple_remote_commit" &&
+
+ # rename the submodule remote
+ git -C top-cloned/middle remote rename origin upstream &&
+
+ # Add another remote
+ git -C top-cloned/middle remote add other bogus &&
+
+ # Make the update of "middle" a no-op, otherwise we error out
+ # because of its unmerged state
+ test_config -C top-cloned submodule.middle.update !true &&
+ git -C top-cloned submodule update --recursive 2>actual.err &&
+ cat >expect.err <<-\EOF &&
+ EOF
+ test_cmp expect.err actual.err
+'
+
+test_expect_success 'submodule update with renamed remote' '
+ test_when_finished "rm -fr top-cloned" &&
+ cp -r top-clean top-cloned &&
+
+ # Create a commit in each repo, starting with bottom
+ test_commit -C bottom rename_commit &&
+ # Create middle commit
+ git -C middle/bottom fetch &&
+ git -C middle/bottom checkout -f FETCH_HEAD &&
+ git -C middle add bottom &&
+ git -C middle commit -m "rename_commit" &&
+ # Create top commit
+ git -C top/middle fetch &&
+ git -C top/middle checkout -f FETCH_HEAD &&
+ git -C top add middle &&
+ git -C top commit -m "rename_commit" &&
+
+ # rename the submodule remote
+ git -C top-cloned/middle remote rename origin upstream &&
+
+ # Make the update of "middle" a no-op, otherwise we error out
+ # because of its unmerged state
+ test_config -C top-cloned submodule.middle.update !true &&
+ git -C top-cloned submodule update --recursive 2>actual.err &&
+ cat >expect.err <<-\EOF &&
+ EOF
+ test_cmp expect.err actual.err
+'
+
test_expect_success 'submodule update should skip unmerged submodules' '
test_when_finished "rm -fr top-cloned" &&
cp -r top-clean top-cloned &&
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 8d7b234beb..77b6d0040e 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -426,14 +426,14 @@ test_expect_success 'option-like arguments passed to foreach commands are not lo
git submodule foreach "echo be --quiet" > ../expected &&
git submodule foreach echo be --quiet > ../actual
) &&
- grep -sq -e "--quiet" expected &&
+ test_grep -e "--quiet" expected &&
test_cmp expected actual
'
test_expect_success 'option-like arguments passed to foreach recurse correctly' '
git -C clone2 submodule foreach --recursive "echo be --an-option" >expect &&
git -C clone2 submodule foreach --recursive echo be --an-option >actual &&
- grep -e "--an-option" expect &&
+ test_grep -e "--an-option" expect &&
test_cmp expect actual
'
diff --git a/t/t7413-submodule-is-active.sh b/t/t7413-submodule-is-active.sh
index 9509dc18fd..6fd3b870de 100755
--- a/t/t7413-submodule-is-active.sh
+++ b/t/t7413-submodule-is-active.sh
@@ -124,4 +124,19 @@ test_expect_success 'is-active, submodule.active and submodule add' '
git -C super2 config --get submodule.mod.active
'
+test_expect_success 'submodule add skips redundant active entry' '
+ git init repo &&
+ (
+ cd repo &&
+ git config submodule.active "lib/*" &&
+ git commit --allow-empty -m init &&
+
+ git init ../lib-origin &&
+ git -C ../lib-origin commit --allow-empty -m init &&
+
+ git submodule add ../lib-origin lib/foo &&
+ test_must_fail git config --get submodule.lib/foo.active
+ )
+'
+
test_done
diff --git a/t/t7416-submodule-dash-url.sh b/t/t7416-submodule-dash-url.sh
index 0c605fd271..3d944a00e0 100755
--- a/t/t7416-submodule-dash-url.sh
+++ b/t/t7416-submodule-dash-url.sh
@@ -33,7 +33,8 @@ test_expect_success 'fsck accepts protected dash' '
'
test_expect_success 'remove ./ protection from .gitmodules url' '
- perl -i -pe "s{\./}{}" .gitmodules &&
+ sed "s|\./||" .gitmodules >.gitmodules.munged &&
+ mv .gitmodules.munged .gitmodules &&
git commit -am "drop protection"
'
diff --git a/t/t7422-submodule-output.sh b/t/t7422-submodule-output.sh
index f21e920367..aea1ddf117 100755
--- a/t/t7422-submodule-output.sh
+++ b/t/t7422-submodule-output.sh
@@ -167,10 +167,42 @@ do
done
test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE' '
- { git submodule status --recursive 2>err; echo $?>status; } |
- grep -q X/S &&
- test_must_be_empty err &&
- test_match_signal 13 "$(cat status)"
+ # The test setup is somewhat involved because triggering a SIGPIPE is
+ # racy with buffered pipes. To avoid the raciness we thus need to make
+ # sure that the subprocess in question fills the buffers completely,
+ # which requires a couple thousand submodules in total.
+ test_when_finished "rm -rf submodule repo" &&
+ git init submodule &&
+ (
+ cd submodule &&
+ test_commit initial &&
+
+ COMMIT=$(git rev-parse HEAD) &&
+ for i in $(test_seq 2000)
+ do
+ echo "[submodule \"sm-$i\"]" &&
+ echo "path = recursive-submodule-path-$i" ||
+ return 1
+ done >gitmodules &&
+ BLOB=$(git hash-object -w --stdin <gitmodules) &&
+
+ printf "100644 blob $BLOB\t.gitmodules\n" >tree &&
+ test_seq -f "160000 commit $COMMIT\trecursive-submodule-path-%d" 2000 >>tree &&
+ TREE=$(git mktree <tree) &&
+
+ COMMIT=$(git commit-tree "$TREE") &&
+ git reset --hard "$COMMIT"
+ ) &&
+
+ git init repo &&
+ (
+ cd repo &&
+ GIT_ALLOW_PROTOCOL=file git submodule add "$(pwd)"/../submodule &&
+ { git submodule status --recursive 2>err; echo $?>status; } |
+ grep -q recursive-submodule-path-1 &&
+ test_must_be_empty err &&
+ test_match_signal 13 "$(cat status)"
+ )
'
test_done
diff --git a/t/t7450-bad-git-dotfiles.sh b/t/t7450-bad-git-dotfiles.sh
index 14b5743b96..f512eed278 100755
--- a/t/t7450-bad-git-dotfiles.sh
+++ b/t/t7450-bad-git-dotfiles.sh
@@ -401,7 +401,7 @@ test_expect_success SYMLINKS,!WINDOWS,!MINGW 'submodule must not checkout into d
git -C repo commit -m submodule &&
git -c protocol.file.allow=always clone --recurse-submodules repo bad-clone &&
- ! test -f "$PWD/foo" &&
+ ! test -f "$PWD/bad-clone/sub/foo" &&
test -f $(printf "bad-clone/sub\r/post-checkout")
'
diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
index cc12f99f11..a37509f004 100755
--- a/t/t7501-commit-basic-functionality.sh
+++ b/t/t7501-commit-basic-functionality.sh
@@ -46,7 +46,7 @@ test_expect_success 'paths and -a do not mix' '
test_must_fail git commit -m foo -a file
'
-test_expect_success PERL 'can use paths with --interactive' '
+test_expect_success 'can use paths with --interactive' '
echo bong-o-bong >file &&
# 2: update, 1:st path, that is all, 7: quit
test_write_lines 2 1 "" 7 |
@@ -345,12 +345,12 @@ test_expect_success 'overriding author from command line' '
grep Rubber.Duck output
'
-test_expect_success PERL 'interactive add' '
+test_expect_success 'interactive add' '
echo 7 | test_must_fail git commit --interactive >out &&
grep "What now" out
'
-test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
+test_expect_success "commit --interactive doesn't change index if editor aborts" '
echo zoo >file &&
test_must_fail git diff --exit-code >diff1 &&
test_write_lines u "*" q |
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index b2070d4e39..cdc1d6fcc7 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1066,7 +1066,7 @@ test_expect_success 'status -s submodule summary (clean submodule)' '
test_expect_success 'status -z implies porcelain' '
git status --porcelain |
- perl -pe "s/\012/\000/g" >expect &&
+ tr "\012" "\000" >expect &&
git status -z >output &&
test_cmp expect output
'
diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh
index 0d2dd29fe6..1201c85ba6 100755
--- a/t/t7510-signed-commit.sh
+++ b/t/t7510-signed-commit.sh
@@ -8,6 +8,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
GNUPGHOME_NOT_USED=$GNUPGHOME
. "$TEST_DIRECTORY/lib-gpg.sh"
+test_expect_success GPG 'verify-commit does not crash with -h' '
+ test_expect_code 129 git verify-commit -h >usage &&
+ test_grep "[Uu]sage: git verify-commit " usage &&
+ test_expect_code 129 nongit git verify-commit -h >usage &&
+ test_grep "[Uu]sage: git verify-commit " usage
+'
+
test_expect_success GPG 'create signed commits' '
test_oid_cache <<-\EOF &&
header sha1:gpgsig
@@ -442,7 +449,17 @@ test_expect_success 'custom `gpg.program`' '
test_must_fail env LET_GPG_PROGRAM_FAIL=1 \
git commit -S --allow-empty -m must-fail 2>err &&
- grep zOMG err
+ grep zOMG err &&
+
+ # `gpg.program` starts with `~`, the path should be interpreted to be relative to `$HOME`
+ test_config gpg.program "~/fake-gpg" &&
+ env HOME="$(pwd)" \
+ git commit -S --allow-empty -m signed-commit &&
+
+ # `gpg.program` does not specify an absolute path, it should find a program in `$PATH`
+ test_config gpg.program "fake-gpg" &&
+ env PATH="$PWD:$PATH" \
+ git commit -S --allow-empty -m signed-commit
'
test_done
diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 802f8f704c..25e8e9711f 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -139,7 +139,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last command done (1 command done):
- pick $LAST_COMMIT one_second
+ pick $LAST_COMMIT # one_second
No commands remaining.
You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
(fix conflicts and then run "git rebase --continue")
@@ -168,7 +168,7 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last command done (1 command done):
- pick $LAST_COMMIT one_second
+ pick $LAST_COMMIT # one_second
No commands remaining.
You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
(all conflicts fixed: run "git rebase --continue")
@@ -200,8 +200,8 @@ test_expect_success 'status when rebasing -i in edit mode' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- pick $COMMIT2 two_rebase_i
- edit $COMMIT3 three_rebase_i
+ pick $COMMIT2 # two_rebase_i
+ edit $COMMIT3 # three_rebase_i
No commands remaining.
You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -233,10 +233,10 @@ test_expect_success 'status when splitting a commit' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- pick $COMMIT2 two_split
- edit $COMMIT3 three_split
+ pick $COMMIT2 # two_split
+ edit $COMMIT3 # three_split
Next command to do (1 remaining command):
- pick $COMMIT4 four_split
+ pick $COMMIT4 # four_split
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
(Once your working directory is clean, run "git rebase --continue")
@@ -271,8 +271,8 @@ test_expect_success 'status after editing the last commit with --amend during a
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (3 commands done):
- pick $COMMIT3 three_amend
- edit $COMMIT4 four_amend
+ pick $COMMIT3 # three_amend
+ edit $COMMIT4 # four_amend
(see more in file .git/rebase-merge/done)
No commands remaining.
You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
@@ -309,10 +309,10 @@ test_expect_success 'status: (continue first edit) second edit' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -340,10 +340,10 @@ test_expect_success 'status: (continue first edit) second edit and split' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(Once your working directory is clean, run "git rebase --continue")
@@ -375,10 +375,10 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -406,10 +406,10 @@ test_expect_success 'status: (amend first edit) second edit' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -438,10 +438,10 @@ test_expect_success 'status: (amend first edit) second edit and split' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(Once your working directory is clean, run "git rebase --continue")
@@ -474,10 +474,10 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -507,10 +507,10 @@ test_expect_success 'status: (split first edit) second edit' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -541,10 +541,10 @@ test_expect_success 'status: (split first edit) second edit and split' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(Once your working directory is clean, run "git rebase --continue")
@@ -579,10 +579,10 @@ test_expect_success 'status: (split first edit) second edit and amend' '
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- edit $COMMIT2 two_edits
- edit $COMMIT3 three_edits
+ edit $COMMIT2 # two_edits
+ edit $COMMIT3 # three_edits
Next command to do (1 remaining command):
- pick $COMMIT4 four_edits
+ pick $COMMIT4 # four_edits
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -997,11 +997,11 @@ test_expect_success 'status: two commands done with some white lines in done fil
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (2 commands done):
- pick $COMMIT2 two_commit
+ pick $COMMIT2 # two_commit
exec exit 15
Next commands to do (2 remaining commands):
- pick $COMMIT3 three_commit
- pick $COMMIT4 four_commit
+ pick $COMMIT3 # three_commit
+ pick $COMMIT4 # four_commit
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -1025,12 +1025,12 @@ test_expect_success 'status: two remaining commands with some white lines in tod
cat >expected <<EOF &&
interactive rebase in progress; onto $ONTO
Last commands done (3 commands done):
- pick $COMMIT2 two_commit
+ pick $COMMIT2 # two_commit
exec exit 15
(see more in file .git/rebase-merge/done)
Next commands to do (2 remaining commands):
- pick $COMMIT3 three_commit
- pick $COMMIT4 four_commit
+ pick $COMMIT3 # three_commit
+ pick $COMMIT4 # four_commit
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
@@ -1050,7 +1050,7 @@ test_expect_success 'status: handle not-yet-started rebase -i gracefully' '
On branch several_commits
No commands done.
Next command to do (1 remaining command):
- pick $COMMIT four_commit
+ pick $COMMIT # four_commit
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
(use "git commit --amend" to amend the current commit)
diff --git a/t/t7528-signed-commit-ssh.sh b/t/t7528-signed-commit-ssh.sh
index 065f780636..0f887a3ebe 100755
--- a/t/t7528-signed-commit-ssh.sh
+++ b/t/t7528-signed-commit-ssh.sh
@@ -84,18 +84,26 @@ test_expect_success GPGSSH 'sign commits using literal public keys with ssh-agen
test_config gpg.format ssh &&
eval $(ssh-agent) &&
test_when_finished "kill ${SSH_AGENT_PID}" &&
- ssh-add "${GPGSSH_KEY_PRIMARY}" &&
- echo 1 >file && git add file &&
- git commit -a -m rsa-inline -S"$(cat "${GPGSSH_KEY_PRIMARY}.pub")" &&
- echo 2 >file &&
- test_config user.signingkey "$(cat "${GPGSSH_KEY_PRIMARY}.pub")" &&
- git commit -a -m rsa-config -S &&
- ssh-add "${GPGSSH_KEY_ECDSA}" &&
- echo 3 >file &&
- git commit -a -m ecdsa-inline -S"key::$(cat "${GPGSSH_KEY_ECDSA}.pub")" &&
- echo 4 >file &&
- test_config user.signingkey "key::$(cat "${GPGSSH_KEY_ECDSA}.pub")" &&
- git commit -a -m ecdsa-config -S
+ test_when_finished "test_unconfig user.signingkey" &&
+ mkdir tmpdir &&
+ TMPDIR="$(pwd)/tmpdir" &&
+ (
+ export TMPDIR &&
+ ssh-add "${GPGSSH_KEY_PRIMARY}" &&
+ echo 1 >file && git add file &&
+ git commit -a -m rsa-inline -S"$(cat "${GPGSSH_KEY_PRIMARY}.pub")" &&
+ echo 2 >file &&
+ git config user.signingkey "$(cat "${GPGSSH_KEY_PRIMARY}.pub")" &&
+ git commit -a -m rsa-config -S &&
+ ssh-add "${GPGSSH_KEY_ECDSA}" &&
+ echo 3 >file &&
+ git commit -a -m ecdsa-inline -S"key::$(cat "${GPGSSH_KEY_ECDSA}.pub")" &&
+ echo 4 >file &&
+ git config user.signingkey "key::$(cat "${GPGSSH_KEY_ECDSA}.pub")" &&
+ git commit -a -m ecdsa-config -S
+ ) &&
+ find tmpdir -type f >tmpfiles &&
+ test_must_be_empty tmpfiles
'
test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed commits with keys having defined lifetimes' '
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index ef54cff4fa..9838094b66 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -173,7 +173,7 @@ test_expect_success 'merge -h with invalid index' '
cd broken &&
git init &&
>.git/index &&
- test_expect_code 129 git merge -h 2>usage
+ test_expect_code 129 git merge -h >usage
) &&
test_grep "[Uu]sage: git merge" broken/usage
'
@@ -185,8 +185,19 @@ test_expect_success 'reject non-strategy with a git-merge-foo name' '
test_expect_success 'merge c0 with c1' '
echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
+ cat >expect <<-\EOF &&
+ Updating FROM..TO
+ Fast-forward
+ file | 2 +-
+ other | 9 +++++++++
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+ create mode 100644 other
+ EOF
+
git reset --hard c0 &&
- git merge c1 &&
+ git merge c1 >out &&
+ sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
+ test_cmp expect actual &&
verify_merge file result.1 &&
verify_head "$c1" &&
@@ -205,6 +216,67 @@ test_expect_success 'merge c0 with c1 with --ff-only' '
verify_head "$c1"
'
+test_expect_success 'the same merge with merge.stat=diffstat' '
+ cat >expect <<-\EOF &&
+ Updating FROM..TO
+ Fast-forward
+ file | 2 +-
+ other | 9 +++++++++
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+ create mode 100644 other
+ EOF
+
+ git reset --hard c0 &&
+ git -c merge.stat=diffstat merge c1 >out &&
+ sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'the same merge with compact summary' '
+ cat >expect <<-\EOF &&
+ Updating FROM..TO
+ Fast-forward
+ file | 2 +-
+ other (new) | 9 +++++++++
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+ EOF
+
+ git reset --hard c0 &&
+ git merge --compact-summary c1 >out &&
+ sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'the same merge with compact summary' '
+ cat >expect <<-\EOF &&
+ Updating FROM..TO
+ Fast-forward
+ file | 2 +-
+ other (new) | 9 +++++++++
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+ EOF
+
+ git reset --hard c0 &&
+ git merge --compact-summary c1 >out &&
+ sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'the same merge with merge.stat=compact' '
+ cat >expect <<-\EOF &&
+ Updating FROM..TO
+ Fast-forward
+ file | 2 +-
+ other (new) | 9 +++++++++
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+ EOF
+
+ git reset --hard c0 &&
+ git -c merge.stat=compact merge c1 >out &&
+ sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
+ test_cmp expect actual
+'
+
test_debug 'git log --graph --decorate --oneline --all'
test_expect_success 'merge from unborn branch' '
diff --git a/t/t7602-merge-octopus-many.sh b/t/t7602-merge-octopus-many.sh
index ff085b086c..42f675b739 100755
--- a/t/t7602-merge-octopus-many.sh
+++ b/t/t7602-merge-octopus-many.sh
@@ -77,12 +77,9 @@ Merge made by the 'recursive' strategy.
EOF
test_expect_success 'merge reduces irrelevant remote heads' '
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- mv expected expected.tmp &&
- sed s/recursive/ort/ expected.tmp >expected &&
- rm expected.tmp
- fi &&
+ mv expected expected.tmp &&
+ sed s/recursive/ort/ expected.tmp >expected &&
+ rm expected.tmp &&
GIT_MERGE_VERBOSITY=0 git merge c4 c5 >actual &&
test_cmp expected actual
'
diff --git a/t/t7603-merge-reduce-heads.sh b/t/t7603-merge-reduce-heads.sh
index 4887ca705b..1f8c3b7ccb 100755
--- a/t/t7603-merge-reduce-heads.sh
+++ b/t/t7603-merge-reduce-heads.sh
@@ -52,12 +52,12 @@ test_expect_success 'merge c1 with c2, c3, c4, c5' '
test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
test "$(git rev-parse c5)" = "$(git rev-parse HEAD^4)" &&
git diff --exit-code &&
- test -f c0.c &&
- test -f c1.c &&
- test -f c2.c &&
- test -f c3.c &&
- test -f c4.c &&
- test -f c5.c &&
+ test_path_is_file c0.c &&
+ test_path_is_file c1.c &&
+ test_path_is_file c2.c &&
+ test_path_is_file c3.c &&
+ test_path_is_file c4.c &&
+ test_path_is_file c5.c &&
git show --format=%s -s >actual &&
! grep c1 actual &&
grep c2 actual &&
@@ -75,12 +75,12 @@ test_expect_success 'pull c2, c3, c4, c5 into c1' '
test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
test "$(git rev-parse c5)" = "$(git rev-parse HEAD^4)" &&
git diff --exit-code &&
- test -f c0.c &&
- test -f c1.c &&
- test -f c2.c &&
- test -f c3.c &&
- test -f c4.c &&
- test -f c5.c &&
+ test_path_is_file c0.c &&
+ test_path_is_file c1.c &&
+ test_path_is_file c2.c &&
+ test_path_is_file c3.c &&
+ test_path_is_file c4.c &&
+ test_path_is_file c5.c &&
git show --format=%s -s >actual &&
! grep c1 actual &&
grep c2 actual &&
diff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh
index e8e205707e..af3ad284ee 100755
--- a/t/t7609-mergetool--lib.sh
+++ b/t/t7609-mergetool--lib.sh
@@ -7,7 +7,7 @@ Testing basic merge tools options'
. ./test-lib.sh
test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '
- . "$GIT_TEST_MERGE_TOOLS_DIR"/vimdiff &&
+ . "$GIT_SOURCE_DIR"/mergetools/vimdiff &&
run_unit_tests
'
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index c077aba7ce..957f8e20ba 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -535,14 +535,9 @@ test_expect_success 'file vs modified submodule' '
yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
yes "" | git mergetool both &&
yes "d" | git mergetool file11 file12 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- yes "c" | git mergetool submod~HEAD &&
- git rm submod &&
- git mv submod~HEAD submod
- else
- yes "l" | git mergetool submod
- fi &&
+ yes "c" | git mergetool submod~HEAD &&
+ git rm submod &&
+ git mv submod~HEAD submod &&
git submodule update -N &&
echo "not a submodule" >expect &&
test_cmp expect submod &&
@@ -559,15 +554,10 @@ test_expect_success 'file vs modified submodule' '
yes "" | git mergetool file1 file2 spaced\ name subdir/file3 &&
yes "" | git mergetool both &&
yes "d" | git mergetool file11 file12 &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- mv submod submod.orig &&
- git rm --cached submod &&
- yes "c" | git mergetool submod~test19 &&
- git mv submod~test19 submod
- else
- yes "r" | git mergetool submod
- fi &&
+ mv submod submod.orig &&
+ git rm --cached submod &&
+ yes "c" | git mergetool submod~test19 &&
+ git mv submod~test19 submod &&
test -d submod.orig &&
git submodule update -N &&
echo "not a submodule" >expect &&
@@ -585,10 +575,7 @@ test_expect_success 'file vs modified submodule' '
yes "" | git mergetool both &&
yes "d" | git mergetool file11 file12 &&
yes "l" | git mergetool submod &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- yes "d" | git mergetool submod~test19
- fi &&
+ yes "d" | git mergetool submod~test19 &&
echo "main submodule" >expect &&
test_cmp expect submod/bar &&
git submodule update -N &&
@@ -686,14 +673,9 @@ test_expect_success 'directory vs modified submodule' '
test_must_fail git merge main &&
test -n "$(git ls-files -u)" &&
test ! -e submod.orig &&
- if test "$GIT_TEST_MERGE_ALGORITHM" = ort
- then
- yes "r" | git mergetool submod~main &&
- git mv submod submod.orig &&
- git mv submod~main submod
- else
- yes "r" | git mergetool submod
- fi &&
+ yes "r" | git mergetool submod~main &&
+ git mv submod submod.orig &&
+ git mv submod~main submod &&
test -d submod.orig &&
echo "not a submodule" >expect &&
test_cmp expect submod.orig/file16 &&
diff --git a/t/t7615-diff-algo-with-mergy-operations.sh b/t/t7615-diff-algo-with-mergy-operations.sh
index 3b1aad0167..5822d02d51 100755
--- a/t/t7615-diff-algo-with-mergy-operations.sh
+++ b/t/t7615-diff-algo-with-mergy-operations.sh
@@ -22,11 +22,9 @@ test_expect_success 'setup' '
git tag c2
'
-GIT_TEST_MERGE_ALGORITHM=recursive
-
test_expect_success 'merge c2 to c1 with recursive merge strategy fails with the current default myers diff algorithm' '
git reset --hard c1 &&
- test_must_fail git merge -s recursive c2
+ test_must_fail git merge -s recursive -Xdiff-algorithm=myers c2
'
test_expect_success 'merge c2 to c1 with recursive merge strategy succeeds with -Xdiff-algorithm=histogram' '
@@ -42,7 +40,7 @@ test_expect_success 'merge c2 to c1 with recursive merge strategy succeeds with
test_expect_success 'cherry-pick c2 to c1 with recursive merge strategy fails with the current default myers diff algorithm' '
git reset --hard c1 &&
- test_must_fail git cherry-pick -s recursive c2
+ test_must_fail git cherry-pick -s recursive -Xdiff-algorithm=myers c2
'
test_expect_success 'cherry-pick c2 to c1 with recursive merge strategy succeeds with -Xdiff-algorithm=histogram' '
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index be1188e736..73b78bdd88 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -308,7 +308,10 @@ test_expect_success 'no bitmaps created if .keep files present' '
keep=${pack%.pack}.keep &&
test_when_finished "rm -f \"\$keep\"" &&
>"$keep" &&
- git -C bare.git repack -ad 2>stderr &&
+
+ # Disable --name-hash-version test due to stderr comparison.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git -C bare.git repack -ad 2>stderr &&
test_must_be_empty stderr &&
find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
test_must_be_empty actual
@@ -319,7 +322,10 @@ test_expect_success 'auto-bitmaps do not complain if unavailable' '
blob=$(test-tool genrandom big $((1024*1024)) |
git -C bare.git hash-object -w --stdin) &&
git -C bare.git update-ref refs/tags/big $blob &&
- git -C bare.git repack -ad 2>stderr &&
+
+ # Disable --name-hash-version test due to stderr comparison.
+ GIT_TEST_NAME_HASH_VERSION=1 \
+ git -C bare.git repack -ad 2>stderr &&
test_must_be_empty stderr &&
find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
test_must_be_empty actual
@@ -776,6 +782,12 @@ test_expect_success 'repack -ad cleans up old .tmp-* packs' '
test_must_be_empty tmpfiles
'
+test_expect_success '--name-hash-version option passes through to pack-objects' '
+ GIT_TRACE2_EVENT="$(pwd)/hash-trace.txt" \
+ git repack -a --name-hash-version=2 &&
+ test_subcommand_flex git pack-objects --name-hash-version=2 <hash-trace.txt
+'
+
test_expect_success 'setup for update-server-info' '
git init update-server-info &&
test_commit -C update-server-info message
@@ -826,4 +838,67 @@ test_expect_success '-n overrides repack.updateServerInfo=true' '
test_server_info_missing
'
+test_expect_success 'pending objects are repacked appropriately' '
+ test_when_finished rm -rf pending &&
+ git init pending &&
+
+ (
+ cd pending &&
+
+ # Commit file, a/b/c and never change them.
+ mkdir -p a/b &&
+ echo singleton >file &&
+ echo stuff >a/b/c &&
+ echo more >a/d &&
+ git add file a &&
+ git commit -m "single blobs" &&
+
+ # Files a/d and a/e will not be singletons.
+ echo d >a/d &&
+ echo e >a/e &&
+ git add a &&
+ git commit -m "more blobs" &&
+
+ # This use of a sparse index helps to force
+ # test that the cache-tree is walked, too.
+ git sparse-checkout set --sparse-index a x &&
+
+ # Create staged changes:
+ # * a/e now has multiple versions.
+ # * a/i now has only one version.
+ echo f >a/d &&
+ echo h >a/e &&
+ echo i >a/i &&
+ git add a &&
+
+ # Stage and unstage a change to make use of
+ # resolve-undo cache and how that impacts fsck.
+ mkdir x &&
+ echo y >x/y &&
+ git add x &&
+ xy=$(git rev-parse :x/y) &&
+ git rm --cached x/y &&
+
+ # The blob for x/y must persist through repacks,
+ # but fsck currently ignores the REUC extension
+ # for finding links to the blob.
+ cat >expect <<-EOF &&
+ dangling blob $xy
+ EOF
+
+ # Bring the loose objects into a packfile to avoid
+ # leftovers in next test. Without this, the loose
+ # objects persist and the test succeeds for other
+ # reasons.
+ git repack -adf &&
+ git fsck >out &&
+ test_cmp expect out &&
+
+ # Test path walk version with pack.useSparse.
+ git -c pack.useSparse=true repack -adf --path-walk &&
+ git fsck >out &&
+ test_cmp expect out
+ )
+'
+
test_done
diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh
index 5715f4d69a..5559d4ccb4 100755
--- a/t/t7701-repack-unpack-unreachable.sh
+++ b/t/t7701-repack-unpack-unreachable.sh
@@ -195,4 +195,20 @@ test_expect_success 'repack -k packs unreachable loose objects' '
git cat-file -p $sha1
'
+test_expect_success 'repack -k packs unreachable loose objects without existing packfiles' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+
+ oid=$(echo would-be-deleted-loose | git hash-object -w --stdin) &&
+ objpath=.git/objects/$(echo $sha1 | sed "s,..,&/,") &&
+ test_path_is_file $objpath &&
+
+ git repack -ad --keep-unreachable &&
+ test_path_is_missing $objpath &&
+ git cat-file -p $oid
+ )
+'
+
test_done
diff --git a/t/t7704-repack-cruft.sh b/t/t7704-repack-cruft.sh
index 959e6e2648..aa2e2e6ad8 100755
--- a/t/t7704-repack-cruft.sh
+++ b/t/t7704-repack-cruft.sh
@@ -149,7 +149,7 @@ generate_cruft_pack () {
echo "$packdir/pack-$pack.mtimes"
}
-test_expect_success '--max-cruft-size creates new packs when above threshold' '
+test_expect_success '--max-cruft-size creates new packs when too large' '
git init max-cruft-size-large &&
(
cd max-cruft-size-large &&
@@ -173,7 +173,7 @@ test_expect_success '--max-cruft-size creates new packs when above threshold' '
)
'
-test_expect_success '--max-cruft-size combines existing packs when below threshold' '
+test_expect_success '--max-cruft-size combines existing packs when not too large' '
git init max-cruft-size-small &&
(
cd max-cruft-size-small &&
@@ -194,10 +194,13 @@ test_expect_success '--max-cruft-size combines existing packs when below thresho
)
'
-test_expect_success '--max-cruft-size combines smaller packs first' '
- git init max-cruft-size-consume-small &&
+test_expect_success '--combine-cruft-below-size combines packs' '
+ repo=combine-cruft-below-size &&
+ test_when_finished "rm -fr $repo" &&
+
+ git init "$repo" &&
(
- cd max-cruft-size-consume-small &&
+ cd "$repo" &&
test_commit base &&
git repack -ad &&
@@ -211,11 +214,11 @@ test_expect_success '--max-cruft-size combines smaller packs first' '
test-tool pack-mtimes "$(basename $cruft_bar)" >>expect.raw &&
sort expect.raw >expect.objects &&
- # repacking with `--max-cruft-size=2M` should combine
- # both 0.5 MiB packs together, instead of, say, one of
- # the 0.5 MiB packs with the 1.0 MiB pack
+ # Repacking with `--combine-cruft-below-size=1M`
+ # should combine both 0.5 MiB packs together, but
+ # ignore the two packs which are >= 1.0 MiB.
ls $packdir/pack-*.mtimes | sort >cruft.before &&
- git repack -d --cruft --max-cruft-size=2M &&
+ git repack -d --cruft --combine-cruft-below-size=1M &&
ls $packdir/pack-*.mtimes | sort >cruft.after &&
comm -13 cruft.before cruft.after >cruft.new &&
@@ -224,11 +227,12 @@ test_expect_success '--max-cruft-size combines smaller packs first' '
test_line_count = 1 cruft.new &&
test_line_count = 2 cruft.removed &&
- # the two smaller packs should be rolled up first
+ # The two packs smaller than 1.0MiB should be repacked
+ # together.
printf "%s\n" $cruft_foo $cruft_bar | sort >expect.removed &&
test_cmp expect.removed cruft.removed &&
- # ...and contain the set of objects rolled up
+ # ...and contain the set of objects rolled up.
test-tool pack-mtimes "$(basename $(cat cruft.new))" >actual.raw &&
sort actual.raw >actual.objects &&
@@ -236,10 +240,10 @@ test_expect_success '--max-cruft-size combines smaller packs first' '
)
'
-test_expect_success 'setup --max-cruft-size with freshened objects' '
- git init max-cruft-size-freshen &&
+test_expect_success 'setup cruft with freshened objects' '
+ git init cruft-freshen &&
(
- cd max-cruft-size-freshen &&
+ cd cruft-freshen &&
test_commit base &&
git repack -ad &&
@@ -257,9 +261,9 @@ test_expect_success 'setup --max-cruft-size with freshened objects' '
)
'
-test_expect_success '--max-cruft-size with freshened objects (loose)' '
+test_expect_success 'cruft with freshened objects (loose)' '
(
- cd max-cruft-size-freshen &&
+ cd cruft-freshen &&
# regenerate the object, setting its mtime to be more recent
foo="$(generate_random_blob foo 64)" &&
@@ -275,9 +279,9 @@ test_expect_success '--max-cruft-size with freshened objects (loose)' '
)
'
-test_expect_success '--max-cruft-size with freshened objects (packed)' '
+test_expect_success 'cruft with freshened objects (packed)' '
(
- cd max-cruft-size-freshen &&
+ cd cruft-freshen &&
# regenerate the object and store it in a packfile,
# setting its mtime to be more recent
@@ -304,6 +308,70 @@ test_expect_success '--max-cruft-size with freshened objects (packed)' '
)
'
+test_expect_success 'multi-cruft with freshened objects (previously cruft)' '
+ repo="max-cruft-size-threshold" &&
+
+ test_when_finished "rm -fr $repo" &&
+ git init "$repo" &&
+ (
+ cd "$repo" &&
+
+ test_commit base &&
+ foo="$(generate_random_blob foo $((2*1024*1024)))" &&
+ bar="$(generate_random_blob bar $((2*1024*1024)))" &&
+ baz="$(generate_random_blob baz $((2*1024*1024)))" &&
+
+ test-tool chmtime --get -100000 \
+ "$objdir/$(test_oid_to_path "$foo")" >foo.old &&
+ test-tool chmtime --get -100000 \
+ "$objdir/$(test_oid_to_path "$bar")" >bar.old &&
+ test-tool chmtime --get -100000 \
+ "$objdir/$(test_oid_to_path "$baz")" >baz.old &&
+
+ git repack --cruft -d &&
+
+ # Make an identical copy of foo stored in a pack with a more
+ # recent mtime.
+ foo="$(generate_random_blob foo $((2*1024*1024)))" &&
+ foo_pack="$(echo "$foo" | git pack-objects $packdir/pack)" &&
+ test-tool chmtime --get -100 \
+ "$packdir/pack-$foo_pack.pack" >foo.new &&
+ git prune-packed &&
+
+ # Make a loose copy of bar, also with a more recent mtime.
+ bar="$(generate_random_blob bar $((2*1024*1024)))" &&
+ test-tool chmtime --get -100 \
+ "$objdir/$(test_oid_to_path "$bar")" >bar.new &&
+
+ # Make a new cruft object $quux to ensure we do not
+ # generate an identical pack to the existing cruft
+ # pack.
+ quux="$(generate_random_blob quux $((1024)))" &&
+ test-tool chmtime --get -100 \
+ "$objdir/$(test_oid_to_path "$quux")" >quux.new &&
+
+ git repack --cruft --max-cruft-size=3M -d &&
+
+ for p in $packdir/pack-*.mtimes
+ do
+ test-tool pack-mtimes "$(basename "$p")" || return 1
+ done >actual.raw &&
+ sort actual.raw >actual &&
+
+ # Among the set of all cruft packs, we should see the
+ # new mtimes for object $foo and $bar, as well as the
+ # single new copy of $baz.
+ sort >expect <<-EOF &&
+ $foo $(cat foo.new)
+ $bar $(cat bar.new)
+ $baz $(cat baz.old)
+ $quux $(cat quux.new)
+ EOF
+
+ test_cmp expect actual
+ )
+'
+
test_expect_success '--max-cruft-size with pruning' '
git init max-cruft-size-prune &&
(
@@ -411,4 +479,394 @@ test_expect_success 'reachable packs are preferred over cruft ones' '
)
'
+test_expect_success 'repack --cruft generates a cruft pack' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit reachable &&
+ git branch -M main &&
+ git checkout --orphan other &&
+ test_commit unreachable &&
+
+ git checkout main &&
+ git branch -D other &&
+ git tag -d unreachable &&
+ # objects are not cruft if they are contained in the reflogs
+ git reflog expire --all --expire=all &&
+
+ git rev-list --objects --all --no-object-names >reachable.raw &&
+ git cat-file --batch-all-objects --batch-check="%(objectname)" >objects &&
+ sort <reachable.raw >reachable &&
+ comm -13 reachable objects >unreachable &&
+
+ git repack --cruft -d &&
+
+ cruft=$(basename $(ls $packdir/pack-*.mtimes) .mtimes) &&
+ pack=$(basename $(ls $packdir/pack-*.pack | grep -v $cruft) .pack) &&
+
+ git show-index <$packdir/$pack.idx >actual.raw &&
+ cut -f2 -d" " actual.raw | sort >actual &&
+ test_cmp reachable actual &&
+
+ git show-index <$packdir/$cruft.idx >actual.raw &&
+ cut -f2 -d" " actual.raw | sort >actual &&
+ test_cmp unreachable actual
+ )
+'
+
+test_expect_success 'cruft packs are not included in geometric repack' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit reachable &&
+ git repack -Ad &&
+ git branch -M main &&
+
+ git checkout --orphan other &&
+ test_commit cruft &&
+ git repack -d &&
+
+ git checkout main &&
+ git branch -D other &&
+ git tag -d cruft &&
+ git reflog expire --all --expire=all &&
+
+ git repack --cruft &&
+
+ find $packdir -type f | sort >before &&
+ git repack --geometric=2 -d &&
+ find $packdir -type f | sort >after &&
+
+ test_cmp before after
+ )
+'
+
+test_expect_success 'repack --geometric collects once-cruft objects' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit reachable &&
+ git repack -Ad &&
+ git branch -M main &&
+
+ git checkout --orphan other &&
+ git rm -rf . &&
+ test_commit --no-tag cruft &&
+ cruft="$(git rev-parse HEAD)" &&
+
+ git checkout main &&
+ git branch -D other &&
+ git reflog expire --all --expire=all &&
+
+ # Pack the objects created in the previous step into a cruft
+ # pack. Intentionally leave loose copies of those objects
+ # around so we can pick them up in a subsequent --geometric
+ # reapack.
+ git repack --cruft &&
+
+ # Now make those objects reachable, and ensure that they are
+ # packed into the new pack created via a --geometric repack.
+ git update-ref refs/heads/other $cruft &&
+
+ # Without this object, the set of unpacked objects is exactly
+ # the set of objects already in the cruft pack. Tweak that set
+ # to ensure we do not overwrite the cruft pack entirely.
+ test_commit reachable2 &&
+
+ find $packdir -name "pack-*.idx" | sort >before &&
+ git repack --geometric=2 -d &&
+ find $packdir -name "pack-*.idx" | sort >after &&
+
+ {
+ git rev-list --objects --no-object-names $cruft &&
+ git rev-list --objects --no-object-names reachable..reachable2
+ } >want.raw &&
+ sort want.raw >want &&
+
+ pack=$(comm -13 before after) &&
+ git show-index <$pack >objects.raw &&
+
+ cut -d" " -f2 objects.raw | sort >got &&
+
+ test_cmp want got
+ )
+'
+
+test_expect_success 'cruft repack with no reachable objects' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit base &&
+ git repack -ad &&
+
+ base="$(git rev-parse base)" &&
+
+ git for-each-ref --format="delete %(refname)" >in &&
+ git update-ref --stdin <in &&
+ git reflog expire --all --expire=all &&
+ rm -fr .git/index &&
+
+ git repack --cruft -d &&
+
+ git cat-file -t $base
+ )
+'
+
+find_pack () {
+ for idx in $(ls $packdir/pack-*.idx)
+ do
+ git show-index <$idx >out &&
+ if grep -q "$1" out
+ then
+ echo $idx
+ fi || return 1
+ done
+}
+
+test_expect_success 'cruft repack with --max-pack-size' '
+ git init max-pack-size &&
+ (
+ cd max-pack-size &&
+ test_commit base &&
+
+ # two cruft objects which exceed the maximum pack size
+ foo=$(generate_random_blob foo 1048576) &&
+ bar=$(generate_random_blob bar 1048576) &&
+ test-tool chmtime --get -1000 \
+ "$objdir/$(test_oid_to_path $foo)" >foo.mtime &&
+ test-tool chmtime --get -2000 \
+ "$objdir/$(test_oid_to_path $bar)" >bar.mtime &&
+ git repack --cruft --max-pack-size=1M &&
+ find $packdir -name "*.mtimes" >cruft &&
+ test_line_count = 2 cruft &&
+
+ foo_mtimes="$(basename $(find_pack $foo) .idx).mtimes" &&
+ bar_mtimes="$(basename $(find_pack $bar) .idx).mtimes" &&
+ test-tool pack-mtimes $foo_mtimes >foo.actual &&
+ test-tool pack-mtimes $bar_mtimes >bar.actual &&
+
+ echo "$foo $(cat foo.mtime)" >foo.expect &&
+ echo "$bar $(cat bar.mtime)" >bar.expect &&
+
+ test_cmp foo.expect foo.actual &&
+ test_cmp bar.expect bar.actual &&
+ test "$foo_mtimes" != "$bar_mtimes"
+ )
+'
+
+test_expect_success 'cruft repack with pack.packSizeLimit' '
+ (
+ cd max-pack-size &&
+ # repack everything back together to remove the existing cruft
+ # pack (but to keep its objects)
+ git repack -adk &&
+ git -c pack.packSizeLimit=1M repack --cruft &&
+ # ensure the same post condition is met when --max-pack-size
+ # would otherwise be inferred from the configuration
+ find $packdir -name "*.mtimes" >cruft &&
+ test_line_count = 2 cruft &&
+ for pack in $(cat cruft)
+ do
+ test-tool pack-mtimes "$(basename $pack)" >objects &&
+ test_line_count = 1 objects || return 1
+ done
+ )
+'
+
+test_expect_success 'cruft repack respects repack.cruftWindow' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit base &&
+
+ GIT_TRACE2_EVENT=$(pwd)/event.trace \
+ git -c pack.window=1 -c repack.cruftWindow=2 repack \
+ --cruft --window=3 &&
+
+ grep "pack-objects.*--window=2.*--cruft" event.trace
+ )
+'
+
+test_expect_success 'cruft repack respects --window by default' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit base &&
+
+ GIT_TRACE2_EVENT=$(pwd)/event.trace \
+ git -c pack.window=2 repack --cruft --window=3 &&
+
+ grep "pack-objects.*--window=3.*--cruft" event.trace
+ )
+'
+
+test_expect_success 'cruft repack respects --quiet' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit base &&
+ GIT_PROGRESS_DELAY=0 git repack --cruft --quiet 2>err &&
+ test_must_be_empty err
+ )
+'
+
+setup_cruft_exclude_tests() {
+ git init "$1" &&
+ (
+ cd "$1" &&
+
+ git config repack.midxMustContainCruft false &&
+
+ test_commit one &&
+
+ test_commit --no-tag two &&
+ two="$(git rev-parse HEAD)" &&
+ test_commit --no-tag three &&
+ three="$(git rev-parse HEAD)" &&
+ git reset --hard one &&
+ git reflog expire --all --expire=all &&
+
+ GIT_TEST_MULTI_PACK_INDEX=0 git repack --cruft -d &&
+
+ git merge $two &&
+ test_commit four
+ )
+}
+
+test_expect_success 'repack --write-midx excludes cruft where possible' '
+ setup_cruft_exclude_tests exclude-cruft-when-possible &&
+ (
+ cd exclude-cruft-when-possible &&
+
+ GIT_TEST_MULTI_PACK_INDEX=0 \
+ git repack -d --geometric=2 --write-midx --write-bitmap-index &&
+
+ test-tool read-midx --show-objects $objdir >midx &&
+ cruft="$(ls $packdir/*.mtimes)" &&
+ test_grep ! "$(basename "$cruft" .mtimes).idx" midx &&
+
+ git rev-list --all --objects --no-object-names >reachable.raw &&
+ sort reachable.raw >reachable.objects &&
+ awk "/\.pack$/ { print \$1 }" <midx | sort >midx.objects &&
+
+ test_cmp reachable.objects midx.objects
+ )
+'
+
+test_expect_success 'repack --write-midx includes cruft when instructed' '
+ setup_cruft_exclude_tests exclude-cruft-when-instructed &&
+ (
+ cd exclude-cruft-when-instructed &&
+
+ GIT_TEST_MULTI_PACK_INDEX=0 \
+ git -c repack.midxMustContainCruft=true repack \
+ -d --geometric=2 --write-midx --write-bitmap-index &&
+
+ test-tool read-midx --show-objects $objdir >midx &&
+ cruft="$(ls $packdir/*.mtimes)" &&
+ test_grep "$(basename "$cruft" .mtimes).idx" midx &&
+
+ git cat-file --batch-check="%(objectname)" --batch-all-objects \
+ >all.objects &&
+ awk "/\.pack$/ { print \$1 }" <midx | sort >midx.objects &&
+
+ test_cmp all.objects midx.objects
+ )
+'
+
+test_expect_success 'repack --write-midx includes cruft when necessary' '
+ setup_cruft_exclude_tests exclude-cruft-when-necessary &&
+ (
+ cd exclude-cruft-when-necessary &&
+
+ test_path_is_file $(ls $packdir/pack-*.mtimes) &&
+ ( cd $packdir && ls pack-*.idx ) | sort >packs.all &&
+ git multi-pack-index write --stdin-packs --bitmap <packs.all &&
+
+ test_commit five &&
+ GIT_TEST_MULTI_PACK_INDEX=0 \
+ git repack -d --geometric=2 --write-midx --write-bitmap-index &&
+
+ test-tool read-midx --show-objects $objdir >midx &&
+ awk "/\.pack$/ { print \$1 }" <midx | sort >midx.objects &&
+ git cat-file --batch-all-objects --batch-check="%(objectname)" \
+ >expect.objects &&
+ test_cmp expect.objects midx.objects &&
+
+ grep "^pack-" midx >midx.packs &&
+ test_line_count = "$(($(wc -l <packs.all) + 1))" midx.packs
+ )
+'
+
+test_expect_success 'repack --write-midx includes cruft when already geometric' '
+ git init repack--write-midx-geometric-noop &&
+ (
+ cd repack--write-midx-geometric-noop &&
+
+ git branch -M main &&
+ test_commit A &&
+ test_commit B &&
+
+ git checkout -B side &&
+ test_commit --no-tag C &&
+ C="$(git rev-parse HEAD)" &&
+
+ git checkout main &&
+ git branch -D side &&
+ git reflog expire --all --expire=all &&
+
+ # At this point we have two packs: one containing the
+ # objects belonging to commits A and B, and another
+ # (cruft) pack containing the objects belonging to
+ # commit C.
+ git repack --cruft -d &&
+
+ # Create a third pack which contains a merge commit
+ # making commit C reachable again.
+ #
+ # --no-ff is important here, as it ensures that we
+ # actually write a new object and subsequently a new
+ # pack to contain it.
+ git merge --no-ff $C &&
+ git repack -d &&
+
+ ls $packdir/pack-*.idx | sort >packs.all &&
+ cruft="$(ls $packdir/pack-*.mtimes)" &&
+ cruft="${cruft%.mtimes}.idx" &&
+
+ for idx in $(grep -v $cruft <packs.all)
+ do
+ git show-index <$idx >out &&
+ wc -l <out || return 1
+ done >sizes.raw &&
+
+ # Make sure that there are two non-cruft packs, and
+ # that one of them contains at least twice as many
+ # objects as the other, ensuring that they are already
+ # in a geometric progression.
+ sort -n sizes.raw >sizes &&
+ test_line_count = 2 sizes &&
+ s1=$(head -n 1 sizes) &&
+ s2=$(tail -n 1 sizes) &&
+ test "$s2" -gt "$((2 * $s1))" &&
+
+ git -c repack.midxMustContainCruft=false repack --geometric=2 \
+ --write-midx --write-bitmap-index
+ )
+'
+
test_done
diff --git a/t/t7815-grep-binary.sh b/t/t7815-grep-binary.sh
index 90ebb64f46..55d5e6de17 100755
--- a/t/t7815-grep-binary.sh
+++ b/t/t7815-grep-binary.sh
@@ -63,7 +63,7 @@ test_expect_success 'git grep ile a' '
git grep ile a
'
-test_expect_failure 'git grep .fi a' '
+test_expect_failure !CYGWIN,!MACOS 'git grep .fi a' '
git grep .fi a
'
@@ -114,13 +114,10 @@ test_expect_success 'grep respects not-binary diff attribute' '
test_cmp expect actual
'
-cat >nul_to_q_textconv <<'EOF'
-#!/bin/sh
-"$PERL_PATH" -pe 'y/\000/Q/' < "$1"
-EOF
-chmod +x nul_to_q_textconv
-
test_expect_success 'setup textconv filters' '
+ write_script nul_to_q_textconv <<-\EOF &&
+ tr "\000" "Q" <"$1"
+ EOF
echo a diff=foo >.gitattributes &&
git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
'
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 1909aed95e..ddd273d8dc 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -49,9 +49,9 @@ test_expect_success 'run [--auto|--quiet]' '
git maintenance run --auto 2>/dev/null &&
GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
git maintenance run --no-quiet 2>/dev/null &&
- test_subcommand git gc --quiet --no-detach <run-no-auto.txt &&
- test_subcommand ! git gc --auto --quiet --no-detach <run-auto.txt &&
- test_subcommand git gc --no-quiet --no-detach <run-no-quiet.txt
+ test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-no-auto.txt &&
+ test_subcommand ! git gc --auto --quiet --no-detach --skip-foreground-tasks <run-auto.txt &&
+ test_subcommand git gc --no-quiet --no-detach --skip-foreground-tasks <run-no-quiet.txt
'
test_expect_success 'maintenance.auto config option' '
@@ -154,9 +154,9 @@ test_expect_success 'run --task=<task>' '
git maintenance run --task=commit-graph 2>/dev/null &&
GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
- test_subcommand ! git gc --quiet --no-detach <run-commit-graph.txt &&
- test_subcommand git gc --quiet --no-detach <run-gc.txt &&
- test_subcommand git gc --quiet --no-detach <run-both.txt &&
+ test_subcommand ! git gc --quiet --no-detach --skip-foreground-tasks <run-commit-graph.txt &&
+ test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-gc.txt &&
+ test_subcommand git gc --quiet --no-detach --skip-foreground-tasks <run-both.txt &&
test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
@@ -306,6 +306,34 @@ test_expect_success 'maintenance.loose-objects.auto' '
test_subcommand git prune-packed --quiet <trace-loC
'
+test_expect_success 'maintenance.loose-objects.batchSize' '
+ git init loose-batch &&
+
+ # This creates three objects per commit.
+ test_commit_bulk -C loose-batch 34 &&
+ pack=$(ls loose-batch/.git/objects/pack/pack-*.pack) &&
+ index="${pack%pack}idx" &&
+ rm "$index" &&
+ git -C loose-batch unpack-objects <"$pack" &&
+ git -C loose-batch config maintenance.loose-objects.batchSize 50 &&
+
+ GIT_PROGRESS_DELAY=0 \
+ git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err &&
+ grep "Enumerating objects: 50, done." err &&
+
+ GIT_PROGRESS_DELAY=0 \
+ git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err &&
+ grep "Enumerating objects: 50, done." err &&
+
+ GIT_PROGRESS_DELAY=0 \
+ git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err &&
+ grep "Enumerating objects: 2, done." err &&
+
+ GIT_PROGRESS_DELAY=0 \
+ git -C loose-batch maintenance run --no-quiet --task=loose-objects 2>err &&
+ test_must_be_empty err
+'
+
test_expect_success 'incremental-repack task' '
packDir=.git/objects/pack &&
for i in $(test_seq 1 5)
@@ -447,9 +475,147 @@ test_expect_success 'pack-refs task' '
test_subcommand git pack-refs --all --prune <pack-refs.txt
'
+test_expect_success 'reflog-expire task' '
+ GIT_TRACE2_EVENT="$(pwd)/reflog-expire.txt" \
+ git maintenance run --task=reflog-expire &&
+ test_subcommand git reflog expire --all <reflog-expire.txt
+'
+
+test_expect_success 'reflog-expire task --auto only packs when exceeding limits' '
+ git reflog expire --all --expire=now &&
+ test_commit reflog-one &&
+ test_commit reflog-two &&
+ GIT_TRACE2_EVENT="$(pwd)/reflog-expire-auto.txt" \
+ git -c maintenance.reflog-expire.auto=3 maintenance run --auto --task=reflog-expire &&
+ test_subcommand ! git reflog expire --all <reflog-expire-auto.txt &&
+ GIT_TRACE2_EVENT="$(pwd)/reflog-expire-auto.txt" \
+ git -c maintenance.reflog-expire.auto=2 maintenance run --auto --task=reflog-expire &&
+ test_subcommand git reflog expire --all <reflog-expire-auto.txt
+'
+
+test_expect_worktree_prune () {
+ negate=
+ if test "$1" = "!"
+ then
+ negate="!"
+ shift
+ fi
+
+ rm -f "worktree-prune.txt" &&
+ GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" "$@" &&
+ test_subcommand $negate git worktree prune --expire 3.months.ago <worktree-prune.txt
+}
+
+test_expect_success 'worktree-prune task without --auto always prunes' '
+ test_expect_worktree_prune git maintenance run --task=worktree-prune
+'
+
+test_expect_success 'worktree-prune task --auto only prunes with prunable worktree' '
+ test_expect_worktree_prune ! git maintenance run --auto --task=worktree-prune &&
+ mkdir .git/worktrees &&
+ : >.git/worktrees/abc &&
+ test_expect_worktree_prune git maintenance run --auto --task=worktree-prune
+'
+
+test_expect_success 'worktree-prune task with --auto honors maintenance.worktree-prune.auto' '
+ # A negative value should always prune.
+ test_expect_worktree_prune git -c maintenance.worktree-prune.auto=-1 maintenance run --auto --task=worktree-prune &&
+
+ mkdir .git/worktrees &&
+ : >.git/worktrees/first &&
+ : >.git/worktrees/second &&
+ : >.git/worktrees/third &&
+
+ # Zero should never prune.
+ test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=0 maintenance run --auto --task=worktree-prune &&
+ # A positive value should require at least this many prunable worktrees.
+ test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=4 maintenance run --auto --task=worktree-prune &&
+ test_expect_worktree_prune git -c maintenance.worktree-prune.auto=3 maintenance run --auto --task=worktree-prune
+'
+
+test_expect_success 'worktree-prune task with --auto honors maintenance.worktree-prune.auto' '
+ # A negative value should always prune.
+ test_expect_worktree_prune git -c maintenance.worktree-prune.auto=-1 maintenance run --auto --task=worktree-prune &&
+
+ mkdir .git/worktrees &&
+ : >.git/worktrees/first &&
+ : >.git/worktrees/second &&
+ : >.git/worktrees/third &&
+
+ # Zero should never prune.
+ test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=0 maintenance run --auto --task=worktree-prune &&
+ # A positive value should require at least this many prunable worktrees.
+ test_expect_worktree_prune ! git -c maintenance.worktree-prune.auto=4 maintenance run --auto --task=worktree-prune &&
+ test_expect_worktree_prune git -c maintenance.worktree-prune.auto=3 maintenance run --auto --task=worktree-prune
+'
+
+test_expect_success 'worktree-prune task honors gc.worktreePruneExpire' '
+ git worktree add worktree &&
+ rm -rf worktree &&
+
+ rm -f worktree-prune.txt &&
+ GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" git -c gc.worktreePruneExpire=1.week.ago maintenance run --auto --task=worktree-prune &&
+ test_subcommand ! git worktree prune --expire 1.week.ago <worktree-prune.txt &&
+ test_path_is_dir .git/worktrees/worktree &&
+
+ rm -f worktree-prune.txt &&
+ GIT_TRACE2_EVENT="$(pwd)/worktree-prune.txt" git -c gc.worktreePruneExpire=now maintenance run --auto --task=worktree-prune &&
+ test_subcommand git worktree prune --expire now <worktree-prune.txt &&
+ test_path_is_missing .git/worktrees/worktree
+'
+
+test_expect_rerere_gc () {
+ negate=
+ if test "$1" = "!"
+ then
+ negate="!"
+ shift
+ fi
+
+ rm -f "rerere-gc.txt" &&
+ GIT_TRACE2_EVENT="$(pwd)/rerere-gc.txt" "$@" &&
+ test_subcommand $negate git rerere gc <rerere-gc.txt
+}
+
+test_expect_success 'rerere-gc task without --auto always collects garbage' '
+ test_expect_rerere_gc git maintenance run --task=rerere-gc
+'
+
+test_expect_success 'rerere-gc task with --auto only prunes with prunable entries' '
+ test_when_finished "rm -rf .git/rr-cache" &&
+ test_expect_rerere_gc ! git maintenance run --auto --task=rerere-gc &&
+ mkdir .git/rr-cache &&
+ test_expect_rerere_gc ! git maintenance run --auto --task=rerere-gc &&
+ : >.git/rr-cache/entry &&
+ test_expect_rerere_gc git maintenance run --auto --task=rerere-gc
+'
+
+test_expect_success 'rerere-gc task with --auto honors maintenance.rerere-gc.auto' '
+ test_when_finished "rm -rf .git/rr-cache" &&
+
+ # A negative value should always prune.
+ test_expect_rerere_gc git -c maintenance.rerere-gc.auto=-1 maintenance run --auto --task=rerere-gc &&
+
+ # A positive value prunes when there is at least one entry.
+ test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc &&
+ mkdir .git/rr-cache &&
+ test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc &&
+ : >.git/rr-cache/entry-1 &&
+ test_expect_rerere_gc git -c maintenance.rerere-gc.auto=9000 maintenance run --auto --task=rerere-gc &&
+
+ # Zero should never prune.
+ : >.git/rr-cache/entry-1 &&
+ test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=0 maintenance run --auto --task=rerere-gc
+'
+
test_expect_success '--auto and --schedule incompatible' '
test_must_fail git maintenance run --auto --schedule=daily 2>err &&
- test_grep "at most one" err
+ test_grep "cannot be used together" err
+'
+
+test_expect_success '--task and --schedule incompatible' '
+ test_must_fail git maintenance run --task=pack-refs --schedule=daily 2>err &&
+ test_grep "cannot be used together" err
'
test_expect_success 'invalid --schedule value' '
diff --git a/t/t8001-annotate.sh b/t/t8001-annotate.sh
index d7167f5539..609845aeb1 100755
--- a/t/t8001-annotate.sh
+++ b/t/t8001-annotate.sh
@@ -7,6 +7,12 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping annotate tests; Perl not available'
+ test_done
+fi
+
PROG='git annotate'
. "$TEST_DIRECTORY"/annotate-tests.sh
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index 1ad039e123..7822947f02 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -7,6 +7,12 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping blame colors tests; Perl not available'
+ test_done
+fi
+
PROG='git blame -c'
. "$TEST_DIRECTORY"/annotate-tests.sh
@@ -101,7 +107,7 @@ test_expect_success 'set up abbrev tests' '
expect=$1 && shift &&
echo $sha1 | cut -c 1-$expect >expect &&
git blame "$@" abbrev.t >actual &&
- perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&
+ sed -n "s/^[\^]\{0,1\}\([0-9a-f][0-9a-f]*\).*/\1/p" actual >actual.sha &&
test_cmp expect actual.sha
}
'
@@ -138,7 +144,7 @@ test_expect_success 'blame --abbrev -b truncates the blank boundary' '
# Note that `--abbrev=` always gets incremented by 1, which is why we
# expect 11 leading spaces and not 10.
cat >expect <<-EOF &&
- $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
+ $(printf "%11s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
EOF
git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual &&
test_cmp expect actual
@@ -146,7 +152,7 @@ test_expect_success 'blame --abbrev -b truncates the blank boundary' '
test_expect_success 'blame with excessive --abbrev and -b culls to hash length' '
cat >expect <<-EOF &&
- $(printf "%0.s " $(test_seq $hexsz)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
+ $(printf "%${hexsz}s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
EOF
git blame -b --abbrev=9000 ^HEAD -- abbrev.t >actual &&
test_cmp expect actual
diff --git a/t/t8006-blame-textconv.sh b/t/t8006-blame-textconv.sh
index 07a287ffd3..db1e2afb2c 100755
--- a/t/t8006-blame-textconv.sh
+++ b/t/t8006-blame-textconv.sh
@@ -11,7 +11,7 @@ find_blame() {
cat >helper <<'EOF'
#!/bin/sh
grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
-"$PERL_PATH" -p -e 's/^bin: /converted: /' "$1"
+sed 's/^bin: /converted: /' "$1"
EOF
chmod +x helper
diff --git a/t/t8011-blame-split-file.sh b/t/t8011-blame-split-file.sh
index c66494f5ba..388057245c 100755
--- a/t/t8011-blame-split-file.sh
+++ b/t/t8011-blame-split-file.sh
@@ -81,7 +81,7 @@ do
git blame --root -C --$output combined >output
'
- test_expect_success "$output output finds correct commits" '
+ test_expect_success PERL_TEST_HELPERS "$output output finds correct commits" '
generate_expect >expect <<-\EOF &&
5 base
1 modified
@@ -93,7 +93,7 @@ do
test_cmp expect actual
'
- test_expect_success "$output output shows correct filenames" '
+ test_expect_success PERL_TEST_HELPERS "$output output shows correct filenames" '
generate_expect >expect <<-\EOF &&
11 one
11 two
@@ -102,7 +102,7 @@ do
test_cmp expect actual
'
- test_expect_success "$output output shows correct previous pointer" '
+ test_expect_success PERL_TEST_HELPERS "$output output shows correct previous pointer" '
generate_expect >expect <<-EOF &&
5 NONE
1 $(git rev-parse modified^) one
diff --git a/t/t8012-blame-colors.sh b/t/t8012-blame-colors.sh
index c3a5f6d01f..3d77352650 100755
--- a/t/t8012-blame-colors.sh
+++ b/t/t8012-blame-colors.sh
@@ -7,6 +7,12 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_CREATE_REPO_NO_TEMPLATE=1
. ./test-lib.sh
+if ! test_have_prereq PERL_TEST_HELPERS
+then
+ skip_all='skipping blame colors tests; Perl not available'
+ test_done
+fi
+
PROG='git blame -c'
. "$TEST_DIRECTORY"/annotate-tests.sh
diff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh
index 370b768149..cace00ae8d 100755
--- a/t/t8013-blame-ignore-revs.sh
+++ b/t/t8013-blame-ignore-revs.sh
@@ -158,6 +158,25 @@ test_expect_success mark_unblamable_lines '
test_cmp expect actual
'
+for opt in --porcelain --line-porcelain
+do
+ test_expect_success "mark_unblamable_lines with $opt" "
+ sha=$(git rev-parse Y) &&
+
+ git -c blame.markUnblamableLines=false blame $opt --ignore-rev Y file >raw &&
+ cat > sedscript <<- 'EOF' &&
+ /^ y3/i\\
+ unblamable
+ /^ y4/i\\
+ unblamable
+ EOF
+ sed -f sedscript raw >expect &&
+
+ git -c blame.markUnblamableLines=true blame $opt --ignore-rev Y file >actual &&
+ test_cmp expect actual
+ "
+done
+
# Commit Z will touch the first two lines. Y touched all four.
# A--B--X--Y--Z
# The blame output when ignoring Z should be:
@@ -191,6 +210,25 @@ test_expect_success mark_ignored_lines '
! test_cmp expect actual
'
+for opt in --porcelain --line-porcelain
+do
+ test_expect_success "mark_ignored_lines with $opt" "
+ sha=$(git rev-parse Y) &&
+
+ git -c blame.markIgnoredLines=false blame $opt --ignore-rev Z file >raw &&
+ cat > sedscript <<- 'EOF' &&
+ /^ line-one-Z/i\\
+ ignored
+ /^ line-two-Z/i\\
+ ignored
+ EOF
+ sed -f sedscript raw >expect &&
+
+ git -c blame.markIgnoredLines=true blame $opt --ignore-rev Z file >actual &&
+ test_cmp expect actual
+ "
+done
+
# For ignored revs that added 'unblamable' lines and more recent commits changed
# the blamable lines, mark the unblamable lines with a
# '*'
diff --git a/t/t8020-last-modified.sh b/t/t8020-last-modified.sh
new file mode 100755
index 0000000000..5eb4cef035
--- /dev/null
+++ b/t/t8020-last-modified.sh
@@ -0,0 +1,210 @@
+#!/bin/sh
+
+test_description='last-modified tests'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ test_commit 1 file &&
+ mkdir a &&
+ test_commit 2 a/file &&
+ mkdir a/b &&
+ test_commit 3 a/b/file
+'
+
+test_expect_success 'cannot run last-modified on two trees' '
+ test_must_fail git last-modified HEAD HEAD~1
+'
+
+check_last_modified() {
+ local indir= &&
+ while test $# != 0
+ do
+ case "$1" in
+ -C)
+ indir="$2"
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac &&
+ shift
+ done &&
+
+ cat >expect &&
+ test_when_finished "rm -f tmp.*" &&
+ git ${indir:+-C "$indir"} last-modified "$@" >tmp.1 &&
+ git name-rev --annotate-stdin --name-only --tags \
+ <tmp.1 >tmp.2 &&
+ tr '\t' ' ' <tmp.2 >actual &&
+ test_cmp expect actual
+}
+
+test_expect_success 'last-modified non-recursive' '
+ check_last_modified <<-\EOF
+ 3 a
+ 1 file
+ EOF
+'
+
+test_expect_success 'last-modified recursive' '
+ check_last_modified -r <<-\EOF
+ 3 a/b/file
+ 2 a/file
+ 1 file
+ EOF
+'
+
+test_expect_success 'last-modified recursive with show-trees' '
+ check_last_modified -r -t <<-\EOF
+ 3 a
+ 3 a/b
+ 3 a/b/file
+ 2 a/file
+ 1 file
+ EOF
+'
+
+test_expect_success 'last-modified non-recursive with show-trees' '
+ check_last_modified -t <<-\EOF
+ 3 a
+ 1 file
+ EOF
+'
+
+test_expect_success 'last-modified subdir' '
+ check_last_modified a <<-\EOF
+ 3 a
+ EOF
+'
+
+test_expect_success 'last-modified subdir recursive' '
+ check_last_modified -r a <<-\EOF
+ 3 a/b/file
+ 2 a/file
+ EOF
+'
+
+test_expect_success 'last-modified from non-HEAD commit' '
+ check_last_modified HEAD^ <<-\EOF
+ 2 a
+ 1 file
+ EOF
+'
+
+test_expect_success 'last-modified from subdir defaults to root' '
+ check_last_modified -C a <<-\EOF
+ 3 a
+ 1 file
+ EOF
+'
+
+test_expect_success 'last-modified from subdir uses relative pathspecs' '
+ check_last_modified -C a -r b <<-\EOF
+ 3 a/b/file
+ EOF
+'
+
+test_expect_success 'limit last-modified traversal by count' '
+ check_last_modified -1 <<-\EOF
+ 3 a
+ ^2 file
+ EOF
+'
+
+test_expect_success 'limit last-modified traversal by commit' '
+ check_last_modified HEAD~2..HEAD <<-\EOF
+ 3 a
+ ^1 file
+ EOF
+'
+
+test_expect_success 'only last-modified files in the current tree' '
+ git rm -rf a &&
+ git commit -m "remove a" &&
+ check_last_modified <<-\EOF
+ 1 file
+ EOF
+'
+
+test_expect_success 'cross merge boundaries in blaming' '
+ git checkout HEAD^0 &&
+ git rm -rf . &&
+ test_commit m1 &&
+ git checkout HEAD^ &&
+ git rm -rf . &&
+ test_commit m2 &&
+ git merge m1 &&
+ check_last_modified <<-\EOF
+ m2 m2.t
+ m1 m1.t
+ EOF
+'
+
+test_expect_success 'last-modified merge for resolved conflicts' '
+ git checkout HEAD^0 &&
+ git rm -rf . &&
+ test_commit c1 conflict &&
+ git checkout HEAD^ &&
+ git rm -rf . &&
+ test_commit c2 conflict &&
+ test_must_fail git merge c1 &&
+ test_commit resolved conflict &&
+ check_last_modified conflict <<-\EOF
+ resolved conflict
+ EOF
+'
+
+
+# Consider `file` with this content through history:
+#
+# A---B---B-------B---B
+# \ /
+# C---D
+test_expect_success 'last-modified merge ignores content from branch' '
+ git checkout HEAD^0 &&
+ git rm -rf . &&
+ test_commit a1 file A &&
+ test_commit a2 file B &&
+ test_commit a3 file C &&
+ test_commit a4 file D &&
+ git checkout a2 &&
+ git merge --no-commit --no-ff a4 &&
+ git checkout a2 -- file &&
+ git merge --continue &&
+ check_last_modified <<-\EOF
+ a2 file
+ EOF
+'
+
+# Consider `file` with this content through history:
+#
+# A---B---B---C---D---B---B
+# \ /
+# B-------B
+test_expect_success 'last-modified merge undoes changes' '
+ git checkout HEAD^0 &&
+ git rm -rf . &&
+ test_commit b1 file A &&
+ test_commit b2 file B &&
+ test_commit b3 file C &&
+ test_commit b4 file D &&
+ git checkout b2 &&
+ test_commit b5 file2 2 &&
+ git checkout b4 &&
+ git merge --no-commit --no-ff b5 &&
+ git checkout b2 -- file &&
+ git merge --continue &&
+ check_last_modified <<-\EOF
+ b5 file2
+ b2 file
+ EOF
+'
+
+test_expect_success 'last-modified complains about unknown arguments' '
+ test_must_fail git last-modified --foo 2>err &&
+ grep "unknown last-modified argument: --foo" err
+'
+
+test_done
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 0c1af43f6f..e56e0c8d77 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -201,6 +201,13 @@ test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
test_cmp expected-cc commandline1
'
+test_expect_failure $PREREQ 'invalid smtp server port value' '
+ clean_fake_sendmail &&
+ git send-email -1 --to=recipient@example.com \
+ --smtp-server-port=bogus-symbolic-name \
+ --smtp-server="$(pwd)/fake.sendmail"
+'
+
test_expect_success $PREREQ 'setup expect' "
cat >expected-show-all-headers <<\EOF
0001-Second.patch
diff --git a/t/t9003-help-autocorrect.sh b/t/t9003-help-autocorrect.sh
index 85a5074b5e..8da318d2b5 100755
--- a/t/t9003-help-autocorrect.sh
+++ b/t/t9003-help-autocorrect.sh
@@ -28,15 +28,18 @@ test_expect_success 'setup' '
test_cmp expect actual
'
-test_expect_success 'autocorrect showing candidates' '
- git config help.autocorrect 0 &&
+for show in false no off 0 show
+do
+ test_expect_success 'autocorrect showing candidates' '
+ git config help.autocorrect $show &&
- test_must_fail git lfg 2>actual &&
- grep "^ lgf" actual &&
+ test_must_fail git lfg 2>actual &&
+ grep "^ lgf" actual &&
- test_must_fail git distimdist 2>actual &&
- grep "^ distimdistim" actual
-'
+ test_must_fail git distimdist 2>actual &&
+ grep "^ distimdistim" actual
+ '
+done
for immediate in -1 immediate
do
diff --git a/t/t9137-git-svn-dcommit-clobber-series.sh b/t/t9137-git-svn-dcommit-clobber-series.sh
index 067b15bad2..b57a362bb9 100755
--- a/t/t9137-git-svn-dcommit-clobber-series.sh
+++ b/t/t9137-git-svn-dcommit-clobber-series.sh
@@ -20,8 +20,8 @@ test_expect_success '(supposedly) non-conflicting change from SVN' '
test x"$(sed -n -e 61p < file)" = x61 &&
svn_cmd co "$svnrepo" tmp &&
(cd tmp &&
- perl -i.bak -p -e "s/^58$/5588/" file &&
- perl -i.bak -p -e "s/^61$/6611/" file &&
+ sed -e "s/^58$/5588/" -e "s/^61$/6611/" file >file.munged &&
+ mv file.munged file &&
poke file &&
test x"$(sed -n -e 58p < file)" = x5588 &&
test x"$(sed -n -e 61p < file)" = x6611 &&
@@ -40,8 +40,10 @@ test_expect_success 'some unrelated changes to git' "
test_expect_success 'change file but in unrelated area' "
test x\"\$(sed -n -e 4p < file)\" = x4 &&
test x\"\$(sed -n -e 7p < file)\" = x7 &&
- perl -i.bak -p -e 's/^4\$/4444/' file &&
- perl -i.bak -p -e 's/^7\$/7777/' file &&
+ sed -e 's/^4\$/4444/' \
+ -e 's/^7\$/7777/' \
+ file >file.munged &&
+ mv file.munged file &&
test x\"\$(sed -n -e 4p < file)\" = x4444 &&
test x\"\$(sed -n -e 7p < file)\" = x7777 &&
git commit -m '4 => 4444, 7 => 7777' file &&
diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh
index a81662713e..bd6f0c40d2 100755
--- a/t/t9210-scalar.sh
+++ b/t/t9210-scalar.sh
@@ -108,7 +108,7 @@ test_expect_success 'scalar register warns when background maintenance fails' '
git init register-repo &&
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
scalar register register-repo 2>err &&
- grep "could not turn on maintenance" err
+ grep "could not toggle maintenance" err
'
test_expect_success 'scalar unregister' '
@@ -129,6 +129,17 @@ test_expect_success 'scalar unregister' '
scalar unregister vanish
'
+test_expect_success 'scalar register --no-maintenance' '
+ git init register-no-maint &&
+ event_log="$(pwd)/no-maint.event" &&
+ GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
+ GIT_TRACE2_EVENT="$event_log" \
+ GIT_TRACE2_EVENT_DEPTH=100 \
+ scalar register --no-maintenance register-no-maint 2>err &&
+ test_must_be_empty err &&
+ test_subcommand ! git maintenance unregister --force <no-maint.event
+'
+
test_expect_success 'set up repository to clone' '
test_commit first &&
test_commit second &&
@@ -199,7 +210,18 @@ test_expect_success 'scalar reconfigure' '
GIT_TRACE2_EVENT="$(pwd)/reconfigure" scalar reconfigure -a &&
test_path_is_file one/src/cron.txt &&
test true = "$(git -C one/src config core.preloadIndex)" &&
- test_subcommand git maintenance start <reconfigure
+ test_subcommand git maintenance start <reconfigure &&
+ test_subcommand ! git maintenance unregister --force <reconfigure &&
+
+ GIT_TRACE2_EVENT="$(pwd)/reconfigure-maint-disable" \
+ scalar reconfigure -a --maintenance=disable &&
+ test_subcommand ! git maintenance start <reconfigure-maint-disable &&
+ test_subcommand git maintenance unregister --force <reconfigure-maint-disable &&
+
+ GIT_TRACE2_EVENT="$(pwd)/reconfigure-maint-keep" \
+ scalar reconfigure --maintenance=keep -a &&
+ test_subcommand ! git maintenance start <reconfigure-maint-keep &&
+ test_subcommand ! git maintenance unregister --force <reconfigure-maint-keep
'
test_expect_success 'scalar reconfigure --all with includeIf.onbranch' '
diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh
index 01f71910f5..bfbf22a462 100755
--- a/t/t9211-scalar-clone.sh
+++ b/t/t9211-scalar-clone.sh
@@ -177,7 +177,16 @@ test_expect_success 'progress without tty' '
test_expect_success 'scalar clone warns when background maintenance fails' '
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
scalar clone "file://$(pwd)/to-clone" maint-fail 2>err &&
- grep "could not turn on maintenance" err
+ grep "could not toggle maintenance" err
+'
+
+test_expect_success 'scalar clone --no-maintenance' '
+ GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
+ GIT_TRACE2_EVENT="$(pwd)/no-maint.event" \
+ GIT_TRACE2_EVENT_DEPTH=100 \
+ scalar clone --no-maintenance "file://$(pwd)/to-clone" no-maint 2>err &&
+ ! grep "could not toggle maintenance" err &&
+ test_subcommand ! git maintenance unregister --force <no-maint.event
'
test_expect_success '`scalar clone --no-src`' '
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index b258dbf1df..4dc3d645bf 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -120,7 +120,7 @@ test_expect_success 'A: create pack from stdin' '
INPUT_END
git fast-import --export-marks=marks.out <input &&
- git whatchanged main
+ git log --raw main
'
test_expect_success 'A: verify pack' '
@@ -279,7 +279,7 @@ test_expect_success 'A: verify marks import does not crash' '
INPUT_END
git fast-import --import-marks=marks.out <input &&
- git whatchanged verify--import-marks
+ git log --raw verify--import-marks
'
test_expect_success 'A: verify pack' '
@@ -652,7 +652,7 @@ test_expect_success 'C: incremental import create pack from stdin' '
INPUT_END
git fast-import <input &&
- git whatchanged branch
+ git log --raw branch
'
test_expect_success 'C: verify pack' '
@@ -715,7 +715,7 @@ test_expect_success 'D: inline data in commit' '
INPUT_END
git fast-import <input &&
- git whatchanged branch
+ git log --raw branch
'
test_expect_success 'D: verify pack' '
@@ -882,7 +882,7 @@ test_expect_success 'H: deletall, add 1' '
INPUT_END
git fast-import <input &&
- git whatchanged H
+ git log --raw H
'
test_expect_success 'H: verify pack' '
@@ -2066,7 +2066,7 @@ test_expect_success 'Q: commit notes' '
INPUT_END
git fast-import <input &&
- git whatchanged notes-test
+ git log --raw notes-test
'
test_expect_success 'Q: verify pack' '
diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh
index 1ae4d7c0d3..e62173cf1f 100755
--- a/t/t9301-fast-import-notes.sh
+++ b/t/t9301-fast-import-notes.sh
@@ -76,7 +76,7 @@ INPUT_END
test_expect_success 'set up main branch' '
git fast-import <input &&
- git whatchanged main
+ git log --raw main
'
commit4=$(git rev-parse refs/heads/main)
diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
index 40427883ec..8f85c69d62 100755
--- a/t/t9350-fast-export.sh
+++ b/t/t9350-fast-export.sh
@@ -8,6 +8,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
+. "$TEST_DIRECTORY/lib-gpg.sh"
test_expect_success 'setup' '
@@ -47,12 +48,11 @@ test_expect_success 'fast-export | fast-import' '
mkdir new &&
git --git-dir=new/.git init &&
git fast-export --all >actual &&
- (cd new &&
- git fast-import &&
- test $MAIN = $(git rev-parse --verify refs/heads/main) &&
- test $REIN = $(git rev-parse --verify refs/tags/rein) &&
- test $WER = $(git rev-parse --verify refs/heads/wer) &&
- test $MUSS = $(git rev-parse --verify refs/tags/muss)) <actual
+ git -C new fast-import <actual &&
+ test $MAIN = $(git -C new rev-parse --verify refs/heads/main) &&
+ test $REIN = $(git -C new rev-parse --verify refs/tags/rein) &&
+ test $WER = $(git -C new rev-parse --verify refs/heads/wer) &&
+ test $MUSS = $(git -C new rev-parse --verify refs/tags/muss)
'
@@ -86,13 +86,11 @@ test_expect_success 'fast-export --mark-tags ^muss^{commit} muss' '
test_expect_success 'fast-export main~2..main' '
git fast-export main~2..main >actual &&
- sed "s/main/partial/" actual |
- (cd new &&
- git fast-import &&
- test $MAIN != $(git rev-parse --verify refs/heads/partial) &&
- git diff --exit-code main partial &&
- git diff --exit-code main^ partial^ &&
- test_must_fail git rev-parse partial~2)
+ sed "s/main/partial/" actual | git -C new fast-import &&
+ test $MAIN != $(git -C new rev-parse --verify refs/heads/partial) &&
+ git -C new diff --exit-code main partial &&
+ git -C new diff --exit-code main^ partial^ &&
+ test_must_fail git -C new rev-parse partial~2
'
@@ -101,10 +99,8 @@ test_expect_success 'fast-export --reference-excluded-parents main~2..main' '
git fast-export --reference-excluded-parents main~2..main >actual &&
grep commit.refs/heads/main actual >commit-count &&
test_line_count = 2 commit-count &&
- sed "s/main/rewrite/" actual |
- (cd new &&
- git fast-import &&
- test $MAIN = $(git rev-parse --verify refs/heads/rewrite))
+ sed "s/main/rewrite/" actual | git -C new fast-import &&
+ test $MAIN = $(git -C new rev-parse --verify refs/heads/rewrite)
'
test_expect_success 'fast-export --show-original-ids' '
@@ -132,20 +128,19 @@ test_expect_success ICONV 'reencoding iso-8859-7' '
echo rosten >file &&
git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
- sed "s/wer/i18n/" iso-8859-7.fi |
- (cd new &&
- git fast-import &&
- # 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 $(($(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 &&
- # Also make sure the commit does not have the "encoding" header
- ! grep ^encoding actual)
+ sed "s/wer/i18n/" iso-8859-7.fi | git -C new fast-import &&
+
+ # 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 $(($(test_oid hexsz) + 181)) -eq "$(git -C new cat-file -s i18n)" &&
+ # ...and for the expected translation of bytes.
+ git -C new cat-file commit i18n >actual &&
+ grep $(printf "\317\200") actual &&
+ # Also make sure the commit does not have the "encoding" header
+ ! grep ^encoding actual
'
test_expect_success 'aborting on iso-8859-7' '
@@ -164,20 +159,19 @@ test_expect_success 'preserving iso-8859-7' '
echo rosten >file &&
git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
git fast-export --reencode=no wer^..wer >iso-8859-7.fi &&
- sed "s/wer/i18n-no-recoding/" iso-8859-7.fi |
- (cd new &&
- git fast-import &&
- # 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 $(($(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 &&
- # Also make sure the commit has the "encoding" header
- grep ^encoding actual)
+ sed "s/wer/i18n-no-recoding/" iso-8859-7.fi | git -C new fast-import &&
+
+ # 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 $(($(test_oid hexsz) + 200)) -eq "$(git -C new cat-file -s i18n-no-recoding)" &&
+ # ...as well as the expected byte.
+ git -C new cat-file commit i18n-no-recoding >actual &&
+ grep $(printf "\360") actual &&
+ # Also make sure the commit has the "encoding" header
+ grep ^encoding actual
'
test_expect_success 'encoding preserved if reencoding fails' '
@@ -187,18 +181,17 @@ test_expect_success 'encoding preserved if reencoding fails' '
echo rosten >file &&
git commit -s -F "$TEST_DIRECTORY/t9350/broken-iso-8859-7-commit-message.txt" file &&
git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
- sed "s/wer/i18n-invalid/" iso-8859-7.fi |
- (cd new &&
- git fast-import &&
- git cat-file commit i18n-invalid >actual &&
- # Make sure the commit still has the encoding header
- grep ^encoding actual &&
- # Verify that the commit has the expected size; i.e.
- # that no bytes were re-encoded to a different encoding.
- 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)
+ sed "s/wer/i18n-invalid/" iso-8859-7.fi | git -C new fast-import &&
+ git -C new cat-file commit i18n-invalid >actual &&
+
+ # Make sure the commit still has the encoding header
+ grep ^encoding actual &&
+ # Verify that the commit has the expected size; i.e.
+ # that no bytes were re-encoded to a different encoding.
+ test $(($(test_oid hexsz) + 212)) -eq "$(git -C new cat-file -s i18n-invalid)" &&
+ # ...and check for the original special bytes
+ grep $(printf "\360") actual &&
+ grep $(printf "\377") actual
'
test_expect_success 'import/export-marks' '
@@ -253,6 +246,24 @@ test_expect_success 'signed-tags=verbatim' '
'
+test_expect_success 'signed-tags=warn-verbatim' '
+
+ git fast-export --signed-tags=warn-verbatim sign-your-name >output 2>err &&
+ grep PGP output &&
+ test -s err
+
+'
+
+# 'warn' is a backward-compatibility alias for 'warn-verbatim'; test
+# that it keeps working.
+test_expect_success 'signed-tags=warn' '
+
+ git fast-export --signed-tags=warn sign-your-name >output 2>err &&
+ grep PGP output &&
+ test -s err
+
+'
+
test_expect_success 'signed-tags=strip' '
git fast-export --signed-tags=strip sign-your-name > output &&
@@ -266,10 +277,133 @@ test_expect_success 'signed-tags=warn-strip' '
test -s err
'
+test_expect_success GPG 'set up signed commit' '
+
+ # Generate a commit with both "gpgsig" and "encoding" set, so
+ # that we can test that fast-import gets the ordering correct
+ # between the two.
+ test_config i18n.commitEncoding ISO-8859-1 &&
+ git checkout -f -b commit-signing main &&
+ echo Sign your name >file-sign &&
+ git add file-sign &&
+ git commit -S -m "signed commit" &&
+ COMMIT_SIGNING=$(git rev-parse --verify commit-signing)
+
+'
+
+test_expect_success GPG 'signed-commits default is same as strip' '
+ git fast-export --reencode=no commit-signing >out1 2>err &&
+ git fast-export --reencode=no --signed-commits=strip commit-signing >out2 &&
+ test_cmp out1 out2
+'
+
+test_expect_success GPG 'signed-commits=abort' '
+
+ test_must_fail git fast-export --signed-commits=abort commit-signing
+
+'
+
+test_expect_success GPG 'signed-commits=verbatim' '
+
+ git fast-export --signed-commits=verbatim --reencode=no commit-signing >output &&
+ test_grep -E "^gpgsig $GIT_DEFAULT_HASH openpgp" output &&
+ grep "encoding ISO-8859-1" output &&
+ git -C new fast-import <output &&
+ STRIPPED=$(git -C new rev-parse --verify refs/heads/commit-signing) &&
+ test $COMMIT_SIGNING = $STRIPPED
+
+'
+
+test_expect_success GPG 'signed-commits=warn-verbatim' '
+
+ git fast-export --signed-commits=warn-verbatim --reencode=no commit-signing >output 2>err &&
+ test_grep -E "^gpgsig $GIT_DEFAULT_HASH openpgp" output &&
+ grep "encoding ISO-8859-1" output &&
+ test -s err &&
+ git -C new fast-import <output &&
+ STRIPPED=$(git -C new rev-parse --verify refs/heads/commit-signing) &&
+ test $COMMIT_SIGNING = $STRIPPED
+
+'
+
+test_expect_success GPG 'signed-commits=strip' '
+
+ git fast-export --signed-commits=strip --reencode=no commit-signing >output &&
+ ! grep ^gpgsig output &&
+ grep "^encoding ISO-8859-1" output &&
+ sed "s/commit-signing/commit-strip-signing/" output | git -C new fast-import &&
+ STRIPPED=$(git -C new rev-parse --verify refs/heads/commit-strip-signing) &&
+ test $COMMIT_SIGNING != $STRIPPED
+
+'
+
+test_expect_success GPG 'signed-commits=warn-strip' '
+
+ git fast-export --signed-commits=warn-strip --reencode=no commit-signing >output 2>err &&
+ ! grep ^gpgsig output &&
+ grep "^encoding ISO-8859-1" output &&
+ test -s err &&
+ sed "s/commit-signing/commit-strip-signing/" output | git -C new fast-import &&
+ STRIPPED=$(git -C new rev-parse --verify refs/heads/commit-strip-signing) &&
+ test $COMMIT_SIGNING != $STRIPPED
+
+'
+
+test_expect_success GPGSM 'setup X.509 signed commit' '
+
+ git checkout -b x509-signing main &&
+ test_config gpg.format x509 &&
+ test_config user.signingkey $GIT_COMMITTER_EMAIL &&
+ echo "X.509 content" >file &&
+ git add file &&
+ git commit -S -m "X.509 signed commit" &&
+ X509_COMMIT=$(git rev-parse HEAD) &&
+ git checkout main
+
+'
+
+test_expect_success GPGSM 'round-trip X.509 signed commit' '
+
+ git fast-export --signed-commits=verbatim x509-signing >output &&
+ test_grep -E "^gpgsig $GIT_DEFAULT_HASH x509" output &&
+ git -C new fast-import <output &&
+ git -C new cat-file commit refs/heads/x509-signing >actual &&
+ grep "^gpgsig" actual &&
+ IMPORTED=$(git -C new rev-parse refs/heads/x509-signing) &&
+ test $X509_COMMIT = $IMPORTED
+
+'
+
+test_expect_success GPGSSH 'setup SSH signed commit' '
+
+ git checkout -b ssh-signing main &&
+ test_config gpg.format ssh &&
+ test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
+ echo "SSH content" >file &&
+ git add file &&
+ git commit -S -m "SSH signed commit" &&
+ SSH_COMMIT=$(git rev-parse HEAD) &&
+ git checkout main
+
+'
+
+test_expect_success GPGSSH 'round-trip SSH signed commit' '
+
+ git fast-export --signed-commits=verbatim ssh-signing >output &&
+ test_grep -E "^gpgsig $GIT_DEFAULT_HASH ssh" output &&
+ git -C new fast-import <output &&
+ git -C new cat-file commit refs/heads/ssh-signing >actual &&
+ grep "^gpgsig" actual &&
+ IMPORTED=$(git -C new rev-parse refs/heads/ssh-signing) &&
+ test $SSH_COMMIT = $IMPORTED
+
+'
+
test_expect_success 'setup submodule' '
test_config_global protocol.file.allow always &&
git checkout -f main &&
+ test_might_fail git update-ref -d refs/heads/commit-signing &&
mkdir sub &&
(
cd sub &&
@@ -301,14 +435,13 @@ test_expect_success 'submodule fast-export | fast-import' '
mkdir new &&
git --git-dir=new/.git init &&
git fast-export --signed-tags=strip --all >actual &&
- (cd new &&
- git fast-import &&
- test "$SUBENT1" = "$(git ls-tree refs/heads/main^ sub)" &&
- test "$SUBENT2" = "$(git ls-tree refs/heads/main sub)" &&
- git checkout main &&
- git submodule init &&
- git submodule update &&
- cmp sub/file ../sub/file) <actual
+ git -C new fast-import <actual &&
+ test "$SUBENT1" = "$(git -C new ls-tree refs/heads/main^ sub)" &&
+ test "$SUBENT2" = "$(git -C new ls-tree refs/heads/main sub)" &&
+ git -C new checkout main &&
+ git -C new submodule init &&
+ git -C new submodule update &&
+ cmp new/sub/file sub/file
'
@@ -350,10 +483,8 @@ test_expect_success 'fast-export -C -C | fast-import' '
git --git-dir=new/.git init &&
git fast-export -C -C --signed-tags=strip --all > output &&
grep "^C file2 file4\$" output &&
- cat output |
- (cd new &&
- git fast-import &&
- test $ENTRY = $(git rev-parse --verify refs/heads/copy))
+ git -C new fast-import <output &&
+ test $ENTRY = $(git -C new rev-parse --verify refs/heads/copy)
'
@@ -610,7 +741,7 @@ test_expect_success 'directory becomes symlink' '
(cd result && git show main:foo)
'
-test_expect_success 'fast-export quotes pathnames' '
+test_expect_success PERL_TEST_HELPERS 'fast-export quotes pathnames' '
git init crazy-paths &&
test_config -C crazy-paths core.protectNTFS false &&
(cd crazy-paths &&
@@ -801,4 +932,42 @@ test_expect_success 'fast-export handles --end-of-options' '
test_cmp expect actual
'
+test_expect_success GPG 'setup a commit with dual signatures on its SHA-1 and SHA-256 formats' '
+ # Create a signed SHA-256 commit
+ git init --object-format=sha256 explicit-sha256 &&
+ git -C explicit-sha256 config extensions.compatObjectFormat sha1 &&
+ git -C explicit-sha256 checkout -b dual-signed &&
+ test_commit -C explicit-sha256 A &&
+ echo B >explicit-sha256/B &&
+ git -C explicit-sha256 add B &&
+ test_tick &&
+ git -C explicit-sha256 commit -S -m "signed" B &&
+ SHA256_B=$(git -C explicit-sha256 rev-parse dual-signed) &&
+
+ # Create the corresponding SHA-1 commit
+ SHA1_B=$(git -C explicit-sha256 rev-parse --output-object-format=sha1 dual-signed) &&
+
+ # Check that the resulting SHA-1 commit has both signatures
+ echo $SHA1_B | git -C explicit-sha256 cat-file --batch >out &&
+ test_grep -E "^gpgsig " out &&
+ test_grep -E "^gpgsig-sha256 " out
+'
+
+test_expect_success GPG 'export and import of doubly signed commit' '
+ git -C explicit-sha256 fast-export --signed-commits=verbatim dual-signed >output &&
+ test_grep -E "^gpgsig sha1 openpgp" output &&
+ test_grep -E "^gpgsig sha256 openpgp" output &&
+ git -C new fast-import <output &&
+ git -C new cat-file commit refs/heads/dual-signed >actual &&
+ test_grep -E "^gpgsig " actual &&
+ test_grep -E "^gpgsig-sha256 " actual &&
+ IMPORTED=$(git -C new rev-parse refs/heads/dual-signed) &&
+ if test "$GIT_DEFAULT_HASH" = "sha1"
+ then
+ test $SHA1_B = $IMPORTED
+ else
+ test $SHA256_B = $IMPORTED
+ fi
+'
+
test_done
diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index 7679780fb8..578d6c8b32 100755
--- a/t/t9500-gitweb-standalone-no-errors.sh
+++ b/t/t9500-gitweb-standalone-no-errors.sh
@@ -700,19 +700,17 @@ test_expect_success \
# ----------------------------------------------------------------------
# syntax highlighting
+test_lazy_prereq HIGHLIGHT '
+ highlight_version=$(highlight --version </dev/null 2>/dev/null) &&
+ test -n "$highlight_version"
+'
-highlight_version=$(highlight --version </dev/null 2>/dev/null)
-if [ $? -eq 127 ]; then
- say "Skipping syntax highlighting tests: 'highlight' not found"
-elif test -z "$highlight_version"; then
- say "Skipping syntax highlighting tests: incorrect 'highlight' found"
-else
- test_set_prereq HIGHLIGHT
+test_expect_success HIGHLIGHT '
cat >>gitweb_config.perl <<-\EOF
our $highlight_bin = "highlight";
- $feature{'highlight'}{'override'} = 1;
+ $feature{"highlight"}{"override"} = 1;
EOF
-fi
+'
test_expect_success HIGHLIGHT \
'syntax highlighting (no highlight, unknown syntax)' \
diff --git a/t/t9811-git-p4-label-import.sh b/t/t9811-git-p4-label-import.sh
index 5ac5383fb7..7614dfbd95 100755
--- a/t/t9811-git-p4-label-import.sh
+++ b/t/t9811-git-p4-label-import.sh
@@ -95,9 +95,8 @@ test_expect_success 'two labels on the same changelist' '
cd "$git" &&
git p4 sync --import-labels &&
- git tag | grep TAG_F1 &&
- git tag | grep -q TAG_F1_1 &&
- git tag | grep -q TAG_F1_2 &&
+ git show-ref --verify refs/tags/TAG_F1_1 &&
+ git show-ref --verify refs/tags/TAG_F1_2 &&
cd main &&
@@ -207,8 +206,7 @@ test_expect_success 'use git config to enable import/export of tags' '
git tag CFG_A_GIT_TAG &&
git p4 rebase --verbose &&
git p4 submit --verbose &&
- git tag &&
- git tag | grep TAG_F1_1
+ git show-ref --verify refs/tags/TAG_F1_1
) &&
(
cd "$cli" &&
diff --git a/t/t9822-git-p4-path-encoding.sh b/t/t9822-git-p4-path-encoding.sh
index 572d395498..e6e07facd4 100755
--- a/t/t9822-git-p4-path-encoding.sh
+++ b/t/t9822-git-p4-path-encoding.sh
@@ -7,12 +7,17 @@ test_description='Clone repositories with non ASCII paths'
UTF8_ESCAPED="a-\303\244_o-\303\266_u-\303\274.txt"
ISO8859_ESCAPED="a-\344_o-\366_u-\374.txt"
-ISO8859="$(printf "$ISO8859_ESCAPED")" &&
-echo content123 >"$ISO8859" &&
-rm "$ISO8859" || {
+test_lazy_prereq FS_ACCEPTS_ISO_8859_1 '
+ ISO8859="$(printf "$ISO8859_ESCAPED")" &&
+ echo content123 >"$ISO8859" &&
+ rm "$ISO8859"
+'
+
+if ! test_have_prereq FS_ACCEPTS_ISO_8859_1
+then
skip_all="fs does not accept ISO-8859-1 filenames"
test_done
-}
+fi
test_expect_success 'start p4d' '
start_p4d
diff --git a/t/t9835-git-p4-metadata-encoding-python2.sh b/t/t9835-git-p4-metadata-encoding-python2.sh
index 6116f806f6..b969c7e0d5 100755
--- a/t/t9835-git-p4-metadata-encoding-python2.sh
+++ b/t/t9835-git-p4-metadata-encoding-python2.sh
@@ -12,23 +12,25 @@ failing, and produces maximally sane output in git.'
## SECTION REPEATED IN t9836 ##
###############################
+EXTRA_PATH="$(pwd)/temp_python"
+mkdir "$EXTRA_PATH"
+PATH="$EXTRA_PATH:$PATH"
+export PATH
+
# These tests are specific to Python 2. Write a custom script that executes
# git-p4 directly with the Python 2 interpreter to ensure that we use that
# version even if Git was compiled with Python 3.
-python_target_binary=$(which python2)
-if test -n "$python_target_binary"
-then
- mkdir temp_python
- PATH="$(pwd)/temp_python:$PATH"
- export PATH
-
- write_script temp_python/git-p4-python2 <<-EOF
+test_lazy_prereq P4_PYTHON2 '
+ python_target_binary=$(which python2) &&
+ test -n "$python_target_binary" &&
+ write_script "$EXTRA_PATH"/git-p4-python2 <<-EOF &&
exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
EOF
-fi
+ ( git p4-python2 || true ) >err &&
+ test_grep "valid commands" err
+'
-git p4-python2 >err
-if ! grep 'valid commands' err
+if ! test_have_prereq P4_PYTHON2
then
skip_all="skipping python2 git p4 tests; python2 not available"
test_done
diff --git a/t/t9836-git-p4-metadata-encoding-python3.sh b/t/t9836-git-p4-metadata-encoding-python3.sh
index 5e5217a66b..da6669bf71 100755
--- a/t/t9836-git-p4-metadata-encoding-python3.sh
+++ b/t/t9836-git-p4-metadata-encoding-python3.sh
@@ -12,23 +12,25 @@ failing, and produces maximally sane output in git.'
## SECTION REPEATED IN t9835 ##
###############################
+EXTRA_PATH="$(pwd)/temp_python"
+mkdir "$EXTRA_PATH"
+PATH="$EXTRA_PATH:$PATH"
+export PATH
+
# These tests are specific to Python 3. Write a custom script that executes
# git-p4 directly with the Python 3 interpreter to ensure that we use that
# version even if Git was compiled with Python 2.
-python_target_binary=$(which python3)
-if test -n "$python_target_binary"
-then
- mkdir temp_python
- PATH="$(pwd)/temp_python:$PATH"
- export PATH
-
- write_script temp_python/git-p4-python3 <<-EOF
+test_lazy_prereq P4_PYTHON3 '
+ python_target_binary=$(which python3) &&
+ test -n "$python_target_binary" &&
+ write_script "$EXTRA_PATH"/git-p4-python3 <<-EOF &&
exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@"
EOF
-fi
+ ( git p4-python3 || true ) >err &&
+ test_grep "valid commands" err
+'
-git p4-python3 >err
-if ! grep 'valid commands' err
+if ! test_have_prereq P4_PYTHON3
then
skip_all="skipping python3 git p4 tests; python3 not available"
test_done
diff --git a/t/t9850-shell.sh b/t/t9850-shell.sh
index 36566ace21..21c3af48bd 100755
--- a/t/t9850-shell.sh
+++ b/t/t9850-shell.sh
@@ -30,7 +30,7 @@ test_expect_success 'shell allows interactive command' '
'
test_expect_success 'shell complains of overlong commands' '
- perl -e "print \"a\" x 2**12 for (0..2**19)" |
+ test-tool genzeros | tr "\000" "a" |
test_must_fail git shell 2>err &&
grep "too long" err
'
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 51bd750837..6650d33fba 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -149,7 +149,8 @@ fi
test_expect_success 'setup for __git_find_repo_path/__gitdir tests' '
mkdir -p subdir/subsubdir &&
mkdir -p non-repo &&
- git init -b main otherrepo
+ git init -b main otherrepo &&
+ git init -b main slashrepo
'
test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' '
@@ -455,6 +456,32 @@ test_expect_success '__git_dequote - open double quote' '
'
+test_expect_success '__git_count_path_components - no slashes' '
+ echo 1 >expected &&
+ __git_count_path_components a >"$actual" &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__git_count_path_components - relative' '
+ echo 3 >expected &&
+ __git_count_path_components a/b/c >"$actual" &&
+ test_cmp expected "$actual"
+
+'
+
+test_expect_success '__git_count_path_components - absolute' '
+ echo 3 >expected &&
+ __git_count_path_components /a/b/c >"$actual" &&
+ test_cmp expected "$actual"
+'
+
+test_expect_success '__git_count_path_components - trailing slash' '
+ echo 3 >expected &&
+ __git_count_path_components a/b/c/ >"$actual" &&
+ test_cmp expected "$actual"
+'
+
+
test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '
sed -e "s/Z$//g" >expected <<-EOF &&
with-trailing-space Z
@@ -648,6 +675,13 @@ test_expect_success 'setup for ref completion' '
) &&
git remote add other "$ROOT/otherrepo/.git" &&
git fetch --no-tags other &&
+ (
+ cd slashrepo &&
+ git commit --allow-empty -m initial &&
+ git branch -m main branch/with/slash
+ ) &&
+ git remote add remote/with/slash "$ROOT/slashrepo/.git" &&
+ git fetch --no-tags remote/with/slash &&
rm -f .git/FETCH_HEAD &&
git init thirdrepo
'
@@ -660,6 +694,8 @@ test_expect_success '__git_refs - simple' '
other/HEAD
other/branch-in-other
other/main-in-other
+ remote/with/slash/HEAD
+ remote/with/slash/branch/with/slash
matching-tag
EOF
(
@@ -676,6 +712,8 @@ test_expect_success '__git_refs - full refs' '
refs/remotes/other/HEAD
refs/remotes/other/branch-in-other
refs/remotes/other/main-in-other
+ refs/remotes/remote/with/slash/HEAD
+ refs/remotes/remote/with/slash/branch/with/slash
refs/tags/matching-tag
EOF
(
@@ -741,6 +779,19 @@ test_expect_success '__git_refs - configured remote' '
test_cmp expected "$actual"
'
+test_expect_success '__git_refs - configured remote - with slash' '
+ cat >expected <<-EOF &&
+ HEAD
+ HEAD
+ branch/with/slash
+ EOF
+ (
+ cur= &&
+ __git_refs remote/with/slash >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
test_expect_success '__git_refs - configured remote - full refs' '
cat >expected <<-EOF &&
HEAD
@@ -883,17 +934,19 @@ test_expect_success '__git_refs - unique remote branches for git checkout DWIMer
other/ambiguous
other/branch-in-other
other/main-in-other
- remote/ambiguous
- remote/branch-in-remote
+ remote/with/slash/HEAD
+ remote/with/slash/ambiguous
+ remote/with/slash/branch-in-remote
+ remote/with/slash/branch/with/slash
matching-tag
- HEAD
branch-in-other
branch-in-remote
+ branch/with/slash
main-in-other
EOF
for remote_ref in refs/remotes/other/ambiguous \
- refs/remotes/remote/ambiguous \
- refs/remotes/remote/branch-in-remote
+ refs/remotes/remote/with/slash/ambiguous \
+ refs/remotes/remote/with/slash/branch-in-remote
do
git update-ref $remote_ref main &&
test_when_finished "git update-ref -d $remote_ref" || return 1
@@ -913,6 +966,8 @@ test_expect_success '__git_refs - after --opt=' '
other/HEAD
other/branch-in-other
other/main-in-other
+ remote/with/slash/HEAD
+ remote/with/slash/branch/with/slash
matching-tag
EOF
(
@@ -929,6 +984,8 @@ test_expect_success '__git_refs - after --opt= - full refs' '
refs/remotes/other/HEAD
refs/remotes/other/branch-in-other
refs/remotes/other/main-in-other
+ refs/remotes/remote/with/slash/HEAD
+ refs/remotes/remote/with/slash/branch/with/slash
refs/tags/matching-tag
EOF
(
@@ -946,6 +1003,8 @@ test_expect_success '__git refs - excluding refs' '
^other/HEAD
^other/branch-in-other
^other/main-in-other
+ ^remote/with/slash/HEAD
+ ^remote/with/slash/branch/with/slash
^matching-tag
EOF
(
@@ -962,6 +1021,8 @@ test_expect_success '__git refs - excluding full refs' '
^refs/remotes/other/HEAD
^refs/remotes/other/branch-in-other
^refs/remotes/other/main-in-other
+ ^refs/remotes/remote/with/slash/HEAD
+ ^refs/remotes/remote/with/slash/branch/with/slash
^refs/tags/matching-tag
EOF
(
@@ -989,6 +1050,8 @@ test_expect_success '__git_refs - do not filter refs unless told so' '
other/branch-in-other
other/main-in-other
other/matching/branch-in-other
+ remote/with/slash/HEAD
+ remote/with/slash/branch/with/slash
matching-tag
matching/tag
EOF
@@ -1109,6 +1172,8 @@ test_expect_success '__git_complete_refs - simple' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
matching-tag Z
EOF
(
@@ -1147,6 +1212,20 @@ test_expect_success '__git_complete_refs - remote' '
test_cmp expected out
'
+test_expect_success '__git_complete_refs - remote - with slash' '
+ sed -e "s/Z$//" >expected <<-EOF &&
+ HEAD Z
+ HEAD Z
+ branch/with/slash Z
+ EOF
+ (
+ cur= &&
+ __git_complete_refs --remote=remote/with/slash &&
+ print_comp
+ ) &&
+ test_cmp expected out
+'
+
test_expect_success '__git_complete_refs - track' '
sed -e "s/Z$//" >expected <<-EOF &&
HEAD Z
@@ -1155,9 +1234,11 @@ test_expect_success '__git_complete_refs - track' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
matching-tag Z
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main-in-other Z
EOF
(
@@ -1202,6 +1283,8 @@ test_expect_success '__git_complete_refs - suffix' '
other/HEAD.
other/branch-in-other.
other/main-in-other.
+ remote/with/slash/HEAD.
+ remote/with/slash/branch/with/slash.
matching-tag.
EOF
(
@@ -1227,6 +1310,20 @@ test_expect_success '__git_complete_fetch_refspecs - simple' '
test_cmp expected out
'
+test_expect_success '__git_complete_fetch_refspecs - with slash' '
+ sed -e "s/Z$//" >expected <<-EOF &&
+ HEAD:HEAD Z
+ HEAD:HEAD Z
+ branch/with/slash:branch/with/slash Z
+ EOF
+ (
+ cur= &&
+ __git_complete_fetch_refspecs remote/with/slash &&
+ print_comp
+ ) &&
+ test_cmp expected out
+'
+
test_expect_success '__git_complete_fetch_refspecs - matching' '
sed -e "s/Z$//" >expected <<-EOF &&
branch-in-other:branch-in-other Z
@@ -1307,8 +1404,8 @@ test_expect_success '__git_complete_worktree_paths with -C' '
test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' '
test_completion "git switch " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -1454,8 +1551,8 @@ test_expect_success 'git-bisect - existing view subcommand is recognized and ena
test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' '
test_completion "git checkout " <<-\EOF
HEAD Z
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -1463,6 +1560,8 @@ test_expect_success 'git checkout - completes refs and unique remote branches fo
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1482,8 +1581,8 @@ test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, compl
test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' '
GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -1492,8 +1591,8 @@ test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_G
test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' '
test_completion "git switch --no-guess --guess " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -1516,14 +1615,16 @@ test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only complete
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' '
GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF
HEAD Z
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -1531,6 +1632,8 @@ test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1,
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1543,14 +1646,16 @@ test_expect_success 'git checkout - with --no-guess, only completes refs' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' '
test_completion "git checkout --no-guess --guess " <<-\EOF
HEAD Z
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -1558,6 +1663,8 @@ test_expect_success 'git checkout - a later --guess overrides previous --no-gues
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1570,6 +1677,8 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1583,6 +1692,8 @@ test_expect_success 'git checkout - with checkout.guess = false, only completes
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1590,8 +1701,8 @@ test_expect_success 'git checkout - with checkout.guess = true, completes refs a
test_config checkout.guess true &&
test_completion "git checkout " <<-\EOF
HEAD Z
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -1599,6 +1710,8 @@ test_expect_success 'git checkout - with checkout.guess = true, completes refs a
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1606,8 +1719,8 @@ test_expect_success 'git checkout - a later --guess overrides previous checkout.
test_config checkout.guess false &&
test_completion "git checkout --guess " <<-\EOF
HEAD Z
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -1615,6 +1728,8 @@ test_expect_success 'git checkout - a later --guess overrides previous checkout.
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1628,6 +1743,8 @@ test_expect_success 'git checkout - a later --no-guess overrides previous checko
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1640,6 +1757,8 @@ test_expect_success 'git switch - with --detach, complete all references' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1652,6 +1771,8 @@ test_expect_success 'git checkout - with --detach, complete only references' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1824,6 +1945,8 @@ test_expect_success 'git switch - with -d, complete all references' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1836,6 +1959,8 @@ test_expect_success 'git checkout - with -d, complete only references' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1844,11 +1969,15 @@ test_expect_success 'git switch - with --track, complete only remote branches' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
test_completion "git switch -t " <<-\EOF
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1857,11 +1986,15 @@ test_expect_success 'git checkout - with --track, complete only remote branches'
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
test_completion "git checkout -t " <<-\EOF
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1881,6 +2014,8 @@ test_expect_success 'git checkout - with --no-track, complete only local referen
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1893,6 +2028,8 @@ test_expect_success 'git switch - with -c, complete all references' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1905,6 +2042,8 @@ test_expect_success 'git switch - with -C, complete all references' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1917,6 +2056,8 @@ test_expect_success 'git switch - with -c and --track, complete all references'
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1929,6 +2070,8 @@ test_expect_success 'git switch - with -C and --track, complete all references'
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1941,6 +2084,8 @@ test_expect_success 'git switch - with -c and --no-track, complete all reference
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1953,6 +2098,8 @@ test_expect_success 'git switch - with -C and --no-track, complete all reference
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1965,6 +2112,8 @@ test_expect_success 'git checkout - with -b, complete all references' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1977,6 +2126,8 @@ test_expect_success 'git checkout - with -B, complete all references' '
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -1989,6 +2140,8 @@ test_expect_success 'git checkout - with -b and --track, complete all references
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -2001,6 +2154,8 @@ test_expect_success 'git checkout - with -B and --track, complete all references
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -2013,6 +2168,8 @@ test_expect_success 'git checkout - with -b and --no-track, complete all referen
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -2025,13 +2182,15 @@ test_expect_success 'git checkout - with -B and --no-track, complete all referen
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
test_expect_success 'git switch - for -c, complete local branches and unique remote branches' '
test_completion "git switch -c " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -2040,8 +2199,8 @@ test_expect_success 'git switch - for -c, complete local branches and unique rem
test_expect_success 'git switch - for -C, complete local branches and unique remote branches' '
test_completion "git switch -C " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -2078,8 +2237,8 @@ test_expect_success 'git switch - for -C with --no-track, complete local branche
test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' '
test_completion "git checkout -b " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -2088,8 +2247,8 @@ test_expect_success 'git checkout - for -b, complete local branches and unique r
test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' '
test_completion "git checkout -B " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -2126,8 +2285,8 @@ test_expect_success 'git checkout - for -B with --no-track, complete local branc
test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' '
test_completion "git switch --orphan " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -2142,8 +2301,8 @@ test_expect_success 'git switch - --orphan with branch already provided complete
test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' '
test_completion "git checkout --orphan " <<-\EOF
- HEAD Z
branch-in-other Z
+ branch/with/slash Z
main Z
main-in-other Z
matching-branch Z
@@ -2159,6 +2318,8 @@ test_expect_success 'git checkout - --orphan with branch already provided comple
other/HEAD Z
other/branch-in-other Z
other/main-in-other Z
+ remote/with/slash/HEAD Z
+ remote/with/slash/branch/with/slash Z
EOF
'
@@ -2173,7 +2334,8 @@ test_expect_success 'git restore completes modified files' '
test_expect_success 'teardown after ref completion' '
git branch -d matching-branch &&
git tag -d matching-tag &&
- git remote remove other
+ git remote remove other &&
+ git remote remove remote/with/slash
'
@@ -2434,6 +2596,8 @@ test_expect_success 'double dash "git checkout"' '
--merge Z
--conflict=Z
--patch Z
+ --unified=Z
+ --inter-hunk-context=Z
--ignore-skip-worktree-bits Z
--ignore-other-worktrees Z
--recurse-submodules Z
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index d667dda654..637a6f13a6 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -66,10 +66,6 @@ test_expect_success 'prompt - unborn branch' '
test_cmp expected "$actual"
'
-if test_have_prereq !FUNNYNAMES; then
- say 'Your filesystem does not allow newlines in filenames.'
-fi
-
test_expect_success FUNNYNAMES 'prompt - with newline in path' '
repo_with_newline="repo
with
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 78e054ab50..a28de7b19b 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -88,15 +88,15 @@ test_decode_color () {
}
lf_to_nul () {
- perl -pe 'y/\012/\000/'
+ tr '\012' '\000'
}
nul_to_q () {
- perl -pe 'y/\000/Q/'
+ tr '\000' 'Q'
}
q_to_nul () {
- perl -pe 'y/Q/\000/'
+ tr 'Q' '\000'
}
q_to_cr () {
@@ -773,6 +773,8 @@ mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&
rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1"
if test "$eval_ret" = 0; then
say >&3 "prerequisite $1 ok"
+ elif test "$eval_ret" = 125; then
+ :;
else
say >&3 "prerequisite $1 not satisfied"
fi
@@ -811,6 +813,9 @@ test_have_prereq () {
if test_run_lazy_prereq_ "$prerequisite" "$script"
then
test_set_prereq $prerequisite
+ elif test $? = 125
+ then
+ BUG "Do not use $prerequisite"
fi
lazily_tested_prereq="$lazily_tested_prereq$prerequisite "
esac
@@ -927,7 +932,7 @@ test_expect_success () {
test -n "$test_skip_test_preamble" ||
say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $test_body"
if test_run_ "$test_body" &&
- check_test_results_san_file_empty_
+ ! check_test_results_san_file_has_entries_
then
test_ok_ "$1"
else
@@ -1268,6 +1273,16 @@ test_cmp () {
eval "$GIT_TEST_CMP" '"$@"'
}
+# test_cmp_sorted runs test_cmp on sorted versions of the two
+# input files. Uses "$1.sorted" and "$2.sorted" as temp files.
+
+test_cmp_sorted () {
+ sort <"$1" >"$1.sorted" &&
+ sort <"$2" >"$2.sorted" &&
+ test_cmp "$1.sorted" "$2.sorted" &&
+ rm "$1.sorted" "$2.sorted"
+}
+
# Check that the given config key has the expected value.
#
# test_cmp_config [-C <dir>] <expected-value>
@@ -1436,9 +1451,21 @@ test_cmp_fspath () {
# test_seq 1 5 -- outputs 1 2 3 4 5 one line at a time
#
# or with one argument (end), in which case it starts counting
-# from 1.
+# from 1. In addition to the start/end arguments, you can pass an optional
+# printf format. For example:
+#
+# test_seq -f "line %d" 1 5
+#
+# would print 5 lines, "line 1" through "line 5".
test_seq () {
+ local fmt="%d"
+ case "$1" in
+ -f)
+ fmt="$2"
+ shift 2
+ ;;
+ esac
case $# in
1) set 1 "$@" ;;
2) ;;
@@ -1447,7 +1474,7 @@ test_seq () {
test_seq_counter__=$1
while test "$test_seq_counter__" -le "$2"
do
- echo "$test_seq_counter__"
+ printf "$fmt\n" "$test_seq_counter__"
test_seq_counter__=$(( $test_seq_counter__ + 1 ))
done
}
@@ -1630,17 +1657,7 @@ test_match_signal () {
# Read up to "$1" bytes (or to EOF) from stdin and write them to stdout.
test_copy_bytes () {
- perl -e '
- my $len = $ARGV[1];
- while ($len > 0) {
- my $s;
- my $nread = sysread(STDIN, $s, $len);
- die "cannot read: $!" unless defined($nread);
- last unless $nread;
- print $s;
- $len -= $nread;
- }
- ' - "$1"
+ dd ibs=1 count="$1" 2>/dev/null
}
# run "$@" inside a non-git directory
@@ -1690,7 +1707,7 @@ test_set_hash () {
# Detect the hash algorithm in use.
test_detect_hash () {
- case "$GIT_TEST_DEFAULT_HASH" in
+ case "${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}" in
"sha256")
test_hash_algo=sha256
test_compat_hash_algo=sha1
@@ -1762,6 +1779,9 @@ test_oid () {
--hash=compat)
algo="$test_compat_hash_algo" &&
shift;;
+ --hash=builtin)
+ algo="$GIT_TEST_BUILTIN_HASH" &&
+ shift;;
--hash=*)
algo="${1#--hash=}" &&
shift;;
@@ -1886,6 +1906,32 @@ test_subcommand () {
fi
}
+# Check that the given subcommand was run with the given set of
+# arguments in order (but with possible extra arguments).
+#
+# test_subcommand_flex [!] <command> <args>... < <trace>
+#
+# If the first parameter passed is !, this instead checks that
+# the given command was not called.
+#
+test_subcommand_flex () {
+ local negate=
+ if test "$1" = "!"
+ then
+ negate=t
+ shift
+ fi
+
+ local expr="$(printf '"%s".*' "$@")"
+
+ if test -n "$negate"
+ then
+ ! grep "\[$expr\]"
+ else
+ grep "\[$expr\]"
+ fi
+}
+
# Check that the given command was invoked as part of the
# trace2-format trace on stdin.
#
@@ -1953,7 +1999,7 @@ test_remote_https_urls() {
# Print the destination of symlink(s) provided as arguments. Basically
# the same as the readlink command, but it's not available everywhere.
test_readlink () {
- perl -le 'print readlink($_) for @ARGV' "$@"
+ test-tool path-utils readlink "$@"
}
# Set mtime to a fixed "magic" timestamp in mid February 2009, before we
@@ -2007,3 +2053,11 @@ test_trailing_hash () {
test-tool hexdump |
sed "s/ //g"
}
+
+# Trim and replace each character with ascii code below 32 or above
+# 127 (included) using a dot '.' character.
+# Octal intervals \001-\040 and \177-\377
+# correspond to decimal intervals 1-32 and 127-255
+test_redact_non_printables () {
+ tr -d "\n\r" | tr "[\001-\040][\177-\377]" "."
+}
diff --git a/t/test-lib.sh b/t/test-lib.sh
index d1f62adbf8..621cd31ae1 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -134,7 +134,8 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
################################################################
# It appears that people try to run tests without building...
-"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
+GIT_BINARY="${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X"
+"$GIT_BINARY" >/dev/null
if test $? != 1
then
if test -n "$GIT_TEST_INSTALLED"
@@ -470,7 +471,7 @@ then
then
: Executed by a Bash version supporting BASH_XTRACEFD. Good.
else
- echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
+ echo >&2 "# warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
trace=
fi
fi
@@ -499,24 +500,20 @@ EDITOR=:
# /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
# deriving from the command substitution clustered with the other
# ones.
-unset VISUAL EMAIL LANGUAGE $("$PERL_PATH" -e '
- my @env = keys %ENV;
- my $ok = join("|", qw(
- TRACE
- DEBUG
- TEST
- .*_TEST
- PROVE
- VALGRIND
- UNZIP
- PERF_
- CURL_VERBOSE
- TRACE_CURL
- BUILD_DIR
- ));
- my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
- print join("\n", @vars);
-')
+unset VISUAL EMAIL LANGUAGE $(env | sed -n \
+ -e '/^GIT_TRACE/d' \
+ -e '/^GIT_DEBUG/d' \
+ -e '/^GIT_TEST/d' \
+ -e '/^GIT_.*_TEST/d' \
+ -e '/^GIT_PROVE/d' \
+ -e '/^GIT_VALGRIND/d' \
+ -e '/^GIT_UNZIP/d' \
+ -e '/^GIT_PERF_/d' \
+ -e '/^GIT_CURL_VERBOSE/d' \
+ -e '/^GIT_TRACE_CURL/d' \
+ -e '/^GIT_BUILD_DIR/d' \
+ -e 's/^\(GIT_[^=]*\)=.*/\1/p'
+)
unset XDG_CACHE_HOME
unset XDG_CONFIG_HOME
unset GITPERLLIB
@@ -540,12 +537,11 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
export EDITOR
-GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-sha1}"
+GIT_TEST_BUILTIN_HASH=$("$GIT_BINARY" version --build-options | sed -ne 's/^default-hash: //p')
+GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}"
export GIT_DEFAULT_HASH
GIT_DEFAULT_REF_FORMAT="${GIT_TEST_DEFAULT_REF_FORMAT:-files}"
export GIT_DEFAULT_REF_FORMAT
-GIT_TEST_MERGE_ALGORITHM="${GIT_TEST_MERGE_ALGORITHM:-ort}"
-export GIT_TEST_MERGE_ALGORITHM
# Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
GIT_TRACE_BARE=1
@@ -713,7 +709,7 @@ then
exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3
elif test "$verbose" = "t"
then
- exec 4>&2 3>&1
+ exec 4>&2 3>&2
else
exec 4>/dev/null 3>/dev/null
fi
@@ -955,7 +951,7 @@ maybe_setup_verbose () {
test -z "$verbose_only" && return
if match_pattern_list $test_count "$verbose_only"
then
- exec 4>&2 3>&1
+ exec 4>&2 3>&2
# Emit a delimiting blank line when going from
# non-verbose to verbose. Within verbose mode the
# delimiter is printed by test_expect_*. The choice
@@ -1169,20 +1165,20 @@ test_atexit_handler () {
teardown_malloc_check
}
-check_test_results_san_file_empty_ () {
- test -z "$TEST_RESULTS_SAN_FILE" && return 0
+check_test_results_san_file_has_entries_ () {
+ test -z "$TEST_RESULTS_SAN_FILE" && return 1
- # stderr piped to /dev/null because the directory may have
- # been "rmdir"'d already.
- ! find "$TEST_RESULTS_SAN_DIR" \
- -type f \
- -name "$TEST_RESULTS_SAN_FILE_PFX.*" 2>/dev/null |
- xargs grep ^DEDUP_TOKEN |
+ # Lines marked with DEDUP_TOKEN show unique leaks. We only care that we
+ # found at least one.
+ #
+ # But also suppress any false positives caused by bugs or races in the
+ # sanitizer itself.
+ grep -s ^DEDUP_TOKEN "$TEST_RESULTS_SAN_FILE".* |
grep -qv sanitizer::GetThreadStackTopAndBottom
}
check_test_results_san_file_ () {
- if check_test_results_san_file_empty_
+ if ! check_test_results_san_file_has_entries_
then
return
fi &&
@@ -1278,7 +1274,14 @@ test_done () {
check_test_results_san_file_ "$test_failure"
- if test -z "$skip_all" && test -n "$invert_exit_code"
+ if test "$test_fixed" != 0
+ then
+ if test -z "$invert_exit_code"
+ then
+ GIT_EXIT_OK=t
+ exit 1
+ fi
+ elif test -z "$skip_all" && test -n "$invert_exit_code"
then
say_color warn "# faking up non-zero exit with --invert-exit-code"
GIT_EXIT_OK=t
@@ -1523,6 +1526,22 @@ then
export LSAN_OPTIONS
fi
+if test -z "$PERL_PATH"
+then
+ case "${GIT_TEST_CHAIN_LINT:-unset}" in
+ unset)
+ GIT_TEST_CHAIN_LINT=0
+ ;;
+ 0)
+ # The user has explicitly disabled the chain linter, so we
+ # don't have anything to worry about.
+ ;;
+ *)
+ BAIL_OUT 'You need Perl for the chain linter'
+ ;;
+ esac
+fi
+
if test "${GIT_TEST_CHAIN_LINT:-1}" != 0 &&
test "${GIT_TEST_EXT_CHAIN_LINT:-1}" != 0
then
@@ -1567,6 +1586,8 @@ fi
# Use -P to resolve symlinks in our working directory so that the cwd
# in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$TRASH_DIRECTORY" || BAIL_OUT "cannot cd -P to \"$TRASH_DIRECTORY\""
+TRASH_DIRECTORY=$(pwd)
+HOME="$TRASH_DIRECTORY"
start_test_output "$0"
@@ -1626,6 +1647,12 @@ fi
# Fix some commands on Windows, and other OS-specific things
uname_s=$(uname -s)
case $uname_s in
+Darwin)
+ test_set_prereq MACOS
+ test_set_prereq POSIXPERM
+ test_set_prereq BSLASHPSPEC
+ test_set_prereq EXECKEEPSPID
+ ;;
*MINGW*)
# Windows has its own (incompatible) sort and find
sort () {
@@ -1694,6 +1721,7 @@ test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK
test -n "$GIT_VALGRIND_ENABLED" && test_set_prereq VALGRIND
+test -n "$PERL_PATH" && test_set_prereq PERL_TEST_HELPERS
if test -z "$GIT_TEST_CHECK_CACHE_TREE"
then
@@ -1862,6 +1890,15 @@ test_lazy_prereq CURL '
curl --version
'
+test_lazy_prereq WITH_BREAKING_CHANGES '
+ test -n "$WITH_BREAKING_CHANGES"
+'
+
+test_lazy_prereq WITHOUT_BREAKING_CHANGES '
+ # Signal that this prereq should not be used.
+ exit 125
+'
+
# SHA1 is a test if the hash algorithm in use is SHA-1. This is both for tests
# 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).
@@ -1873,6 +1910,10 @@ test_lazy_prereq SHA1 '
esac
'
+test_lazy_prereq DEFAULT_HASH_ALGORITHM '
+ test "$GIT_TEST_BUILTIN_HASH" = "$GIT_DEFAULT_HASH"
+'
+
test_lazy_prereq DEFAULT_REPO_FORMAT '
test_have_prereq SHA1,REFFILES
'
diff --git a/t/unit-tests/clar/clar.c b/t/unit-tests/clar/clar.c
index d54e455367..03a3aa8e87 100644
--- a/t/unit-tests/clar/clar.c
+++ b/t/unit-tests/clar/clar.c
@@ -350,7 +350,7 @@ static void
clar_run_suite(const struct clar_suite *suite, const char *filter)
{
const struct clar_func *test = suite->tests;
- size_t i, matchlen;
+ size_t i, matchlen = 0;
struct clar_report *report;
int exact = 0;
diff --git a/t/unit-tests/clar/clar/fs.h b/t/unit-tests/clar/clar/fs.h
index 8b206179fc..2203743fb4 100644
--- a/t/unit-tests/clar/clar/fs.h
+++ b/t/unit-tests/clar/clar/fs.h
@@ -376,9 +376,12 @@ fs_copydir_helper(const char *source, const char *dest, int dest_mode)
mkdir(dest, dest_mode);
cl_assert_(source_dir = opendir(source), "Could not open source dir");
- while ((d = (errno = 0, readdir(source_dir))) != NULL) {
+ for (;;) {
char *child;
+ errno = 0;
+ if ((d = readdir(source_dir)) == NULL)
+ break;
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;
@@ -479,9 +482,12 @@ fs_rmdir_helper(const char *path)
struct dirent *d;
cl_assert_(dir = opendir(path), "Could not open dir");
- while ((d = (errno = 0, readdir(dir))) != NULL) {
+ for (;;) {
char *child;
+ errno = 0;
+ if ((d = readdir(dir)) == NULL)
+ break;
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;
diff --git a/t/unit-tests/generate-clar-decls.sh b/t/unit-tests/generate-clar-decls.sh
index 3b315c64b3..abf6a2ea2a 100755
--- a/t/unit-tests/generate-clar-decls.sh
+++ b/t/unit-tests/generate-clar-decls.sh
@@ -14,6 +14,7 @@ do
suite_name=$(basename "$suite")
suite_name=${suite_name%.c}
suite_name=${suite_name#u-}
+ suite_name=$(echo "$suite_name" | tr '-' '_')
sed -ne "s/^\(void test_${suite_name}__[a-zA-Z_0-9][a-zA-Z_0-9]*(void)\)$/extern \1;/p" "$suite" ||
exit 1
done >"$OUTPUT"
diff --git a/t/unit-tests/lib-oid.c b/t/unit-tests/lib-oid.c
index 8f0ccac532..e0b3180f23 100644
--- a/t/unit-tests/lib-oid.c
+++ b/t/unit-tests/lib-oid.c
@@ -1,9 +1,9 @@
-#include "test-lib.h"
+#include "unit-test.h"
#include "lib-oid.h"
#include "strbuf.h"
#include "hex.h"
-int init_hash_algo(void)
+int cl_setup_hash_algo(void)
{
static int algo = -1;
@@ -11,42 +11,32 @@ int init_hash_algo(void)
const char *algo_name = getenv("GIT_TEST_DEFAULT_HASH");
algo = algo_name ? hash_algo_by_name(algo_name) : GIT_HASH_SHA1;
- if (!check(algo != GIT_HASH_UNKNOWN))
- test_msg("BUG: invalid GIT_TEST_DEFAULT_HASH value ('%s')",
- algo_name);
+ cl_assert(algo != GIT_HASH_UNKNOWN);
}
return algo;
}
-static int get_oid_arbitrary_hex_algop(const char *hex, struct object_id *oid,
+static void cl_parse_oid(const char *hex, struct object_id *oid,
const struct git_hash_algo *algop)
{
- int ret;
size_t sz = strlen(hex);
struct strbuf buf = STRBUF_INIT;
- if (!check(sz <= algop->hexsz)) {
- test_msg("BUG: hex string (%s) bigger than maximum allowed (%lu)",
- hex, (unsigned long)algop->hexsz);
- return -1;
- }
+ cl_assert(sz <= algop->hexsz);
strbuf_add(&buf, hex, sz);
strbuf_addchars(&buf, '0', algop->hexsz - sz);
- ret = get_oid_hex_algop(buf.buf, oid, algop);
- if (!check_int(ret, ==, 0))
- test_msg("BUG: invalid hex input (%s) provided", hex);
+ cl_assert_equal_i(get_oid_hex_algop(buf.buf, oid, algop), 0);
strbuf_release(&buf);
- return ret;
}
-int get_oid_arbitrary_hex(const char *hex, struct object_id *oid)
+
+void cl_parse_any_oid(const char *hex, struct object_id *oid)
{
- int hash_algo = init_hash_algo();
+ int hash_algo = cl_setup_hash_algo();
- if (!check_int(hash_algo, !=, GIT_HASH_UNKNOWN))
- return -1;
- return get_oid_arbitrary_hex_algop(hex, oid, &hash_algos[hash_algo]);
+ cl_assert(hash_algo != GIT_HASH_UNKNOWN);
+ cl_parse_oid(hex, oid, &hash_algos[hash_algo]);
}
diff --git a/t/unit-tests/lib-oid.h b/t/unit-tests/lib-oid.h
index 4e77c04bd2..4031775104 100644
--- a/t/unit-tests/lib-oid.h
+++ b/t/unit-tests/lib-oid.h
@@ -5,6 +5,7 @@
/*
* Convert arbitrary hex string to object_id.
+ *
* For example, passing "abc12" will generate
* "abc1200000000000000000000000000000000000" hex of length 40 for SHA-1 and
* create object_id with that.
@@ -12,14 +13,16 @@
* algo is not allowed. The hash algo is decided based on GIT_TEST_DEFAULT_HASH
* environment variable.
*/
-int get_oid_arbitrary_hex(const char *s, struct object_id *oid);
+
+void cl_parse_any_oid (const char *s, struct object_id *oid);
/*
* Returns one of GIT_HASH_{SHA1, SHA256, UNKNOWN} based on the value of
* GIT_TEST_DEFAULT_HASH environment variable. The fallback value in the
* absence of GIT_TEST_DEFAULT_HASH is GIT_HASH_SHA1. It also uses
- * check(algo != GIT_HASH_UNKNOWN) before returning to verify if the
+ * cl_assert(algo != GIT_HASH_UNKNOWN) before returning to verify if the
* GIT_TEST_DEFAULT_HASH's value is valid or not.
*/
-int init_hash_algo(void);
+
+int cl_setup_hash_algo(void);
#endif /* LIB_OID_H */
diff --git a/t/unit-tests/lib-reftable.c b/t/unit-tests/lib-reftable.c
index 8a69612266..fdb5b11a20 100644
--- a/t/unit-tests/lib-reftable.c
+++ b/t/unit-tests/lib-reftable.c
@@ -1,12 +1,14 @@
-#define DISABLE_SIGN_COMPARE_WARNINGS
-
+#include "unit-test.h"
#include "lib-reftable.h"
-#include "test-lib.h"
+#include "hex.h"
+#include "parse-options.h"
#include "reftable/constants.h"
#include "reftable/writer.h"
#include "strbuf.h"
+#include "string-list.h"
+#include "strvec.h"
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
{
memset(p, (uint8_t)i, hash_size(id));
}
@@ -22,17 +24,17 @@ static int strbuf_writer_flush(void *arg UNUSED)
return 0;
}
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
struct reftable_write_options *opts)
{
struct reftable_writer *writer;
int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush,
buf, opts);
- check(!ret);
+ cl_assert(!ret);
return writer;
}
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
struct reftable_ref_record *refs,
size_t nrefs,
struct reftable_log_record *logs,
@@ -64,35 +66,36 @@ void t_reftable_write_to_buf(struct reftable_buf *buf,
min = ui;
}
- writer = t_reftable_strbuf_writer(buf, &opts);
- reftable_writer_set_limits(writer, min, max);
+ writer = cl_reftable_strbuf_writer(buf, &opts);
+ ret = reftable_writer_set_limits(writer, min, max);
+ cl_assert(!ret);
if (nrefs) {
ret = reftable_writer_add_refs(writer, refs, nrefs);
- check_int(ret, ==, 0);
+ cl_assert_equal_i(ret, 0);
}
if (nlogs) {
ret = reftable_writer_add_logs(writer, logs, nlogs);
- check_int(ret, ==, 0);
+ cl_assert_equal_i(ret, 0);
}
ret = reftable_writer_close(writer);
- check_int(ret, ==, 0);
+ cl_assert_equal_i(ret, 0);
stats = reftable_writer_stats(writer);
- for (size_t i = 0; i < stats->ref_stats.blocks; i++) {
+ for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) {
size_t off = i * (opts.block_size ? opts.block_size
: DEFAULT_BLOCK_SIZE);
if (!off)
off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
- check_char(buf->buf[off], ==, 'r');
+ cl_assert(buf->buf[off] == 'r');
}
if (nrefs)
- check_int(stats->ref_stats.blocks, >, 0);
+ cl_assert(stats->ref_stats.blocks > 0);
if (nlogs)
- check_int(stats->log_stats.blocks, >, 0);
+ cl_assert(stats->log_stats.blocks > 0);
reftable_writer_free(writer);
}
diff --git a/t/unit-tests/lib-reftable.h b/t/unit-tests/lib-reftable.h
index e4c360fa7e..d7e6d3136f 100644
--- a/t/unit-tests/lib-reftable.h
+++ b/t/unit-tests/lib-reftable.h
@@ -1,21 +1,20 @@
-#ifndef LIB_REFTABLE_H
-#define LIB_REFTABLE_H
-
+#include "git-compat-util.h"
+#include "clar/clar.h"
+#include "clar-decls.h"
#include "git-compat-util.h"
#include "reftable/reftable-writer.h"
+#include "strbuf.h"
struct reftable_buf;
-void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
+void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
-struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
+struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
struct reftable_write_options *opts);
-void t_reftable_write_to_buf(struct reftable_buf *buf,
+void cl_reftable_write_to_buf(struct reftable_buf *buf,
struct reftable_ref_record *refs,
size_t nrecords,
struct reftable_log_record *logs,
size_t nlogs,
struct reftable_write_options *opts);
-
-#endif
diff --git a/t/unit-tests/t-example-decorate.c b/t/unit-tests/t-example-decorate.c
deleted file mode 100644
index bfc776e223..0000000000
--- a/t/unit-tests/t-example-decorate.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
-#include "test-lib.h"
-#include "object.h"
-#include "decorate.h"
-#include "repository.h"
-
-struct test_vars {
- struct object *one, *two, *three;
- struct decoration n;
- int decoration_a, decoration_b;
-};
-
-static void t_add(struct test_vars *vars)
-{
- void *ret = add_decoration(&vars->n, vars->one, &vars->decoration_a);
-
- check(ret == NULL);
- ret = add_decoration(&vars->n, vars->two, NULL);
- check(ret == NULL);
-}
-
-static void t_readd(struct test_vars *vars)
-{
- void *ret = add_decoration(&vars->n, vars->one, NULL);
-
- check(ret == &vars->decoration_a);
- ret = add_decoration(&vars->n, vars->two, &vars->decoration_b);
- check(ret == NULL);
-}
-
-static void t_lookup(struct test_vars *vars)
-{
- void *ret = lookup_decoration(&vars->n, vars->one);
-
- check(ret == NULL);
- ret = lookup_decoration(&vars->n, vars->two);
- check(ret == &vars->decoration_b);
- ret = lookup_decoration(&vars->n, vars->three);
- check(ret == NULL);
-}
-
-static void t_loop(struct test_vars *vars)
-{
- int objects_noticed = 0;
-
- for (size_t i = 0; i < vars->n.size; i++) {
- if (vars->n.entries[i].base)
- objects_noticed++;
- }
- check_int(objects_noticed, ==, 2);
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- struct object_id one_oid = { { 1 } }, two_oid = { { 2 } }, three_oid = { { 3 } };
- struct test_vars vars = { 0 };
-
- vars.one = lookup_unknown_object(the_repository, &one_oid);
- vars.two = lookup_unknown_object(the_repository, &two_oid);
- vars.three = lookup_unknown_object(the_repository, &three_oid);
-
- TEST(t_add(&vars),
- "Add 2 objects, one with a non-NULL decoration and one with a NULL decoration.");
- TEST(t_readd(&vars),
- "When re-adding an already existing object, the old decoration is returned.");
- TEST(t_lookup(&vars),
- "Lookup returns the added declarations, or NULL if the object was never added.");
- TEST(t_loop(&vars), "The user can also loop through all entries.");
-
- clear_decoration(&vars.n, NULL);
-
- return test_done();
-}
diff --git a/t/unit-tests/t-mem-pool.c b/t/unit-tests/t-mem-pool.c
deleted file mode 100644
index fe500c704b..0000000000
--- a/t/unit-tests/t-mem-pool.c
+++ /dev/null
@@ -1,31 +0,0 @@
-#include "test-lib.h"
-#include "mem-pool.h"
-
-static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc)
-{
- struct mem_pool pool = { .block_alloc = block_alloc };
- f(&pool);
- mem_pool_discard(&pool, 0);
-}
-
-static void t_calloc_100(struct mem_pool *pool)
-{
- size_t size = 100;
- char *buffer = mem_pool_calloc(pool, 1, size);
- for (size_t i = 0; i < size; i++)
- check_int(buffer[i], ==, 0);
- if (!check(pool->mp_block != NULL))
- return;
- check(pool->mp_block->next_free != NULL);
- check(pool->mp_block->end != NULL);
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- TEST(setup_static(t_calloc_100, 1024 * 1024),
- "mem_pool_calloc returns 100 zeroed bytes with big block");
- TEST(setup_static(t_calloc_100, 1),
- "mem_pool_calloc returns 100 zeroed bytes with tiny block");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-oid-array.c b/t/unit-tests/t-oid-array.c
deleted file mode 100644
index 45b59a2a51..0000000000
--- a/t/unit-tests/t-oid-array.c
+++ /dev/null
@@ -1,126 +0,0 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
-#include "test-lib.h"
-#include "lib-oid.h"
-#include "oid-array.h"
-#include "hex.h"
-
-static int fill_array(struct oid_array *array, const char *hexes[], size_t n)
-{
- for (size_t i = 0; i < n; i++) {
- struct object_id oid;
-
- if (!check_int(get_oid_arbitrary_hex(hexes[i], &oid), ==, 0))
- return -1;
- oid_array_append(array, &oid);
- }
- if (!check_uint(array->nr, ==, n))
- return -1;
- return 0;
-}
-
-static int add_to_oid_array(const struct object_id *oid, void *data)
-{
- struct oid_array *array = data;
-
- oid_array_append(array, oid);
- return 0;
-}
-
-static void t_enumeration(const char **input_args, size_t input_sz,
- const char **expect_args, size_t expect_sz)
-{
- struct oid_array input = OID_ARRAY_INIT, expect = OID_ARRAY_INIT,
- actual = OID_ARRAY_INIT;
- size_t i;
-
- if (fill_array(&input, input_args, input_sz))
- return;
- if (fill_array(&expect, expect_args, expect_sz))
- return;
-
- oid_array_for_each_unique(&input, add_to_oid_array, &actual);
- if (!check_uint(actual.nr, ==, expect.nr))
- return;
-
- for (i = 0; i < actual.nr; i++) {
- if (!check(oideq(&actual.oid[i], &expect.oid[i])))
- test_msg("expected: %s\n got: %s\n index: %" PRIuMAX,
- oid_to_hex(&expect.oid[i]), oid_to_hex(&actual.oid[i]),
- (uintmax_t)i);
- }
-
- oid_array_clear(&actual);
- oid_array_clear(&input);
- oid_array_clear(&expect);
-}
-
-#define TEST_ENUMERATION(input, expect, desc) \
- TEST(t_enumeration(input, ARRAY_SIZE(input), expect, ARRAY_SIZE(expect)), \
- desc " works")
-
-static void t_lookup(const char **input_hexes, size_t n, const char *query_hex,
- int lower_bound, int upper_bound)
-{
- struct oid_array array = OID_ARRAY_INIT;
- struct object_id oid_query;
- int ret;
-
- if (!check_int(get_oid_arbitrary_hex(query_hex, &oid_query), ==, 0))
- return;
- if (fill_array(&array, input_hexes, n))
- return;
- ret = oid_array_lookup(&array, &oid_query);
-
- if (!check_int(ret, <=, upper_bound) ||
- !check_int(ret, >=, lower_bound))
- test_msg("oid query for lookup: %s", oid_to_hex(&oid_query));
-
- oid_array_clear(&array);
-}
-
-#define TEST_LOOKUP(input_hexes, query, lower_bound, upper_bound, desc) \
- TEST(t_lookup(input_hexes, ARRAY_SIZE(input_hexes), query, \
- lower_bound, upper_bound), \
- desc " works")
-
-static void setup(void)
-{
- /* The hash algo is used by oid_array_lookup() internally */
- int algo = init_hash_algo();
- if (check_int(algo, !=, GIT_HASH_UNKNOWN))
- repo_set_hash_algo(the_repository, algo);
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- const char *arr_input[] = { "88", "44", "aa", "55" };
- const char *arr_input_dup[] = { "88", "44", "aa", "55",
- "88", "44", "aa", "55",
- "88", "44", "aa", "55" };
- const char *res_sorted[] = { "44", "55", "88", "aa" };
- const char *nearly_55;
-
- if (!TEST(setup(), "setup"))
- test_skip_all("hash algo initialization failed");
-
- TEST_ENUMERATION(arr_input, res_sorted, "ordered enumeration");
- TEST_ENUMERATION(arr_input_dup, res_sorted,
- "ordered enumeration with duplicate suppression");
-
- TEST_LOOKUP(arr_input, "55", 1, 1, "lookup");
- TEST_LOOKUP(arr_input, "33", INT_MIN, -1, "lookup non-existent entry");
- TEST_LOOKUP(arr_input_dup, "55", 3, 5, "lookup with duplicates");
- TEST_LOOKUP(arr_input_dup, "66", INT_MIN, -1,
- "lookup non-existent entry with duplicates");
-
- nearly_55 = init_hash_algo() == GIT_HASH_SHA1 ?
- "5500000000000000000000000000000000000001" :
- "5500000000000000000000000000000000000000000000000000000000000001";
- TEST_LOOKUP(((const char *[]){ "55", nearly_55 }), "55", 0, 0,
- "lookup with almost duplicate values");
- TEST_LOOKUP(((const char *[]){ "55", "55" }), "55", 0, 1,
- "lookup with single duplicate value");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-oidmap.c b/t/unit-tests/t-oidmap.c
deleted file mode 100644
index b22e52d08b..0000000000
--- a/t/unit-tests/t-oidmap.c
+++ /dev/null
@@ -1,181 +0,0 @@
-#include "test-lib.h"
-#include "lib-oid.h"
-#include "oidmap.h"
-#include "hash.h"
-#include "hex.h"
-
-/*
- * Elements we will put in oidmap structs are made of a key: the entry.oid
- * field, which is of type struct object_id, and a value: the name field (could
- * be a refname for example).
- */
-struct test_entry {
- struct oidmap_entry entry;
- char name[FLEX_ARRAY];
-};
-
-static const char *const key_val[][2] = { { "11", "one" },
- { "22", "two" },
- { "33", "three" } };
-
-static void setup(void (*f)(struct oidmap *map))
-{
- struct oidmap map = OIDMAP_INIT;
- int ret = 0;
-
- for (size_t i = 0; i < ARRAY_SIZE(key_val); i++){
- struct test_entry *entry;
-
- FLEX_ALLOC_STR(entry, name, key_val[i][1]);
- if ((ret = get_oid_arbitrary_hex(key_val[i][0], &entry->entry.oid))) {
- free(entry);
- break;
- }
- entry = oidmap_put(&map, entry);
- if (!check(entry == NULL))
- free(entry);
- }
-
- if (!ret)
- f(&map);
- oidmap_free(&map, 1);
-}
-
-static void t_replace(struct oidmap *map)
-{
- struct test_entry *entry, *prev;
-
- FLEX_ALLOC_STR(entry, name, "un");
- if (get_oid_arbitrary_hex("11", &entry->entry.oid))
- return;
- prev = oidmap_put(map, entry);
- if (!check(prev != NULL))
- return;
- check_str(prev->name, "one");
- free(prev);
-
- FLEX_ALLOC_STR(entry, name, "deux");
- if (get_oid_arbitrary_hex("22", &entry->entry.oid))
- return;
- prev = oidmap_put(map, entry);
- if (!check(prev != NULL))
- return;
- check_str(prev->name, "two");
- free(prev);
-}
-
-static void t_get(struct oidmap *map)
-{
- struct test_entry *entry;
- struct object_id oid;
-
- if (get_oid_arbitrary_hex("22", &oid))
- return;
- entry = oidmap_get(map, &oid);
- if (!check(entry != NULL))
- return;
- check_str(entry->name, "two");
-
- if (get_oid_arbitrary_hex("44", &oid))
- return;
- check(oidmap_get(map, &oid) == NULL);
-
- if (get_oid_arbitrary_hex("11", &oid))
- return;
- entry = oidmap_get(map, &oid);
- if (!check(entry != NULL))
- return;
- check_str(entry->name, "one");
-}
-
-static void t_remove(struct oidmap *map)
-{
- struct test_entry *entry;
- struct object_id oid;
-
- if (get_oid_arbitrary_hex("11", &oid))
- return;
- entry = oidmap_remove(map, &oid);
- if (!check(entry != NULL))
- return;
- check_str(entry->name, "one");
- check(oidmap_get(map, &oid) == NULL);
- free(entry);
-
- if (get_oid_arbitrary_hex("22", &oid))
- return;
- entry = oidmap_remove(map, &oid);
- if (!check(entry != NULL))
- return;
- check_str(entry->name, "two");
- check(oidmap_get(map, &oid) == NULL);
- free(entry);
-
- if (get_oid_arbitrary_hex("44", &oid))
- return;
- check(oidmap_remove(map, &oid) == NULL);
-}
-
-static int key_val_contains(struct test_entry *entry, char seen[])
-{
- for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
- struct object_id oid;
-
- if (get_oid_arbitrary_hex(key_val[i][0], &oid))
- return -1;
-
- if (oideq(&entry->entry.oid, &oid)) {
- if (seen[i])
- return 2;
- seen[i] = 1;
- return 0;
- }
- }
- return 1;
-}
-
-static void t_iterate(struct oidmap *map)
-{
- struct oidmap_iter iter;
- struct test_entry *entry;
- char seen[ARRAY_SIZE(key_val)] = { 0 };
- int count = 0;
-
- oidmap_iter_init(map, &iter);
- while ((entry = oidmap_iter_next(&iter))) {
- int ret;
- if (!check_int((ret = key_val_contains(entry, seen)), ==, 0)) {
- switch (ret) {
- case -1:
- break; /* error message handled by get_oid_arbitrary_hex() */
- case 1:
- test_msg("obtained entry was not given in the input\n"
- " name: %s\n oid: %s\n",
- entry->name, oid_to_hex(&entry->entry.oid));
- break;
- case 2:
- test_msg("duplicate entry detected\n"
- " name: %s\n oid: %s\n",
- entry->name, oid_to_hex(&entry->entry.oid));
- break;
- default:
- test_msg("BUG: invalid return value (%d) from key_val_contains()",
- ret);
- break;
- }
- } else {
- count++;
- }
- }
- check_int(count, ==, ARRAY_SIZE(key_val));
- check_int(hashmap_get_size(&map->map), ==, ARRAY_SIZE(key_val));
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- TEST(setup(t_replace), "replace works");
- TEST(setup(t_get), "get works");
- TEST(setup(t_remove), "remove works");
- TEST(setup(t_iterate), "iterate works");
- return test_done();
-}
diff --git a/t/unit-tests/t-oidtree.c b/t/unit-tests/t-oidtree.c
deleted file mode 100644
index a38754b066..0000000000
--- a/t/unit-tests/t-oidtree.c
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "test-lib.h"
-#include "lib-oid.h"
-#include "oidtree.h"
-#include "hash.h"
-#include "hex.h"
-#include "strvec.h"
-
-#define FILL_TREE(tree, ...) \
- do { \
- const char *hexes[] = { __VA_ARGS__ }; \
- if (fill_tree_loc(tree, hexes, ARRAY_SIZE(hexes))) \
- return; \
- } while (0)
-
-static int fill_tree_loc(struct oidtree *ot, const char *hexes[], size_t n)
-{
- for (size_t i = 0; i < n; i++) {
- struct object_id oid;
- if (!check_int(get_oid_arbitrary_hex(hexes[i], &oid), ==, 0))
- return -1;
- oidtree_insert(ot, &oid);
- }
- return 0;
-}
-
-static void check_contains(struct oidtree *ot, const char *hex, int expected)
-{
- struct object_id oid;
-
- if (!check_int(get_oid_arbitrary_hex(hex, &oid), ==, 0))
- return;
- if (!check_int(oidtree_contains(ot, &oid), ==, expected))
- test_msg("oid: %s", oid_to_hex(&oid));
-}
-
-struct expected_hex_iter {
- size_t i;
- struct strvec expected_hexes;
- const char *query;
-};
-
-static enum cb_next check_each_cb(const struct object_id *oid, void *data)
-{
- struct expected_hex_iter *hex_iter = data;
- struct object_id expected;
-
- if (!check_int(hex_iter->i, <, hex_iter->expected_hexes.nr)) {
- test_msg("error: extraneous callback for query: ('%s'), object_id: ('%s')",
- hex_iter->query, oid_to_hex(oid));
- return CB_BREAK;
- }
-
- if (!check_int(get_oid_arbitrary_hex(hex_iter->expected_hexes.v[hex_iter->i],
- &expected), ==, 0))
- ; /* the data is bogus and cannot be used */
- else if (!check(oideq(oid, &expected)))
- test_msg("expected: %s\n got: %s\n query: %s",
- oid_to_hex(&expected), oid_to_hex(oid), hex_iter->query);
-
- hex_iter->i += 1;
- return CB_CONTINUE;
-}
-
-LAST_ARG_MUST_BE_NULL
-static void check_each(struct oidtree *ot, const char *query, ...)
-{
- struct object_id oid;
- struct expected_hex_iter hex_iter = { .expected_hexes = STRVEC_INIT,
- .query = query };
- const char *arg;
- va_list hex_args;
-
- va_start(hex_args, query);
- while ((arg = va_arg(hex_args, const char *)))
- strvec_push(&hex_iter.expected_hexes, arg);
- va_end(hex_args);
-
- if (!check_int(get_oid_arbitrary_hex(query, &oid), ==, 0))
- return;
- oidtree_each(ot, &oid, strlen(query), check_each_cb, &hex_iter);
-
- if (!check_int(hex_iter.i, ==, hex_iter.expected_hexes.nr))
- test_msg("error: could not find some 'object_id's for query ('%s')", query);
- strvec_clear(&hex_iter.expected_hexes);
-}
-
-static void setup(void (*f)(struct oidtree *ot))
-{
- struct oidtree ot;
-
- oidtree_init(&ot);
- f(&ot);
- oidtree_clear(&ot);
-}
-
-static void t_contains(struct oidtree *ot)
-{
- FILL_TREE(ot, "444", "1", "2", "3", "4", "5", "a", "b", "c", "d", "e");
- check_contains(ot, "44", 0);
- check_contains(ot, "441", 0);
- check_contains(ot, "440", 0);
- check_contains(ot, "444", 1);
- check_contains(ot, "4440", 1);
- check_contains(ot, "4444", 0);
-}
-
-static void t_each(struct oidtree *ot)
-{
- FILL_TREE(ot, "f", "9", "8", "123", "321", "320", "a", "b", "c", "d", "e");
- check_each(ot, "12300", "123", NULL);
- check_each(ot, "3211", NULL); /* should not reach callback */
- check_each(ot, "3210", "321", NULL);
- check_each(ot, "32100", "321", NULL);
- check_each(ot, "32", "320", "321", NULL);
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- TEST(setup(t_contains), "oidtree insert and contains works");
- TEST(setup(t_each), "oidtree each works");
- return test_done();
-}
diff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c
deleted file mode 100644
index a053635000..0000000000
--- a/t/unit-tests/t-prio-queue.c
+++ /dev/null
@@ -1,91 +0,0 @@
-#include "test-lib.h"
-#include "prio-queue.h"
-
-static int intcmp(const void *va, const void *vb, void *data UNUSED)
-{
- const int *a = va, *b = vb;
- return *a - *b;
-}
-
-
-#define MISSING -1
-#define DUMP -2
-#define STACK -3
-#define GET -4
-#define REVERSE -5
-
-static int show(int *v)
-{
- return v ? *v : MISSING;
-}
-
-static void test_prio_queue(int *input, size_t input_size,
- int *result, size_t result_size)
-{
- struct prio_queue pq = { intcmp };
- int j = 0;
-
- for (size_t i = 0; i < input_size; i++) {
- void *peek, *get;
- switch(input[i]) {
- case GET:
- peek = prio_queue_peek(&pq);
- get = prio_queue_get(&pq);
- if (!check(peek == get))
- return;
- if (!check_uint(j, <, result_size))
- break;
- if (!check_int(result[j], ==, show(get)))
- test_msg(" j: %d", j);
- j++;
- break;
- case DUMP:
- while ((peek = prio_queue_peek(&pq))) {
- get = prio_queue_get(&pq);
- if (!check(peek == get))
- return;
- if (!check_uint(j, <, result_size))
- break;
- if (!check_int(result[j], ==, show(get)))
- test_msg(" j: %d", j);
- j++;
- }
- break;
- case STACK:
- pq.compare = NULL;
- break;
- case REVERSE:
- prio_queue_reverse(&pq);
- break;
- default:
- prio_queue_put(&pq, &input[i]);
- break;
- }
- }
- check_uint(j, ==, result_size);
- clear_prio_queue(&pq);
-}
-
-#define TEST_INPUT(input, result) \
- test_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- TEST(TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),
- ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 })),
- "prio-queue works for basic input");
- TEST(TEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),
- ((int []){ 2, 3, 4, 1, 5, 6 })),
- "prio-queue works for mixed put & get commands");
- TEST(TEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),
- ((int []){ 1, 2, MISSING, 1, 2, MISSING })),
- "prio-queue works when queue is empty");
- TEST(TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),
- ((int []){ 3, 2, 6, 4, 5, 1, 8 })),
- "prio-queue works when used as a LIFO stack");
- TEST(TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),
- ((int []){ 1, 2, 3, 4, 5, 6 })),
- "prio-queue works when LIFO stack is reversed");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c
deleted file mode 100644
index 1d640b280f..0000000000
--- a/t/unit-tests/t-reftable-basics.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#include "test-lib.h"
-#include "reftable/basics.h"
-
-struct integer_needle_lesseq_args {
- int needle;
- int *haystack;
-};
-
-static int integer_needle_lesseq(size_t i, void *_args)
-{
- struct integer_needle_lesseq_args *args = _args;
- return args->needle <= args->haystack[i];
-}
-
-static void *realloc_stub(void *p UNUSED, size_t size UNUSED)
-{
- return NULL;
-}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- if_test ("binary search with binsearch works") {
- int haystack[] = { 2, 4, 6, 8, 10 };
- struct {
- int needle;
- size_t expected_idx;
- } testcases[] = {
- {-9000, 0},
- {-1, 0},
- {0, 0},
- {2, 0},
- {3, 1},
- {4, 1},
- {7, 3},
- {9, 4},
- {10, 4},
- {11, 5},
- {9000, 5},
- };
-
- for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
- struct integer_needle_lesseq_args args = {
- .haystack = haystack,
- .needle = testcases[i].needle,
- };
- size_t idx;
-
- idx = binsearch(ARRAY_SIZE(haystack),
- &integer_needle_lesseq, &args);
- check_int(idx, ==, testcases[i].expected_idx);
- }
- }
-
- if_test ("names_length returns size of a NULL-terminated string array") {
- const char *a[] = { "a", "b", NULL };
- check_int(names_length(a), ==, 2);
- }
-
- if_test ("names_equal compares NULL-terminated string arrays") {
- const char *a[] = { "a", "b", "c", NULL };
- const char *b[] = { "a", "b", "d", NULL };
- const char *c[] = { "a", "b", NULL };
-
- check(names_equal(a, a));
- check(!names_equal(a, b));
- check(!names_equal(a, c));
- }
-
- if_test ("parse_names works for basic input") {
- char in1[] = "line\n";
- char in2[] = "a\nb\nc";
- char **out = parse_names(in1, strlen(in1));
- check(out != NULL);
- check_str(out[0], "line");
- check(!out[1]);
- free_names(out);
-
- out = parse_names(in2, strlen(in2));
- check(out != NULL);
- check_str(out[0], "a");
- check_str(out[1], "b");
- check_str(out[2], "c");
- check(!out[3]);
- free_names(out);
- }
-
- if_test ("parse_names drops empty string") {
- char in[] = "a\n\nb\n";
- char **out = parse_names(in, strlen(in));
- check(out != NULL);
- check_str(out[0], "a");
- /* simply '\n' should be dropped as empty string */
- check_str(out[1], "b");
- check(!out[2]);
- free_names(out);
- }
-
- if_test ("common_prefix_size works") {
- struct reftable_buf a = REFTABLE_BUF_INIT;
- struct reftable_buf b = REFTABLE_BUF_INIT;
- struct {
- const char *a, *b;
- int want;
- } cases[] = {
- {"abcdef", "abc", 3},
- { "abc", "ab", 2 },
- { "", "abc", 0 },
- { "abc", "abd", 2 },
- { "abc", "pqr", 0 },
- };
-
- for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
- check(!reftable_buf_addstr(&a, cases[i].a));
- check(!reftable_buf_addstr(&b, cases[i].b));
- check_int(common_prefix_size(&a, &b), ==, cases[i].want);
- reftable_buf_reset(&a);
- reftable_buf_reset(&b);
- }
- reftable_buf_release(&a);
- reftable_buf_release(&b);
- }
-
- if_test ("put_be24 and get_be24 work") {
- uint32_t in = 0x112233;
- uint8_t dest[3];
- uint32_t out;
- put_be24(dest, in);
- out = get_be24(dest);
- check_int(in, ==, out);
- }
-
- if_test ("put_be16 and get_be16 work") {
- uint32_t in = 0xfef1;
- uint8_t dest[3];
- uint32_t out;
- put_be16(dest, in);
- out = get_be16(dest);
- check_int(in, ==, out);
- }
-
- if_test ("REFTABLE_ALLOC_GROW works") {
- int *arr = NULL, *old_arr;
- size_t alloc = 0, old_alloc;
-
- check(!REFTABLE_ALLOC_GROW(arr, 1, alloc));
- check(arr != NULL);
- check_uint(alloc, >=, 1);
- arr[0] = 42;
-
- old_alloc = alloc;
- old_arr = arr;
- reftable_set_alloc(NULL, realloc_stub, NULL);
- check(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
- check(arr == old_arr);
- check_uint(alloc, ==, old_alloc);
-
- old_alloc = alloc;
- reftable_set_alloc(NULL, NULL, NULL);
- check(!REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
- check(arr != NULL);
- check_uint(alloc, >, old_alloc);
- arr[alloc - 1] = 42;
-
- reftable_free(arr);
- }
-
- if_test ("REFTABLE_ALLOC_GROW_OR_NULL works") {
- int *arr = NULL;
- size_t alloc = 0, old_alloc;
-
- REFTABLE_ALLOC_GROW_OR_NULL(arr, 1, alloc);
- check(arr != NULL);
- check_uint(alloc, >=, 1);
- arr[0] = 42;
-
- old_alloc = alloc;
- REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
- check(arr != NULL);
- check_uint(alloc, >, old_alloc);
- arr[alloc - 1] = 42;
-
- old_alloc = alloc;
- reftable_set_alloc(NULL, realloc_stub, NULL);
- REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
- check(arr == NULL);
- check_uint(alloc, ==, 0);
- reftable_set_alloc(NULL, NULL, NULL);
-
- reftable_free(arr);
- }
-
- return test_done();
-}
diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c
deleted file mode 100644
index 22040aeefa..0000000000
--- a/t/unit-tests/t-reftable-block.c
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
-Copyright 2020 Google LLC
-
-Use of this source code is governed by a BSD-style
-license that can be found in the LICENSE file or at
-https://developers.google.com/open-source/licenses/bsd
-*/
-
-#include "test-lib.h"
-#include "reftable/block.h"
-#include "reftable/blocksource.h"
-#include "reftable/constants.h"
-#include "reftable/reftable-error.h"
-#include "strbuf.h"
-
-static void t_ref_block_read_write(void)
-{
- const int header_off = 21; /* random */
- struct reftable_record recs[30];
- const size_t N = ARRAY_SIZE(recs);
- const size_t block_size = 1024;
- struct reftable_block block = { 0 };
- struct block_writer bw = {
- .last_key = REFTABLE_BUF_INIT,
- };
- struct reftable_record rec = {
- .type = BLOCK_TYPE_REF,
- };
- size_t i = 0;
- int ret;
- struct block_reader br = { 0 };
- struct block_iter it = BLOCK_ITER_INIT;
- struct reftable_buf want = REFTABLE_BUF_INIT, buf = REFTABLE_BUF_INIT;
-
- REFTABLE_CALLOC_ARRAY(block.data, block_size);
- check(block.data != NULL);
- block.len = block_size;
- block_source_from_buf(&block.source ,&buf);
- ret = block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
- header_off, hash_size(REFTABLE_HASH_SHA1));
- check(!ret);
-
- rec.u.ref.refname = (char *) "";
- rec.u.ref.value_type = REFTABLE_REF_DELETION;
- ret = block_writer_add(&bw, &rec);
- check_int(ret, ==, REFTABLE_API_ERROR);
-
- for (i = 0; i < N; i++) {
- rec.u.ref.refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
- rec.u.ref.value_type = REFTABLE_REF_VAL1;
- memset(rec.u.ref.value.val1, i, REFTABLE_HASH_SIZE_SHA1);
-
- recs[i] = rec;
- ret = block_writer_add(&bw, &rec);
- rec.u.ref.refname = NULL;
- rec.u.ref.value_type = REFTABLE_REF_DELETION;
- check_int(ret, ==, 0);
- }
-
- ret = block_writer_finish(&bw);
- check_int(ret, >, 0);
-
- block_writer_release(&bw);
-
- block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
-
- block_iter_seek_start(&it, &br);
-
- for (i = 0; ; i++) {
- ret = block_iter_next(&it, &rec);
- check_int(ret, >=, 0);
- if (ret > 0) {
- check_int(i, ==, N);
- break;
- }
- check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
- }
-
- for (i = 0; i < N; i++) {
- block_iter_reset(&it);
- reftable_record_key(&recs[i], &want);
-
- ret = block_iter_seek_key(&it, &br, &want);
- check_int(ret, ==, 0);
-
- ret = block_iter_next(&it, &rec);
- check_int(ret, ==, 0);
-
- check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
-
- want.len--;
- ret = block_iter_seek_key(&it, &br, &want);
- check_int(ret, ==, 0);
-
- ret = block_iter_next(&it, &rec);
- check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
- }
-
- block_reader_release(&br);
- block_iter_close(&it);
- reftable_record_release(&rec);
- reftable_block_done(&br.block);
- reftable_buf_release(&want);
- reftable_buf_release(&buf);
- for (i = 0; i < N; i++)
- reftable_record_release(&recs[i]);
-}
-
-static void t_log_block_read_write(void)
-{
- const int header_off = 21;
- struct reftable_record recs[30];
- const size_t N = ARRAY_SIZE(recs);
- const size_t block_size = 2048;
- struct reftable_block block = { 0 };
- struct block_writer bw = {
- .last_key = REFTABLE_BUF_INIT,
- };
- struct reftable_record rec = {
- .type = BLOCK_TYPE_LOG,
- };
- size_t i = 0;
- int ret;
- struct block_reader br = { 0 };
- struct block_iter it = BLOCK_ITER_INIT;
- struct reftable_buf want = REFTABLE_BUF_INIT, buf = REFTABLE_BUF_INIT;
-
- REFTABLE_CALLOC_ARRAY(block.data, block_size);
- check(block.data != NULL);
- block.len = block_size;
- block_source_from_buf(&block.source ,&buf);
- ret = block_writer_init(&bw, BLOCK_TYPE_LOG, block.data, block_size,
- header_off, hash_size(REFTABLE_HASH_SHA1));
- check(!ret);
-
- for (i = 0; i < N; i++) {
- rec.u.log.refname = xstrfmt("branch%02"PRIuMAX , (uintmax_t)i);
- rec.u.log.update_index = i;
- rec.u.log.value_type = REFTABLE_LOG_UPDATE;
-
- recs[i] = rec;
- ret = block_writer_add(&bw, &rec);
- rec.u.log.refname = NULL;
- rec.u.log.value_type = REFTABLE_LOG_DELETION;
- check_int(ret, ==, 0);
- }
-
- ret = block_writer_finish(&bw);
- check_int(ret, >, 0);
-
- block_writer_release(&bw);
-
- block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
-
- block_iter_seek_start(&it, &br);
-
- for (i = 0; ; i++) {
- ret = block_iter_next(&it, &rec);
- check_int(ret, >=, 0);
- if (ret > 0) {
- check_int(i, ==, N);
- break;
- }
- check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
- }
-
- for (i = 0; i < N; i++) {
- block_iter_reset(&it);
- reftable_buf_reset(&want);
- check(!reftable_buf_addstr(&want, recs[i].u.log.refname));
-
- ret = block_iter_seek_key(&it, &br, &want);
- check_int(ret, ==, 0);
-
- ret = block_iter_next(&it, &rec);
- check_int(ret, ==, 0);
-
- check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
-
- want.len--;
- ret = block_iter_seek_key(&it, &br, &want);
- check_int(ret, ==, 0);
-
- ret = block_iter_next(&it, &rec);
- check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
- }
-
- block_reader_release(&br);
- block_iter_close(&it);
- reftable_record_release(&rec);
- reftable_block_done(&br.block);
- reftable_buf_release(&want);
- reftable_buf_release(&buf);
- for (i = 0; i < N; i++)
- reftable_record_release(&recs[i]);
-}
-
-static void t_obj_block_read_write(void)
-{
- const int header_off = 21;
- struct reftable_record recs[30];
- const size_t N = ARRAY_SIZE(recs);
- const size_t block_size = 1024;
- struct reftable_block block = { 0 };
- struct block_writer bw = {
- .last_key = REFTABLE_BUF_INIT,
- };
- struct reftable_record rec = {
- .type = BLOCK_TYPE_OBJ,
- };
- size_t i = 0;
- int ret;
- struct block_reader br = { 0 };
- struct block_iter it = BLOCK_ITER_INIT;
- struct reftable_buf want = REFTABLE_BUF_INIT, buf = REFTABLE_BUF_INIT;
-
- REFTABLE_CALLOC_ARRAY(block.data, block_size);
- check(block.data != NULL);
- block.len = block_size;
- block_source_from_buf(&block.source, &buf);
- ret = block_writer_init(&bw, BLOCK_TYPE_OBJ, block.data, block_size,
- header_off, hash_size(REFTABLE_HASH_SHA1));
- check(!ret);
-
- for (i = 0; i < N; i++) {
- uint8_t bytes[] = { i, i + 1, i + 2, i + 3, i + 5 }, *allocated;
- DUP_ARRAY(allocated, bytes, ARRAY_SIZE(bytes));
-
- rec.u.obj.hash_prefix = allocated;
- rec.u.obj.hash_prefix_len = 5;
-
- recs[i] = rec;
- ret = block_writer_add(&bw, &rec);
- rec.u.obj.hash_prefix = NULL;
- rec.u.obj.hash_prefix_len = 0;
- check_int(ret, ==, 0);
- }
-
- ret = block_writer_finish(&bw);
- check_int(ret, >, 0);
-
- block_writer_release(&bw);
-
- block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
-
- block_iter_seek_start(&it, &br);
-
- for (i = 0; ; i++) {
- ret = block_iter_next(&it, &rec);
- check_int(ret, >=, 0);
- if (ret > 0) {
- check_int(i, ==, N);
- break;
- }
- check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
- }
-
- for (i = 0; i < N; i++) {
- block_iter_reset(&it);
- reftable_record_key(&recs[i], &want);
-
- ret = block_iter_seek_key(&it, &br, &want);
- check_int(ret, ==, 0);
-
- ret = block_iter_next(&it, &rec);
- check_int(ret, ==, 0);
-
- check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
- }
-
- block_reader_release(&br);
- block_iter_close(&it);
- reftable_record_release(&rec);
- reftable_block_done(&br.block);
- reftable_buf_release(&want);
- reftable_buf_release(&buf);
- for (i = 0; i < N; i++)
- reftable_record_release(&recs[i]);
-}
-
-static void t_index_block_read_write(void)
-{
- const int header_off = 21;
- struct reftable_record recs[30];
- const size_t N = ARRAY_SIZE(recs);
- const size_t block_size = 1024;
- struct reftable_block block = { 0 };
- struct block_writer bw = {
- .last_key = REFTABLE_BUF_INIT,
- };
- struct reftable_record rec = {
- .type = BLOCK_TYPE_INDEX,
- .u.idx.last_key = REFTABLE_BUF_INIT,
- };
- size_t i = 0;
- int ret;
- struct block_reader br = { 0 };
- struct block_iter it = BLOCK_ITER_INIT;
- struct reftable_buf want = REFTABLE_BUF_INIT, buf = REFTABLE_BUF_INIT;
-
- REFTABLE_CALLOC_ARRAY(block.data, block_size);
- check(block.data != NULL);
- block.len = block_size;
- block_source_from_buf(&block.source, &buf);
- ret = block_writer_init(&bw, BLOCK_TYPE_INDEX, block.data, block_size,
- header_off, hash_size(REFTABLE_HASH_SHA1));
- check(!ret);
-
- for (i = 0; i < N; i++) {
- char buf[128];
-
- snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i);
-
- reftable_buf_init(&recs[i].u.idx.last_key);
- recs[i].type = BLOCK_TYPE_INDEX;
- check(!reftable_buf_addstr(&recs[i].u.idx.last_key, buf));
- recs[i].u.idx.offset = i;
-
- ret = block_writer_add(&bw, &recs[i]);
- check_int(ret, ==, 0);
- }
-
- ret = block_writer_finish(&bw);
- check_int(ret, >, 0);
-
- block_writer_release(&bw);
-
- block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
-
- block_iter_seek_start(&it, &br);
-
- for (i = 0; ; i++) {
- ret = block_iter_next(&it, &rec);
- check_int(ret, >=, 0);
- if (ret > 0) {
- check_int(i, ==, N);
- break;
- }
- check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
- }
-
- for (i = 0; i < N; i++) {
- block_iter_reset(&it);
- reftable_record_key(&recs[i], &want);
-
- ret = block_iter_seek_key(&it, &br, &want);
- check_int(ret, ==, 0);
-
- ret = block_iter_next(&it, &rec);
- check_int(ret, ==, 0);
-
- check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
-
- want.len--;
- ret = block_iter_seek_key(&it, &br, &want);
- check_int(ret, ==, 0);
-
- ret = block_iter_next(&it, &rec);
- check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
- }
-
- block_reader_release(&br);
- block_iter_close(&it);
- reftable_record_release(&rec);
- reftable_block_done(&br.block);
- reftable_buf_release(&want);
- reftable_buf_release(&buf);
- for (i = 0; i < N; i++)
- reftable_record_release(&recs[i]);
-}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- TEST(t_index_block_read_write(), "read-write operations on index blocks work");
- TEST(t_log_block_read_write(), "read-write operations on log blocks work");
- TEST(t_obj_block_read_write(), "read-write operations on obj blocks work");
- TEST(t_ref_block_read_write(), "read-write operations on ref blocks work");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-reftable-reader.c b/t/unit-tests/t-reftable-reader.c
deleted file mode 100644
index 546df6005e..0000000000
--- a/t/unit-tests/t-reftable-reader.c
+++ /dev/null
@@ -1,96 +0,0 @@
-#include "test-lib.h"
-#include "lib-reftable.h"
-#include "reftable/blocksource.h"
-#include "reftable/reader.h"
-
-static int t_reader_seek_once(void)
-{
- struct reftable_ref_record records[] = {
- {
- .refname = (char *) "refs/heads/main",
- .value_type = REFTABLE_REF_VAL1,
- .value.val1 = { 42 },
- },
- };
- struct reftable_block_source source = { 0 };
- struct reftable_ref_record ref = { 0 };
- struct reftable_iterator it = { 0 };
- struct reftable_reader *reader;
- struct reftable_buf buf = REFTABLE_BUF_INIT;
- int ret;
-
- t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
- block_source_from_buf(&source, &buf);
-
- ret = reftable_reader_new(&reader, &source, "name");
- check(!ret);
-
- reftable_reader_init_ref_iterator(reader, &it);
- ret = reftable_iterator_seek_ref(&it, "");
- check(!ret);
- ret = reftable_iterator_next_ref(&it, &ref);
- check(!ret);
-
- ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
- check_int(ret, ==, 1);
-
- ret = reftable_iterator_next_ref(&it, &ref);
- check_int(ret, ==, 1);
-
- reftable_ref_record_release(&ref);
- reftable_iterator_destroy(&it);
- reftable_reader_decref(reader);
- reftable_buf_release(&buf);
- return 0;
-}
-
-static int t_reader_reseek(void)
-{
- struct reftable_ref_record records[] = {
- {
- .refname = (char *) "refs/heads/main",
- .value_type = REFTABLE_REF_VAL1,
- .value.val1 = { 42 },
- },
- };
- struct reftable_block_source source = { 0 };
- struct reftable_ref_record ref = { 0 };
- struct reftable_iterator it = { 0 };
- struct reftable_reader *reader;
- struct reftable_buf buf = REFTABLE_BUF_INIT;
- int ret;
-
- t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
- block_source_from_buf(&source, &buf);
-
- ret = reftable_reader_new(&reader, &source, "name");
- check(!ret);
-
- reftable_reader_init_ref_iterator(reader, &it);
-
- for (size_t i = 0; i < 5; i++) {
- ret = reftable_iterator_seek_ref(&it, "");
- check(!ret);
- ret = reftable_iterator_next_ref(&it, &ref);
- check(!ret);
-
- ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
- check_int(ret, ==, 1);
-
- ret = reftable_iterator_next_ref(&it, &ref);
- check_int(ret, ==, 1);
- }
-
- reftable_ref_record_release(&ref);
- reftable_iterator_destroy(&it);
- reftable_reader_decref(reader);
- reftable_buf_release(&buf);
- return 0;
-}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- TEST(t_reader_seek_once(), "reader can seek once");
- TEST(t_reader_reseek(), "reader can reseek multiple times");
- return test_done();
-}
diff --git a/t/unit-tests/t-strbuf.c b/t/unit-tests/t-strbuf.c
deleted file mode 100644
index 3f4044d697..0000000000
--- a/t/unit-tests/t-strbuf.c
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "test-lib.h"
-#include "strbuf.h"
-
-/* wrapper that supplies tests with an empty, initialized strbuf */
-static void setup(void (*f)(struct strbuf*, const void*),
- const void *data)
-{
- struct strbuf buf = STRBUF_INIT;
-
- f(&buf, data);
- strbuf_release(&buf);
- check_uint(buf.len, ==, 0);
- check_uint(buf.alloc, ==, 0);
-}
-
-/* wrapper that supplies tests with a populated, initialized strbuf */
-static void setup_populated(void (*f)(struct strbuf*, const void*),
- const char *init_str, const void *data)
-{
- struct strbuf buf = STRBUF_INIT;
-
- strbuf_addstr(&buf, init_str);
- check_uint(buf.len, ==, strlen(init_str));
- f(&buf, data);
- strbuf_release(&buf);
- check_uint(buf.len, ==, 0);
- check_uint(buf.alloc, ==, 0);
-}
-
-static int assert_sane_strbuf(struct strbuf *buf)
-{
- /* Initialized strbufs should always have a non-NULL buffer */
- if (!check(!!buf->buf))
- return 0;
- /* Buffers should always be NUL-terminated */
- if (!check_char(buf->buf[buf->len], ==, '\0'))
- return 0;
- /*
- * Freshly-initialized strbufs may not have a dynamically allocated
- * buffer
- */
- if (buf->len == 0 && buf->alloc == 0)
- return 1;
- /* alloc must be at least one byte larger than len */
- return check_uint(buf->len, <, buf->alloc);
-}
-
-static void t_static_init(void)
-{
- struct strbuf buf = STRBUF_INIT;
-
- check_uint(buf.len, ==, 0);
- check_uint(buf.alloc, ==, 0);
- check_char(buf.buf[0], ==, '\0');
-}
-
-static void t_dynamic_init(void)
-{
- struct strbuf buf;
-
- strbuf_init(&buf, 1024);
- check(assert_sane_strbuf(&buf));
- check_uint(buf.len, ==, 0);
- check_uint(buf.alloc, >=, 1024);
- check_char(buf.buf[0], ==, '\0');
- strbuf_release(&buf);
-}
-
-static void t_addch(struct strbuf *buf, const void *data)
-{
- const char *p_ch = data;
- const char ch = *p_ch;
- size_t orig_alloc = buf->alloc;
- size_t orig_len = buf->len;
-
- if (!check(assert_sane_strbuf(buf)))
- return;
- strbuf_addch(buf, ch);
- if (!check(assert_sane_strbuf(buf)))
- return;
- if (!(check_uint(buf->len, ==, orig_len + 1) &&
- check_uint(buf->alloc, >=, orig_alloc)))
- return; /* avoid de-referencing buf->buf */
- check_char(buf->buf[buf->len - 1], ==, ch);
- check_char(buf->buf[buf->len], ==, '\0');
-}
-
-static void t_addstr(struct strbuf *buf, const void *data)
-{
- const char *text = data;
- size_t len = strlen(text);
- size_t orig_alloc = buf->alloc;
- size_t orig_len = buf->len;
-
- if (!check(assert_sane_strbuf(buf)))
- return;
- strbuf_addstr(buf, text);
- if (!check(assert_sane_strbuf(buf)))
- return;
- if (!(check_uint(buf->len, ==, orig_len + len) &&
- check_uint(buf->alloc, >=, orig_alloc) &&
- check_uint(buf->alloc, >, orig_len + len) &&
- check_char(buf->buf[orig_len + len], ==, '\0')))
- return;
- check_str(buf->buf + orig_len, text);
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- if (!TEST(t_static_init(), "static initialization works"))
- test_skip_all("STRBUF_INIT is broken");
- TEST(t_dynamic_init(), "dynamic initialization works");
- TEST(setup(t_addch, "a"), "strbuf_addch adds char");
- TEST(setup(t_addch, ""), "strbuf_addch adds NUL char");
- TEST(setup_populated(t_addch, "initial value", "a"),
- "strbuf_addch appends to initial value");
- TEST(setup(t_addstr, "hello there"), "strbuf_addstr adds string");
- TEST(setup_populated(t_addstr, "initial value", "hello there"),
- "strbuf_addstr appends string to initial value");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-strcmp-offset.c b/t/unit-tests/t-strcmp-offset.c
deleted file mode 100644
index 6880f21161..0000000000
--- a/t/unit-tests/t-strcmp-offset.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "test-lib.h"
-#include "read-cache-ll.h"
-
-static void check_strcmp_offset(const char *string1, const char *string2,
- int expect_result, uintmax_t expect_offset)
-{
- size_t offset;
- int result = strcmp_offset(string1, string2, &offset);
-
- /*
- * Because different CRTs behave differently, only rely on signs of the
- * result values.
- */
- result = (result < 0 ? -1 :
- result > 0 ? 1 :
- 0);
-
- check_int(result, ==, expect_result);
- check_uint((uintmax_t)offset, ==, expect_offset);
-}
-
-#define TEST_STRCMP_OFFSET(string1, string2, expect_result, expect_offset) \
- TEST(check_strcmp_offset(string1, string2, expect_result, \
- expect_offset), \
- "strcmp_offset(%s, %s) works", #string1, #string2)
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- TEST_STRCMP_OFFSET("abc", "abc", 0, 3);
- TEST_STRCMP_OFFSET("abc", "def", -1, 0);
- TEST_STRCMP_OFFSET("abc", "abz", -1, 2);
- TEST_STRCMP_OFFSET("abc", "abcdef", -1, 3);
-
- return test_done();
-}
diff --git a/t/unit-tests/t-trailer.c b/t/unit-tests/t-trailer.c
deleted file mode 100644
index 184593e73d..0000000000
--- a/t/unit-tests/t-trailer.c
+++ /dev/null
@@ -1,317 +0,0 @@
-#define DISABLE_SIGN_COMPARE_WARNINGS
-
-#include "test-lib.h"
-#include "trailer.h"
-
-struct contents {
- const char *raw;
- const char *key;
- const char *val;
-};
-
-static void t_trailer_iterator(const char *msg, size_t num_expected,
- struct contents *contents)
-{
- struct trailer_iterator iter;
- size_t i = 0;
-
- trailer_iterator_init(&iter, msg);
- while (trailer_iterator_advance(&iter)) {
- if (num_expected) {
- check_str(iter.raw, contents[i].raw);
- check_str(iter.key.buf, contents[i].key);
- check_str(iter.val.buf, contents[i].val);
- }
- i++;
- }
- trailer_iterator_release(&iter);
-
- check_uint(i, ==, num_expected);
-}
-
-static void run_t_trailer_iterator(void)
-{
-
- static struct test_cases {
- const char *name;
- const char *msg;
- size_t num_expected;
- struct contents contents[10];
- } tc[] = {
- {
- "empty input",
- "",
- 0,
- {{0}},
- },
- {
- "no newline at beginning",
- "Fixes: x\n"
- "Acked-by: x\n"
- "Reviewed-by: x\n",
- 0,
- {{0}},
- },
- {
- "newline at beginning",
- "\n"
- "Fixes: x\n"
- "Acked-by: x\n"
- "Reviewed-by: x\n",
- 3,
- {
- {
- .raw = "Fixes: x\n",
- .key = "Fixes",
- .val = "x",
- },
- {
- .raw = "Acked-by: x\n",
- .key = "Acked-by",
- .val = "x",
- },
- {
- .raw = "Reviewed-by: x\n",
- .key = "Reviewed-by",
- .val = "x",
- },
- {
- 0
- },
- },
- },
- {
- "without body text",
- "subject: foo bar\n"
- "\n"
- "Fixes: x\n"
- "Acked-by: x\n"
- "Reviewed-by: x\n",
- 3,
- {
- {
- .raw = "Fixes: x\n",
- .key = "Fixes",
- .val = "x",
- },
- {
- .raw = "Acked-by: x\n",
- .key = "Acked-by",
- .val = "x",
- },
- {
- .raw = "Reviewed-by: x\n",
- .key = "Reviewed-by",
- .val = "x",
- },
- {
- 0
- },
- },
- },
- {
- "with body text, without divider",
- "my subject\n"
- "\n"
- "my body which is long\n"
- "and contains some special\n"
- "chars like : = ? !\n"
- "hello\n"
- "\n"
- "Fixes: x\n"
- "Acked-by: x\n"
- "Reviewed-by: x\n"
- "Signed-off-by: x\n",
- 4,
- {
- {
- .raw = "Fixes: x\n",
- .key = "Fixes",
- .val = "x",
- },
- {
- .raw = "Acked-by: x\n",
- .key = "Acked-by",
- .val = "x",
- },
- {
- .raw = "Reviewed-by: x\n",
- .key = "Reviewed-by",
- .val = "x",
- },
- {
- .raw = "Signed-off-by: x\n",
- .key = "Signed-off-by",
- .val = "x",
- },
- {
- 0
- },
- },
- },
- {
- "with body text, without divider (second trailer block)",
- "my subject\n"
- "\n"
- "my body which is long\n"
- "and contains some special\n"
- "chars like : = ? !\n"
- "hello\n"
- "\n"
- "Fixes: x\n"
- "Acked-by: x\n"
- "Reviewed-by: x\n"
- "Signed-off-by: x\n"
- "\n"
- /*
- * Because this is the last trailer block, it takes
- * precedence over the first one encountered above.
- */
- "Helped-by: x\n"
- "Signed-off-by: x\n",
- 2,
- {
- {
- .raw = "Helped-by: x\n",
- .key = "Helped-by",
- .val = "x",
- },
- {
- .raw = "Signed-off-by: x\n",
- .key = "Signed-off-by",
- .val = "x",
- },
- {
- 0
- },
- },
- },
- {
- "with body text, with divider",
- "my subject\n"
- "\n"
- "my body which is long\n"
- "and contains some special\n"
- "chars like : = ? !\n"
- "hello\n"
- "\n"
- "---\n"
- "\n"
- /*
- * This trailer still counts because the iterator
- * always ignores the divider.
- */
- "Signed-off-by: x\n",
- 1,
- {
- {
- .raw = "Signed-off-by: x\n",
- .key = "Signed-off-by",
- .val = "x",
- },
- {
- 0
- },
- },
- },
- {
- "with non-trailer lines in trailer block",
- "subject: foo bar\n"
- "\n"
- /*
- * Even though this trailer block has a non-trailer line
- * in it, it's still a valid trailer block because it's
- * at least 25% trailers and is Git-generated (see
- * git_generated_prefixes[] in trailer.c).
- */
- "not a trailer line\n"
- "not a trailer line\n"
- "not a trailer line\n"
- "Signed-off-by: x\n",
- /*
- * Even though there is only really 1 real "trailer"
- * (Signed-off-by), we still have 4 trailer objects
- * because we still want to iterate through the entire
- * block.
- */
- 4,
- {
- {
- .raw = "not a trailer line\n",
- .key = "not a trailer line",
- .val = "",
- },
- {
- .raw = "not a trailer line\n",
- .key = "not a trailer line",
- .val = "",
- },
- {
- .raw = "not a trailer line\n",
- .key = "not a trailer line",
- .val = "",
- },
- {
- .raw = "Signed-off-by: x\n",
- .key = "Signed-off-by",
- .val = "x",
- },
- {
- 0
- },
- },
- },
- {
- "with non-trailer lines (one too many) in trailer block",
- "subject: foo bar\n"
- "\n"
- /*
- * This block has only 20% trailers, so it's below the
- * 25% threshold.
- */
- "not a trailer line\n"
- "not a trailer line\n"
- "not a trailer line\n"
- "not a trailer line\n"
- "Signed-off-by: x\n",
- 0,
- {{0}},
- },
- {
- "with non-trailer lines (only 1) in trailer block, but no Git-generated trailers",
- "subject: foo bar\n"
- "\n"
- /*
- * This block has only 1 non-trailer out of 10 (IOW, 90%
- * trailers) but is not considered a trailer block
- * because the 25% threshold only applies to cases where
- * there was a Git-generated trailer.
- */
- "Reviewed-by: x\n"
- "Reviewed-by: x\n"
- "Reviewed-by: x\n"
- "Helped-by: x\n"
- "Helped-by: x\n"
- "Helped-by: x\n"
- "Acked-by: x\n"
- "Acked-by: x\n"
- "Acked-by: x\n"
- "not a trailer line\n",
- 0,
- {{0}},
- },
- };
-
- for (int i = 0; i < sizeof(tc) / sizeof(tc[0]); i++) {
- TEST(t_trailer_iterator(tc[i].msg,
- tc[i].num_expected,
- tc[i].contents),
- "%s", tc[i].name);
- }
-}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- run_t_trailer_iterator();
- return test_done();
-}
diff --git a/t/unit-tests/u-dir.c b/t/unit-tests/u-dir.c
new file mode 100644
index 0000000000..2d0adaa39e
--- /dev/null
+++ b/t/unit-tests/u-dir.c
@@ -0,0 +1,47 @@
+#include "unit-test.h"
+#include "dir.h"
+
+#define TEST_WITHIN_DEPTH(path, depth, max_depth, expect) do { \
+ int actual = within_depth(path, strlen(path), \
+ depth, max_depth); \
+ if (actual != expect) \
+ cl_failf("path '%s' with depth '%d' and max-depth '%d': expected %d, got %d", \
+ path, depth, max_depth, expect, actual); \
+ } while (0)
+
+void test_dir__within_depth(void)
+{
+ /* depth = 0; max_depth = 0 */
+ TEST_WITHIN_DEPTH("", 0, 0, 1);
+ TEST_WITHIN_DEPTH("file", 0, 0, 1);
+ TEST_WITHIN_DEPTH("a", 0, 0, 1);
+ TEST_WITHIN_DEPTH("a/file", 0, 0, 0);
+ TEST_WITHIN_DEPTH("a/b", 0, 0, 0);
+ TEST_WITHIN_DEPTH("a/b/file", 0, 0, 0);
+
+ /* depth = 0; max_depth = 1 */
+ TEST_WITHIN_DEPTH("", 0, 1, 1);
+ TEST_WITHIN_DEPTH("file", 0, 1, 1);
+ TEST_WITHIN_DEPTH("a", 0, 1, 1);
+ TEST_WITHIN_DEPTH("a/file", 0, 1, 1);
+ TEST_WITHIN_DEPTH("a/b", 0, 1, 1);
+ TEST_WITHIN_DEPTH("a/b/file", 0, 1, 0);
+
+ /* depth = 1; max_depth = 1 */
+ TEST_WITHIN_DEPTH("", 1, 1, 1);
+ TEST_WITHIN_DEPTH("file", 1, 1, 1);
+ TEST_WITHIN_DEPTH("a", 1, 1, 1);
+ TEST_WITHIN_DEPTH("a/file", 1, 1, 0);
+ TEST_WITHIN_DEPTH("a/b", 1, 1, 0);
+ TEST_WITHIN_DEPTH("a/b/file", 1, 1, 0);
+
+ /* depth = 1; max_depth = 0 */
+ TEST_WITHIN_DEPTH("", 1, 0, 0);
+ TEST_WITHIN_DEPTH("file", 1, 0, 0);
+ TEST_WITHIN_DEPTH("a", 1, 0, 0);
+ TEST_WITHIN_DEPTH("a/file", 1, 0, 0);
+ TEST_WITHIN_DEPTH("a/b", 1, 0, 0);
+ TEST_WITHIN_DEPTH("a/b/file", 1, 0, 0);
+
+
+}
diff --git a/t/unit-tests/u-example-decorate.c b/t/unit-tests/u-example-decorate.c
new file mode 100644
index 0000000000..9b1d1ce753
--- /dev/null
+++ b/t/unit-tests/u-example-decorate.c
@@ -0,0 +1,64 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
+#include "unit-test.h"
+#include "object.h"
+#include "decorate.h"
+#include "repository.h"
+
+struct test_vars {
+ struct object *one, *two, *three;
+ struct decoration n;
+ int decoration_a, decoration_b;
+};
+
+static struct test_vars vars;
+
+void test_example_decorate__initialize(void)
+{
+ struct object_id one_oid = { { 1 } }, two_oid = { { 2 } }, three_oid = { { 3 } };
+
+ vars.one = lookup_unknown_object(the_repository, &one_oid);
+ vars.two = lookup_unknown_object(the_repository, &two_oid);
+ vars.three = lookup_unknown_object(the_repository, &three_oid);
+}
+
+void test_example_decorate__cleanup(void)
+{
+ clear_decoration(&vars.n, NULL);
+}
+
+void test_example_decorate__add(void)
+{
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, NULL), NULL);
+}
+
+void test_example_decorate__readd(void)
+{
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, NULL), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, NULL), &vars.decoration_a);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
+}
+
+void test_example_decorate__lookup(void)
+{
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, NULL), NULL);
+ cl_assert_equal_p(lookup_decoration(&vars.n, vars.two), &vars.decoration_b);
+ cl_assert_equal_p(lookup_decoration(&vars.n, vars.one), NULL);
+}
+
+void test_example_decorate__loop(void)
+{
+ int objects_noticed = 0;
+
+ cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL);
+ cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL);
+
+ for (size_t i = 0; i < vars.n.size; i++)
+ if (vars.n.entries[i].base)
+ objects_noticed++;
+
+ cl_assert_equal_i(objects_noticed, 2);
+}
diff --git a/t/unit-tests/t-hash.c b/t/unit-tests/u-hash.c
index e62647019b..bd4ac6a6e1 100644
--- a/t/unit-tests/t-hash.c
+++ b/t/unit-tests/u-hash.c
@@ -1,84 +1,109 @@
-#include "test-lib.h"
+#include "unit-test.h"
#include "hex.h"
#include "strbuf.h"
static void check_hash_data(const void *data, size_t data_length,
const char *expected_hashes[])
{
- if (!check(data != NULL)) {
- test_msg("BUG: NULL data pointer provided");
- return;
- }
+ cl_assert(data != NULL);
for (size_t i = 1; i < ARRAY_SIZE(hash_algos); i++) {
- git_hash_ctx ctx;
+ struct git_hash_ctx ctx;
unsigned char hash[GIT_MAX_HEXSZ];
const struct git_hash_algo *algop = &hash_algos[i];
algop->init_fn(&ctx);
- algop->update_fn(&ctx, data, data_length);
- algop->final_fn(hash, &ctx);
+ git_hash_update(&ctx, data, data_length);
+ git_hash_final(hash, &ctx);
- if (!check_str(hash_to_hex_algop(hash, algop), expected_hashes[i - 1]))
- test_msg("result does not match with the expected for %s\n", hash_algos[i].name);
+ cl_assert_equal_s(hash_to_hex_algop(hash,algop), expected_hashes[i - 1]);
}
}
/* Works with a NUL terminated string. Doesn't work if it should contain a NUL character. */
#define TEST_HASH_STR(data, expected_sha1, expected_sha256) do { \
const char *expected_hashes[] = { expected_sha1, expected_sha256 }; \
- TEST(check_hash_data(data, strlen(data), expected_hashes), \
- "SHA1 and SHA256 (%s) works", #data); \
+ check_hash_data(data, strlen(data), expected_hashes); \
} while (0)
/* Only works with a literal string, useful when it contains a NUL character. */
#define TEST_HASH_LITERAL(literal, expected_sha1, expected_sha256) do { \
const char *expected_hashes[] = { expected_sha1, expected_sha256 }; \
- TEST(check_hash_data(literal, (sizeof(literal) - 1), expected_hashes), \
- "SHA1 and SHA256 (%s) works", #literal); \
+ check_hash_data(literal, (sizeof(literal) - 1), expected_hashes); \
} while (0)
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
+void test_hash__empty_string(void)
{
- struct strbuf aaaaaaaaaa_100000 = STRBUF_INIT;
- struct strbuf alphabet_100000 = STRBUF_INIT;
-
- strbuf_addstrings(&aaaaaaaaaa_100000, "aaaaaaaaaa", 100000);
- strbuf_addstrings(&alphabet_100000, "abcdefghijklmnopqrstuvwxyz", 100000);
-
TEST_HASH_STR("",
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+}
+
+void test_hash__single_character(void)
+{
TEST_HASH_STR("a",
"86f7e437faa5a7fce15d1ddcb9eaeaea377667b8",
"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb");
+}
+
+void test_hash__multi_character(void)
+{
TEST_HASH_STR("abc",
"a9993e364706816aba3e25717850c26c9cd0d89d",
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
+}
+
+void test_hash__message_digest(void)
+{
TEST_HASH_STR("message digest",
"c12252ceda8be8994d5fa0290a47231c1d16aae3",
"f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650");
+}
+
+void test_hash__alphabet(void)
+{
TEST_HASH_STR("abcdefghijklmnopqrstuvwxyz",
"32d10c7b8cf96570ca04ce37f2a19d84240d3a89",
"71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73");
+}
+
+void test_hash__aaaaaaaaaa_100000(void)
+{
+ struct strbuf aaaaaaaaaa_100000 = STRBUF_INIT;
+ strbuf_addstrings(&aaaaaaaaaa_100000, "aaaaaaaaaa", 100000);
TEST_HASH_STR(aaaaaaaaaa_100000.buf,
"34aa973cd4c4daa4f61eeb2bdbad27316534016f",
"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0");
+ strbuf_release(&aaaaaaaaaa_100000);
+}
+
+void test_hash__alphabet_100000(void)
+{
+ struct strbuf alphabet_100000 = STRBUF_INIT;
+ strbuf_addstrings(&alphabet_100000, "abcdefghijklmnopqrstuvwxyz", 100000);
TEST_HASH_STR(alphabet_100000.buf,
"e7da7c55b3484fdf52aebec9cbe7b85a98f02fd4",
"e406ba321ca712ad35a698bf0af8d61fc4dc40eca6bdcea4697962724ccbde35");
+ strbuf_release(&alphabet_100000);
+}
+
+void test_hash__zero_blob_literal(void)
+{
TEST_HASH_LITERAL("blob 0\0",
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
"473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813");
+}
+
+void test_hash__three_blob_literal(void)
+{
TEST_HASH_LITERAL("blob 3\0abc",
"f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f",
"c1cf6e465077930e88dc5136641d402f72a229ddd996f627d60e9639eaba35a6");
+}
+
+void test_hash__zero_tree_literal(void)
+{
TEST_HASH_LITERAL("tree 0\0",
"4b825dc642cb6eb9a060e54bf8d69288fbee4904",
"6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321");
-
- strbuf_release(&aaaaaaaaaa_100000);
- strbuf_release(&alphabet_100000);
-
- return test_done();
}
diff --git a/t/unit-tests/t-hashmap.c b/t/unit-tests/u-hashmap.c
index 83b79dff39..eb80aa1348 100644
--- a/t/unit-tests/t-hashmap.c
+++ b/t/unit-tests/u-hashmap.c
@@ -1,4 +1,4 @@
-#include "test-lib.h"
+#include "unit-test.h"
#include "hashmap.h"
#include "strbuf.h"
@@ -83,23 +83,23 @@ static void t_replace(struct hashmap *map, unsigned int ignore_case)
struct test_entry *entry;
entry = alloc_test_entry("key1", "value1", ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
entry = alloc_test_entry(ignore_case ? "Key1" : "key1", "value2",
ignore_case);
entry = hashmap_put_entry(map, entry, ent);
- if (check(entry != NULL))
- check_str(get_value(entry), "value1");
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(get_value(entry), "value1");
free(entry);
entry = alloc_test_entry("fooBarFrotz", "value3", ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
entry = alloc_test_entry(ignore_case ? "FOObarFrotz" : "fooBarFrotz",
"value4", ignore_case);
entry = hashmap_put_entry(map, entry, ent);
- if (check(entry != NULL))
- check_str(get_value(entry), "value3");
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(get_value(entry), "value3");
free(entry);
}
@@ -122,20 +122,18 @@ static void t_get(struct hashmap *map, unsigned int ignore_case)
for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
entry = alloc_test_entry(key_val[i][0], key_val[i][1],
ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
}
for (size_t i = 0; i < ARRAY_SIZE(query); i++) {
entry = get_test_entry(map, query[i][0], ignore_case);
- if (check(entry != NULL))
- check_str(get_value(entry), query[i][1]);
- else
- test_msg("query key: %s", query[i][0]);
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(get_value(entry), query[i][1]);
}
- check_pointer_eq(get_test_entry(map, "notInMap", ignore_case), NULL);
- check_int(map->tablesize, ==, 64);
- check_int(hashmap_get_size(map), ==, ARRAY_SIZE(key_val));
+ cl_assert_equal_p(get_test_entry(map, "notInMap", ignore_case), NULL);
+ cl_assert_equal_i(map->tablesize, 64);
+ cl_assert_equal_i(hashmap_get_size(map), ARRAY_SIZE(key_val));
}
static void t_add(struct hashmap *map, unsigned int ignore_case)
@@ -165,39 +163,19 @@ static void t_add(struct hashmap *map, unsigned int ignore_case)
hashmap_for_each_entry_from(map, entry, ent)
{
- int ret;
- if (!check_int((ret = key_val_contains(
- key_val, seen,
- ARRAY_SIZE(key_val), entry)),
- ==, 0)) {
- switch (ret) {
- case 1:
- test_msg("found entry was not given in the input\n"
- " key: %s\n value: %s",
- entry->key, get_value(entry));
- break;
- case 2:
- test_msg("duplicate entry detected\n"
- " key: %s\n value: %s",
- entry->key, get_value(entry));
- break;
- }
- } else {
- count++;
- }
+ int ret = key_val_contains(key_val, seen,
+ ARRAY_SIZE(key_val), entry);
+ cl_assert_equal_i(ret, 0);
+ count++;
}
- check_int(count, ==, 2);
+ cl_assert_equal_i(count, 2);
}
- for (size_t i = 0; i < ARRAY_SIZE(seen); i++) {
- if (!check_int(seen[i], ==, 1))
- test_msg("following key-val pair was not iterated over:\n"
- " key: %s\n value: %s",
- key_val[i][0], key_val[i][1]);
- }
+ for (size_t i = 0; i < ARRAY_SIZE(seen); i++)
+ cl_assert_equal_i(seen[i], 1);
- check_int(hashmap_get_size(map), ==, ARRAY_SIZE(key_val));
- check_pointer_eq(get_test_entry(map, "notInMap", ignore_case), NULL);
+ cl_assert_equal_i(hashmap_get_size(map), ARRAY_SIZE(key_val));
+ cl_assert_equal_p(get_test_entry(map, "notInMap", ignore_case), NULL);
}
static void t_remove(struct hashmap *map, unsigned int ignore_case)
@@ -211,24 +189,25 @@ static void t_remove(struct hashmap *map, unsigned int ignore_case)
for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
entry = alloc_test_entry(key_val[i][0], key_val[i][1], ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
}
for (size_t i = 0; i < ARRAY_SIZE(remove); i++) {
entry = alloc_test_entry(remove[i][0], "", ignore_case);
removed = hashmap_remove_entry(map, entry, ent, remove[i][0]);
- if (check(removed != NULL))
- check_str(get_value(removed), remove[i][1]);
+ cl_assert(removed != NULL);
+ cl_assert_equal_s(get_value(removed), remove[i][1]);
free(entry);
free(removed);
}
entry = alloc_test_entry("notInMap", "", ignore_case);
- check_pointer_eq(hashmap_remove_entry(map, entry, ent, "notInMap"), NULL);
+ cl_assert_equal_p(hashmap_remove_entry(map, entry, ent, "notInMap"), NULL);
free(entry);
- check_int(map->tablesize, ==, 64);
- check_int(hashmap_get_size(map), ==, ARRAY_SIZE(key_val) - ARRAY_SIZE(remove));
+ cl_assert_equal_i(map->tablesize, 64);
+ cl_assert_equal_i(hashmap_get_size(map),
+ ARRAY_SIZE(key_val) - ARRAY_SIZE(remove));
}
static void t_iterate(struct hashmap *map, unsigned int ignore_case)
@@ -242,38 +221,21 @@ static void t_iterate(struct hashmap *map, unsigned int ignore_case)
for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
entry = alloc_test_entry(key_val[i][0], key_val[i][1], ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
}
hashmap_for_each_entry(map, &iter, entry, ent /* member name */)
{
- int ret;
- if (!check_int((ret = key_val_contains(key_val, seen,
- ARRAY_SIZE(key_val),
- entry)), ==, 0)) {
- switch (ret) {
- case 1:
- test_msg("found entry was not given in the input\n"
- " key: %s\n value: %s",
- entry->key, get_value(entry));
- break;
- case 2:
- test_msg("duplicate entry detected\n"
- " key: %s\n value: %s",
- entry->key, get_value(entry));
- break;
- }
- }
+ int ret = key_val_contains(key_val, seen,
+ ARRAY_SIZE(key_val),
+ entry);
+ cl_assert(ret == 0);
}
- for (size_t i = 0; i < ARRAY_SIZE(seen); i++) {
- if (!check_int(seen[i], ==, 1))
- test_msg("following key-val pair was not iterated over:\n"
- " key: %s\n value: %s",
- key_val[i][0], key_val[i][1]);
- }
+ for (size_t i = 0; i < ARRAY_SIZE(seen); i++)
+ cl_assert_equal_i(seen[i], 1);
- check_int(hashmap_get_size(map), ==, ARRAY_SIZE(key_val));
+ cl_assert_equal_i(hashmap_get_size(map), ARRAY_SIZE(key_val));
}
static void t_alloc(struct hashmap *map, unsigned int ignore_case)
@@ -284,17 +246,17 @@ static void t_alloc(struct hashmap *map, unsigned int ignore_case)
char *key = xstrfmt("key%d", i);
char *value = xstrfmt("value%d", i);
entry = alloc_test_entry(key, value, ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
free(key);
free(value);
}
- check_int(map->tablesize, ==, 64);
- check_int(hashmap_get_size(map), ==, 51);
+ cl_assert_equal_i(map->tablesize, 64);
+ cl_assert_equal_i(hashmap_get_size(map), 51);
entry = alloc_test_entry("key52", "value52", ignore_case);
- check_pointer_eq(hashmap_put_entry(map, entry, ent), NULL);
- check_int(map->tablesize, ==, 256);
- check_int(hashmap_get_size(map), ==, 52);
+ cl_assert_equal_p(hashmap_put_entry(map, entry, ent), NULL);
+ cl_assert_equal_i(map->tablesize, 256);
+ cl_assert_equal_i(hashmap_get_size(map), 52);
for (int i = 1; i <= 12; i++) {
char *key = xstrfmt("key%d", i);
@@ -302,27 +264,27 @@ static void t_alloc(struct hashmap *map, unsigned int ignore_case)
entry = alloc_test_entry(key, "", ignore_case);
removed = hashmap_remove_entry(map, entry, ent, key);
- if (check(removed != NULL))
- check_str(value, get_value(removed));
+ cl_assert(removed != NULL);
+ cl_assert_equal_s(value, get_value(removed));
free(key);
free(value);
free(entry);
free(removed);
}
- check_int(map->tablesize, ==, 256);
- check_int(hashmap_get_size(map), ==, 40);
+ cl_assert_equal_i(map->tablesize, 256);
+ cl_assert_equal_i(hashmap_get_size(map), 40);
entry = alloc_test_entry("key40", "", ignore_case);
removed = hashmap_remove_entry(map, entry, ent, "key40");
- if (check(removed != NULL))
- check_str("value40", get_value(removed));
- check_int(map->tablesize, ==, 64);
- check_int(hashmap_get_size(map), ==, 39);
+ cl_assert(removed != NULL);
+ cl_assert_equal_s("value40", get_value(removed));
+ cl_assert_equal_i(map->tablesize, 64);
+ cl_assert_equal_i(hashmap_get_size(map), 39);
free(entry);
free(removed);
}
-static void t_intern(void)
+void test_hashmap__intern(void)
{
const char *values[] = { "value1", "Value1", "value2", "value2" };
@@ -330,32 +292,68 @@ static void t_intern(void)
const char *i1 = strintern(values[i]);
const char *i2 = strintern(values[i]);
- if (!check(!strcmp(i1, values[i])))
- test_msg("strintern(%s) returns %s\n", values[i], i1);
- else if (!check(i1 != values[i]))
- test_msg("strintern(%s) returns input pointer\n",
- values[i]);
- else if (!check_pointer_eq(i1, i2))
- test_msg("address('%s') != address('%s'), so strintern('%s') != strintern('%s')",
- i1, i2, values[i], values[i]);
- else
- check_str(i1, values[i]);
+ cl_assert_equal_s(i1, values[i]);
+ cl_assert(i1 != values[i]);
+ cl_assert_equal_p(i1, i2);
}
}
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
+void test_hashmap__replace_case_sensitive(void)
+{
+ setup(t_replace, 0);
+}
+
+void test_hashmap__replace_case_insensitive(void)
+{
+ setup(t_replace, 1);
+}
+
+void test_hashmap__get_case_sensitive(void)
+{
+ setup(t_get, 0);
+}
+
+void test_hashmap__get_case_insensitive(void)
+{
+ setup(t_get, 1);
+}
+
+void test_hashmap__add_case_sensitive(void)
+{
+ setup(t_add, 0);
+}
+
+void test_hashmap__add_case_insensitive(void)
+{
+ setup(t_add, 1);
+}
+
+void test_hashmap__remove_case_sensitive(void)
+{
+ setup(t_remove, 0);
+}
+
+void test_hashmap__remove_case_insensitive(void)
+{
+ setup(t_remove, 1);
+}
+
+void test_hashmap__iterate_case_sensitive(void)
+{
+ setup(t_iterate, 0);
+}
+
+void test_hashmap__iterate_case_insensitive(void)
+{
+ setup(t_iterate, 1);
+}
+
+void test_hashmap__alloc_case_sensitive(void)
+{
+ setup(t_alloc, 0);
+}
+
+void test_hashmap__alloc_case_insensitive(void)
{
- TEST(setup(t_replace, 0), "replace works");
- TEST(setup(t_replace, 1), "replace (case insensitive) works");
- TEST(setup(t_get, 0), "get works");
- TEST(setup(t_get, 1), "get (case insensitive) works");
- TEST(setup(t_add, 0), "add works");
- TEST(setup(t_add, 1), "add (case insensitive) works");
- TEST(setup(t_remove, 0), "remove works");
- TEST(setup(t_remove, 1), "remove (case insensitive) works");
- TEST(setup(t_iterate, 0), "iterate works");
- TEST(setup(t_iterate, 1), "iterate (case insensitive) works");
- TEST(setup(t_alloc, 0), "grow / shrink works");
- TEST(t_intern(), "string interning works");
- return test_done();
+ setup(t_alloc, 1);
}
diff --git a/t/unit-tests/u-mem-pool.c b/t/unit-tests/u-mem-pool.c
new file mode 100644
index 0000000000..2bc2493b7e
--- /dev/null
+++ b/t/unit-tests/u-mem-pool.c
@@ -0,0 +1,25 @@
+#include "unit-test.h"
+#include "mem-pool.h"
+
+static void test_many_pool_allocations(size_t block_alloc)
+{
+ struct mem_pool pool = { .block_alloc = block_alloc };
+ size_t size = 100;
+ char *buffer = mem_pool_calloc(&pool, 1, size);
+ for (size_t i = 0; i < size; i++)
+ cl_assert_equal_i(0, buffer[i]);
+ cl_assert(pool.mp_block != NULL);
+ cl_assert(pool.mp_block->next_free != NULL);
+ cl_assert(pool.mp_block->end != NULL);
+ mem_pool_discard(&pool, 0);
+}
+
+void test_mem_pool__big_block(void)
+{
+ test_many_pool_allocations(1024 * 1024);
+}
+
+void test_mem_pool__tiny_block(void)
+{
+ test_many_pool_allocations(1);
+}
diff --git a/t/unit-tests/u-oid-array.c b/t/unit-tests/u-oid-array.c
new file mode 100644
index 0000000000..e48a433f21
--- /dev/null
+++ b/t/unit-tests/u-oid-array.c
@@ -0,0 +1,129 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
+#include "unit-test.h"
+#include "lib-oid.h"
+#include "oid-array.h"
+#include "hex.h"
+
+static void fill_array(struct oid_array *array, const char *hexes[], size_t n)
+{
+ for (size_t i = 0; i < n; i++) {
+ struct object_id oid;
+
+ cl_parse_any_oid(hexes[i], &oid);
+ oid_array_append(array, &oid);
+ }
+ cl_assert_equal_i(array->nr, n);
+}
+
+static int add_to_oid_array(const struct object_id *oid, void *data)
+{
+ struct oid_array *array = data;
+
+ oid_array_append(array, oid);
+ return 0;
+}
+
+static void t_enumeration(const char **input_args, size_t input_sz,
+ const char **expect_args, size_t expect_sz)
+{
+ struct oid_array input = OID_ARRAY_INIT, expect = OID_ARRAY_INIT,
+ actual = OID_ARRAY_INIT;
+ size_t i;
+
+ fill_array(&input, input_args, input_sz);
+ fill_array(&expect, expect_args, expect_sz);
+
+ oid_array_for_each_unique(&input, add_to_oid_array, &actual);
+ cl_assert_equal_i(actual.nr, expect.nr);
+
+ for (i = 0; i < actual.nr; i++)
+ cl_assert(oideq(&actual.oid[i], &expect.oid[i]));
+
+ oid_array_clear(&actual);
+ oid_array_clear(&input);
+ oid_array_clear(&expect);
+}
+
+#define TEST_ENUMERATION(input, expect) \
+ t_enumeration(input, ARRAY_SIZE(input), expect, ARRAY_SIZE(expect));
+
+static void t_lookup(const char **input_hexes, size_t n, const char *query_hex,
+ int lower_bound, int upper_bound)
+{
+ struct oid_array array = OID_ARRAY_INIT;
+ struct object_id oid_query;
+ int ret;
+
+ cl_parse_any_oid(query_hex, &oid_query);
+ fill_array(&array, input_hexes, n);
+ ret = oid_array_lookup(&array, &oid_query);
+
+ cl_assert(ret <= upper_bound);
+ cl_assert(ret >= lower_bound);
+
+ oid_array_clear(&array);
+}
+
+#define TEST_LOOKUP(input_hexes, query, lower_bound, upper_bound) \
+ t_lookup(input_hexes, ARRAY_SIZE(input_hexes), query, \
+ lower_bound, upper_bound);
+
+void test_oid_array__initialize(void)
+{
+ /* The hash algo is used by oid_array_lookup() internally */
+ int algo = cl_setup_hash_algo();
+ repo_set_hash_algo(the_repository, algo);
+}
+
+static const char *arr_input[] = { "88", "44", "aa", "55" };
+static const char *arr_input_dup[] = { "88", "44", "aa", "55",
+ "88", "44", "aa", "55",
+ "88", "44", "aa", "55" };
+static const char *res_sorted[] = { "44", "55", "88", "aa" };
+
+void test_oid_array__enumerate_unique(void)
+{
+ TEST_ENUMERATION(arr_input, res_sorted);
+}
+
+void test_oid_array__enumerate_duplicate(void)
+{
+ TEST_ENUMERATION(arr_input_dup, res_sorted);
+}
+
+void test_oid_array__lookup(void)
+{
+ TEST_LOOKUP(arr_input, "55", 1, 1);
+}
+
+void test_oid_array__lookup_non_existent(void)
+{
+ TEST_LOOKUP(arr_input, "33", INT_MIN, -1);
+}
+
+void test_oid_array__lookup_duplicates(void)
+{
+ TEST_LOOKUP(arr_input_dup, "55", 3, 5);
+}
+
+void test_oid_array__lookup_non_existent_dup(void)
+{
+ TEST_LOOKUP(arr_input_dup, "66", INT_MIN, -1);
+}
+
+void test_oid_array__lookup_almost_dup(void)
+{
+ const char *nearly_55;
+
+ nearly_55 = cl_setup_hash_algo() == GIT_HASH_SHA1 ?
+ "5500000000000000000000000000000000000001" :
+ "5500000000000000000000000000000000000000000000000000000000000001";
+
+ TEST_LOOKUP(((const char *[]){ "55", nearly_55 }), "55", 0, 0);
+}
+
+void test_oid_array__lookup_single_dup(void)
+{
+ TEST_LOOKUP(((const char *[]){ "55", "55" }), "55", 0, 1);
+}
diff --git a/t/unit-tests/u-oidmap.c b/t/unit-tests/u-oidmap.c
new file mode 100644
index 0000000000..b23af449f6
--- /dev/null
+++ b/t/unit-tests/u-oidmap.c
@@ -0,0 +1,136 @@
+#include "unit-test.h"
+#include "lib-oid.h"
+#include "oidmap.h"
+#include "hash.h"
+#include "hex.h"
+
+/*
+ * Elements we will put in oidmap structs are made of a key: the entry.oid
+ * field, which is of type struct object_id, and a value: the name field (could
+ * be a refname for example).
+ */
+struct test_entry {
+ struct oidmap_entry entry;
+ char name[FLEX_ARRAY];
+};
+
+static const char *const key_val[][2] = { { "11", "one" },
+ { "22", "two" },
+ { "33", "three" } };
+
+static struct oidmap map;
+
+void test_oidmap__initialize(void)
+{
+ oidmap_init(&map, 0);
+
+ for (size_t i = 0; i < ARRAY_SIZE(key_val); i++){
+ struct test_entry *entry;
+
+ FLEX_ALLOC_STR(entry, name, key_val[i][1]);
+ cl_parse_any_oid(key_val[i][0], &entry->entry.oid);
+ cl_assert(oidmap_put(&map, entry) == NULL);
+ }
+}
+
+void test_oidmap__cleanup(void)
+{
+ oidmap_clear(&map, 1);
+}
+
+void test_oidmap__replace(void)
+{
+ struct test_entry *entry, *prev;
+
+ FLEX_ALLOC_STR(entry, name, "un");
+ cl_parse_any_oid("11", &entry->entry.oid);
+ prev = oidmap_put(&map, entry);
+ cl_assert(prev != NULL);
+ cl_assert_equal_s(prev->name, "one");
+ free(prev);
+
+ FLEX_ALLOC_STR(entry, name, "deux");
+ cl_parse_any_oid("22", &entry->entry.oid);
+ prev = oidmap_put(&map, entry);
+ cl_assert(prev != NULL);
+ cl_assert_equal_s(prev->name, "two");
+ free(prev);
+}
+
+void test_oidmap__get(void)
+{
+ struct test_entry *entry;
+ struct object_id oid;
+
+ cl_parse_any_oid("22", &oid);
+ entry = oidmap_get(&map, &oid);
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(entry->name, "two");
+
+ cl_parse_any_oid("44", &oid);
+ cl_assert(oidmap_get(&map, &oid) == NULL);
+
+ cl_parse_any_oid("11", &oid);
+ entry = oidmap_get(&map, &oid);
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(entry->name, "one");
+}
+
+void test_oidmap__remove(void)
+{
+ struct test_entry *entry;
+ struct object_id oid;
+
+ cl_parse_any_oid("11", &oid);
+ entry = oidmap_remove(&map, &oid);
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(entry->name, "one");
+ cl_assert(oidmap_get(&map, &oid) == NULL);
+ free(entry);
+
+ cl_parse_any_oid("22", &oid);
+ entry = oidmap_remove(&map, &oid);
+ cl_assert(entry != NULL);
+ cl_assert_equal_s(entry->name, "two");
+ cl_assert(oidmap_get(&map, &oid) == NULL);
+ free(entry);
+
+ cl_parse_any_oid("44", &oid);
+ cl_assert(oidmap_remove(&map, &oid) == NULL);
+}
+
+static int key_val_contains(struct test_entry *entry, char seen[])
+{
+ for (size_t i = 0; i < ARRAY_SIZE(key_val); i++) {
+ struct object_id oid;
+
+ cl_parse_any_oid(key_val[i][0], &oid);
+
+ if (oideq(&entry->entry.oid, &oid)) {
+ if (seen[i])
+ return 2;
+ seen[i] = 1;
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void test_oidmap__iterate(void)
+{
+ struct oidmap_iter iter;
+ struct test_entry *entry;
+ char seen[ARRAY_SIZE(key_val)] = { 0 };
+ int count = 0;
+
+ oidmap_iter_init(&map, &iter);
+ while ((entry = oidmap_iter_next(&iter))) {
+ if (key_val_contains(entry, seen) != 0) {
+ cl_failf("Unexpected entry: name = %s, oid = %s",
+ entry->name, oid_to_hex(&entry->entry.oid));
+ }
+ count++;
+ }
+ cl_assert_equal_i(count, ARRAY_SIZE(key_val));
+ cl_assert_equal_i(hashmap_get_size(&map.map), ARRAY_SIZE(key_val));
+}
diff --git a/t/unit-tests/u-oidtree.c b/t/unit-tests/u-oidtree.c
new file mode 100644
index 0000000000..e6eede2740
--- /dev/null
+++ b/t/unit-tests/u-oidtree.c
@@ -0,0 +1,107 @@
+#include "unit-test.h"
+#include "lib-oid.h"
+#include "oidtree.h"
+#include "hash.h"
+#include "hex.h"
+#include "strvec.h"
+
+static struct oidtree ot;
+
+#define FILL_TREE(tree, ...) \
+ do { \
+ const char *hexes[] = { __VA_ARGS__ }; \
+ if (fill_tree_loc(tree, hexes, ARRAY_SIZE(hexes))) \
+ return; \
+ } while (0)
+
+static int fill_tree_loc(struct oidtree *ot, const char *hexes[], size_t n)
+{
+ for (size_t i = 0; i < n; i++) {
+ struct object_id oid;
+ cl_parse_any_oid(hexes[i], &oid);
+ oidtree_insert(ot, &oid);
+ }
+ return 0;
+}
+
+static void check_contains(struct oidtree *ot, const char *hex, int expected)
+{
+ struct object_id oid;
+
+ cl_parse_any_oid(hex, &oid);
+ cl_assert_equal_i(oidtree_contains(ot, &oid), expected);
+}
+
+struct expected_hex_iter {
+ size_t i;
+ struct strvec expected_hexes;
+ const char *query;
+};
+
+static enum cb_next check_each_cb(const struct object_id *oid, void *data)
+{
+ struct expected_hex_iter *hex_iter = data;
+ struct object_id expected;
+
+ cl_assert(hex_iter->i < hex_iter->expected_hexes.nr);
+
+ cl_parse_any_oid(hex_iter->expected_hexes.v[hex_iter->i],
+ &expected);
+ cl_assert_equal_s(oid_to_hex(oid), oid_to_hex(&expected));
+ hex_iter->i += 1;
+ return CB_CONTINUE;
+}
+
+LAST_ARG_MUST_BE_NULL
+static void check_each(struct oidtree *ot, const char *query, ...)
+{
+ struct object_id oid;
+ struct expected_hex_iter hex_iter = { .expected_hexes = STRVEC_INIT,
+ .query = query };
+ const char *arg;
+ va_list hex_args;
+
+ va_start(hex_args, query);
+ while ((arg = va_arg(hex_args, const char *)))
+ strvec_push(&hex_iter.expected_hexes, arg);
+ va_end(hex_args);
+
+ cl_parse_any_oid(query, &oid);
+ oidtree_each(ot, &oid, strlen(query), check_each_cb, &hex_iter);
+
+ if (hex_iter.i != hex_iter.expected_hexes.nr)
+ cl_failf("error: could not find some 'object_id's for query ('%s')", query);
+
+ strvec_clear(&hex_iter.expected_hexes);
+}
+
+void test_oidtree__initialize(void)
+{
+ oidtree_init(&ot);
+}
+
+void test_oidtree__cleanup(void)
+{
+ oidtree_clear(&ot);
+}
+
+void test_oidtree__contains(void)
+{
+ FILL_TREE(&ot, "444", "1", "2", "3", "4", "5", "a", "b", "c", "d", "e");
+ check_contains(&ot, "44", 0);
+ check_contains(&ot, "441", 0);
+ check_contains(&ot, "440", 0);
+ check_contains(&ot, "444", 1);
+ check_contains(&ot, "4440", 1);
+ check_contains(&ot, "4444", 0);
+}
+
+void test_oidtree__each(void)
+{
+ FILL_TREE(&ot, "f", "9", "8", "123", "321", "320", "a", "b", "c", "d", "e");
+ check_each(&ot, "12300", "123", NULL);
+ check_each(&ot, "3211", NULL); /* should not reach callback */
+ check_each(&ot, "3210", "321", NULL);
+ check_each(&ot, "32100", "321", NULL);
+ check_each(&ot, "32", "320", "321", NULL);
+}
diff --git a/t/unit-tests/u-prio-queue.c b/t/unit-tests/u-prio-queue.c
new file mode 100644
index 0000000000..63e58114ae
--- /dev/null
+++ b/t/unit-tests/u-prio-queue.c
@@ -0,0 +1,117 @@
+#include "unit-test.h"
+#include "prio-queue.h"
+
+static int intcmp(const void *va, const void *vb, void *data UNUSED)
+{
+ const int *a = va, *b = vb;
+ return *a - *b;
+}
+
+
+#define MISSING -1
+#define DUMP -2
+#define STACK -3
+#define GET -4
+#define REVERSE -5
+#define REPLACE -6
+
+static int show(int *v)
+{
+ return v ? *v : MISSING;
+}
+
+static void test_prio_queue(int *input, size_t input_size,
+ int *result, size_t result_size)
+{
+ struct prio_queue pq = { intcmp };
+ size_t j = 0;
+
+ for (size_t i = 0; i < input_size; i++) {
+ void *peek, *get;
+ switch(input[i]) {
+ case GET:
+ peek = prio_queue_peek(&pq);
+ get = prio_queue_get(&pq);
+ cl_assert(peek == get);
+ cl_assert(j < result_size);
+ cl_assert_equal_i(result[j], show(get));
+ j++;
+ break;
+ case DUMP:
+ while ((peek = prio_queue_peek(&pq))) {
+ get = prio_queue_get(&pq);
+ cl_assert(peek == get);
+ cl_assert(j < result_size);
+ cl_assert_equal_i(result[j], show(get));
+ j++;
+ }
+ break;
+ case STACK:
+ pq.compare = NULL;
+ break;
+ case REVERSE:
+ prio_queue_reverse(&pq);
+ break;
+ case REPLACE:
+ peek = prio_queue_peek(&pq);
+ cl_assert(i + 1 < input_size);
+ cl_assert(input[i + 1] >= 0);
+ cl_assert(j < result_size);
+ cl_assert_equal_i(result[j], show(peek));
+ j++;
+ prio_queue_replace(&pq, &input[++i]);
+ break;
+ default:
+ prio_queue_put(&pq, &input[i]);
+ break;
+ }
+ }
+ cl_assert_equal_i(j, result_size);
+ clear_prio_queue(&pq);
+}
+
+#define TEST_INPUT(input, result) \
+ test_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))
+
+void test_prio_queue__basic(void)
+{
+ TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),
+ ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 }));
+}
+
+void test_prio_queue__mixed(void)
+{
+ TEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),
+ ((int []){ 2, 3, 4, 1, 5, 6 }));
+}
+
+void test_prio_queue__empty(void)
+{
+ TEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),
+ ((int []){ 1, 2, MISSING, 1, 2, MISSING }));
+}
+
+void test_prio_queue__replace(void)
+{
+ TEST_INPUT(((int []){ REPLACE, 6, 2, 4, REPLACE, 5, 7, GET,
+ REPLACE, 1, DUMP }),
+ ((int []){ MISSING, 2, 4, 5, 1, 6, 7 }));
+}
+
+void test_prio_queue__stack(void)
+{
+ TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),
+ ((int []){ 3, 2, 6, 4, 5, 1, 8 }));
+}
+
+void test_prio_queue__reverse_stack(void)
+{
+ TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),
+ ((int []){ 1, 2, 3, 4, 5, 6 }));
+}
+
+void test_prio_queue__replace_stack(void)
+{
+ TEST_INPUT(((int []){ STACK, 8, 1, 5, REPLACE, 4, 6, 2, 3, DUMP }),
+ ((int []){ 5, 3, 2, 6, 4, 1, 8 }));
+}
diff --git a/t/unit-tests/u-reftable-basics.c b/t/unit-tests/u-reftable-basics.c
new file mode 100644
index 0000000000..a0471083e7
--- /dev/null
+++ b/t/unit-tests/u-reftable-basics.c
@@ -0,0 +1,227 @@
+/*
+Copyright 2020 Google LLC
+
+Use of this source code is governed by a BSD-style
+license that can be found in the LICENSE file or at
+https://developers.google.com/open-source/licenses/bsd
+*/
+
+#include "unit-test.h"
+#include "lib-reftable.h"
+#include "reftable/basics.h"
+
+struct integer_needle_lesseq_args {
+ int needle;
+ int *haystack;
+};
+
+static int integer_needle_lesseq(size_t i, void *_args)
+{
+ struct integer_needle_lesseq_args *args = _args;
+ return args->needle <= args->haystack[i];
+}
+
+static void *realloc_stub(void *p UNUSED, size_t size UNUSED)
+{
+ return NULL;
+}
+
+void test_reftable_basics__binsearch(void)
+{
+ int haystack[] = { 2, 4, 6, 8, 10 };
+ struct {
+ int needle;
+ size_t expected_idx;
+ } testcases[] = {
+ {-9000, 0},
+ {-1, 0},
+ {0, 0},
+ {2, 0},
+ {3, 1},
+ {4, 1},
+ {7, 3},
+ {9, 4},
+ {10, 4},
+ {11, 5},
+ {9000, 5},
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
+ struct integer_needle_lesseq_args args = {
+ .haystack = haystack,
+ .needle = testcases[i].needle,
+ };
+ size_t idx;
+
+ idx = binsearch(ARRAY_SIZE(haystack),
+ &integer_needle_lesseq, &args);
+ cl_assert_equal_i(idx, testcases[i].expected_idx);
+ }
+}
+
+void test_reftable_basics__names_length(void)
+{
+ const char *a[] = { "a", "b", NULL };
+ cl_assert_equal_i(names_length(a), 2);
+}
+
+void test_reftable_basics__names_equal(void)
+{
+ const char *a[] = { "a", "b", "c", NULL };
+ const char *b[] = { "a", "b", "d", NULL };
+ const char *c[] = { "a", "b", NULL };
+
+ cl_assert(names_equal(a, a));
+ cl_assert(!names_equal(a, b));
+ cl_assert(!names_equal(a, c));
+}
+
+void test_reftable_basics__parse_names(void)
+{
+ char in1[] = "line\n";
+ char in2[] = "a\nb\nc";
+ char **out = parse_names(in1, strlen(in1));
+ cl_assert(out != NULL);
+ cl_assert_equal_s(out[0], "line");
+ cl_assert(!out[1]);
+ free_names(out);
+
+ out = parse_names(in2, strlen(in2));
+ cl_assert(out != NULL);
+ cl_assert_equal_s(out[0], "a");
+ cl_assert_equal_s(out[1], "b");
+ cl_assert_equal_s(out[2], "c");
+ cl_assert(!out[3]);
+ free_names(out);
+}
+
+void test_reftable_basics__parse_names_drop_empty_string(void)
+{
+ char in[] = "a\n\nb\n";
+ char **out = parse_names(in, strlen(in));
+ cl_assert(out != NULL);
+ cl_assert_equal_s(out[0], "a");
+ /* simply '\n' should be dropped as empty string */
+ cl_assert_equal_s(out[1], "b");
+ cl_assert(out[2] == NULL);
+ free_names(out);
+}
+
+void test_reftable_basics__common_prefix_size(void)
+{
+ struct reftable_buf a = REFTABLE_BUF_INIT;
+ struct reftable_buf b = REFTABLE_BUF_INIT;
+ struct {
+ const char *a, *b;
+ int want;
+ } cases[] = {
+ {"abcdef", "abc", 3},
+ { "abc", "ab", 2 },
+ { "", "abc", 0 },
+ { "abc", "abd", 2 },
+ { "abc", "pqr", 0 },
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
+ cl_assert_equal_i(reftable_buf_addstr(&a, cases[i].a), 0);
+ cl_assert_equal_i(reftable_buf_addstr(&b, cases[i].b), 0);
+ cl_assert_equal_i(common_prefix_size(&a, &b), cases[i].want);
+ reftable_buf_reset(&a);
+ reftable_buf_reset(&b);
+ }
+ reftable_buf_release(&a);
+ reftable_buf_release(&b);
+}
+
+void test_reftable_basics__put_get_be64(void)
+{
+ uint64_t in = 0x1122334455667788;
+ uint8_t dest[8];
+ uint64_t out;
+ reftable_put_be64(dest, in);
+ out = reftable_get_be64(dest);
+ cl_assert(in == out);
+}
+
+void test_reftable_basics__put_get_be32(void)
+{
+ uint32_t in = 0x11223344;
+ uint8_t dest[4];
+ uint32_t out;
+ reftable_put_be32(dest, in);
+ out = reftable_get_be32(dest);
+ cl_assert_equal_i(in, out);
+}
+
+void test_reftable_basics__put_get_be24(void)
+{
+ uint32_t in = 0x112233;
+ uint8_t dest[3];
+ uint32_t out;
+ reftable_put_be24(dest, in);
+ out = reftable_get_be24(dest);
+ cl_assert_equal_i(in, out);
+}
+
+void test_reftable_basics__put_get_be16(void)
+{
+ uint32_t in = 0xfef1;
+ uint8_t dest[3];
+ uint32_t out;
+ reftable_put_be16(dest, in);
+ out = reftable_get_be16(dest);
+ cl_assert_equal_i(in, out);
+}
+
+void test_reftable_basics__alloc_grow(void)
+{
+ int *arr = NULL, *old_arr;
+ size_t alloc = 0, old_alloc;
+
+ cl_assert_equal_i(REFTABLE_ALLOC_GROW(arr, 1, alloc), 0);
+ cl_assert(arr != NULL);
+ cl_assert(alloc >= 1);
+ arr[0] = 42;
+
+ old_alloc = alloc;
+ old_arr = arr;
+ reftable_set_alloc(NULL, realloc_stub, NULL);
+ cl_assert(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
+ cl_assert(arr == old_arr);
+ cl_assert_equal_i(alloc, old_alloc);
+
+ old_alloc = alloc;
+ reftable_set_alloc(NULL, NULL, NULL);
+ cl_assert_equal_i(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc), 0);
+ cl_assert(arr != NULL);
+ cl_assert(alloc > old_alloc);
+ arr[alloc - 1] = 42;
+
+ reftable_free(arr);
+}
+
+void test_reftable_basics__alloc_grow_or_null(void)
+{
+ int *arr = NULL;
+ size_t alloc = 0, old_alloc;
+
+ REFTABLE_ALLOC_GROW_OR_NULL(arr, 1, alloc);
+ cl_assert(arr != NULL);
+ cl_assert(alloc >= 1);
+ arr[0] = 42;
+
+ old_alloc = alloc;
+ REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
+ cl_assert(arr != NULL);
+ cl_assert(alloc > old_alloc);
+ arr[alloc - 1] = 42;
+
+ old_alloc = alloc;
+ reftable_set_alloc(NULL, realloc_stub, NULL);
+ REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
+ cl_assert(arr == NULL);
+ cl_assert_equal_i(alloc, 0);
+ reftable_set_alloc(NULL, NULL, NULL);
+
+ reftable_free(arr);
+}
diff --git a/t/unit-tests/u-reftable-block.c b/t/unit-tests/u-reftable-block.c
new file mode 100644
index 0000000000..f4bded7d26
--- /dev/null
+++ b/t/unit-tests/u-reftable-block.c
@@ -0,0 +1,458 @@
+/*
+Copyright 2020 Google LLC
+
+Use of this source code is governed by a BSD-style
+license that can be found in the LICENSE file or at
+https://developers.google.com/open-source/licenses/bsd
+*/
+
+#include "unit-test.h"
+#include "lib-reftable.h"
+#include "reftable/block.h"
+#include "reftable/blocksource.h"
+#include "reftable/constants.h"
+#include "reftable/reftable-error.h"
+#include "strbuf.h"
+
+void test_reftable_block__read_write(void)
+{
+ const int header_off = 21; /* random */
+ struct reftable_record recs[30];
+ const size_t N = ARRAY_SIZE(recs);
+ const size_t block_size = 1024;
+ struct reftable_block_source source = { 0 };
+ struct block_writer bw = {
+ .last_key = REFTABLE_BUF_INIT,
+ };
+ struct reftable_record rec = {
+ .type = REFTABLE_BLOCK_TYPE_REF,
+ };
+ size_t i = 0;
+ int ret;
+ struct reftable_block block = { 0 };
+ struct block_iter it = BLOCK_ITER_INIT;
+ struct reftable_buf want = REFTABLE_BUF_INIT;
+ struct reftable_buf block_data = REFTABLE_BUF_INIT;
+
+ REFTABLE_CALLOC_ARRAY(block_data.buf, block_size);
+ cl_assert(block_data.buf != NULL);
+ block_data.len = block_size;
+
+ ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_REF,
+ (uint8_t *) block_data.buf, block_size,
+ header_off, hash_size(REFTABLE_HASH_SHA1));
+ cl_assert(!ret);
+
+ rec.u.ref.refname = (char *) "";
+ rec.u.ref.value_type = REFTABLE_REF_DELETION;
+ ret = block_writer_add(&bw, &rec);
+ cl_assert_equal_i(ret, REFTABLE_API_ERROR);
+
+ for (i = 0; i < N; i++) {
+ rec.u.ref.refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
+ rec.u.ref.value_type = REFTABLE_REF_VAL1;
+ memset(rec.u.ref.value.val1, i, REFTABLE_HASH_SIZE_SHA1);
+
+ recs[i] = rec;
+ ret = block_writer_add(&bw, &rec);
+ rec.u.ref.refname = NULL;
+ rec.u.ref.value_type = REFTABLE_REF_DELETION;
+ cl_assert_equal_i(ret, 0);
+ }
+
+ ret = block_writer_finish(&bw);
+ cl_assert(ret > 0);
+
+ block_writer_release(&bw);
+
+ block_source_from_buf(&source ,&block_data);
+ reftable_block_init(&block, &source, 0, header_off, block_size,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_REF);
+
+ block_iter_init(&it, &block);
+
+ for (i = 0; ; i++) {
+ ret = block_iter_next(&it, &rec);
+ cl_assert(ret >= 0);
+ if (ret > 0) {
+ cl_assert_equal_i(i, N);
+ break;
+ }
+ cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+ }
+
+ for (i = 0; i < N; i++) {
+ reftable_record_key(&recs[i], &want);
+
+ ret = block_iter_seek_key(&it, &want);
+ cl_assert_equal_i(ret, 0);
+
+ ret = block_iter_next(&it, &rec);
+ cl_assert_equal_i(ret, 0);
+
+ cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+
+ want.len--;
+ ret = block_iter_seek_key(&it, &want);
+ cl_assert_equal_i(ret, 0);
+
+ ret = block_iter_next(&it, &rec);
+ cl_assert_equal_i(ret, 0);
+ cl_assert_equal_i(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+ }
+
+ reftable_block_release(&block);
+ block_iter_close(&it);
+ reftable_record_release(&rec);
+ reftable_buf_release(&want);
+ reftable_buf_release(&block_data);
+ for (i = 0; i < N; i++)
+ reftable_record_release(&recs[i]);
+}
+
+void test_reftable_block__log_read_write(void)
+{
+ const int header_off = 21;
+ struct reftable_record recs[30];
+ const size_t N = ARRAY_SIZE(recs);
+ const size_t block_size = 2048;
+ struct reftable_block_source source = { 0 };
+ struct block_writer bw = {
+ .last_key = REFTABLE_BUF_INIT,
+ };
+ struct reftable_record rec = {
+ .type = REFTABLE_BLOCK_TYPE_LOG,
+ };
+ size_t i = 0;
+ int ret;
+ struct reftable_block block = { 0 };
+ struct block_iter it = BLOCK_ITER_INIT;
+ struct reftable_buf want = REFTABLE_BUF_INIT;
+ struct reftable_buf block_data = REFTABLE_BUF_INIT;
+
+ REFTABLE_CALLOC_ARRAY(block_data.buf, block_size);
+ cl_assert(block_data.buf != NULL);
+ block_data.len = block_size;
+
+ ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_LOG, (uint8_t *) block_data.buf, block_size,
+ header_off, hash_size(REFTABLE_HASH_SHA1));
+ cl_assert(!ret);
+
+ for (i = 0; i < N; i++) {
+ rec.u.log.refname = xstrfmt("branch%02"PRIuMAX , (uintmax_t)i);
+ rec.u.log.update_index = i;
+ rec.u.log.value_type = REFTABLE_LOG_UPDATE;
+
+ recs[i] = rec;
+ ret = block_writer_add(&bw, &rec);
+ rec.u.log.refname = NULL;
+ rec.u.log.value_type = REFTABLE_LOG_DELETION;
+ cl_assert_equal_i(ret, 0);
+ }
+
+ ret = block_writer_finish(&bw);
+ cl_assert(ret > 0);
+
+ block_writer_release(&bw);
+
+ block_source_from_buf(&source, &block_data);
+ reftable_block_init(&block, &source, 0, header_off, block_size,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_LOG);
+
+ block_iter_init(&it, &block);
+
+ for (i = 0; ; i++) {
+ ret = block_iter_next(&it, &rec);
+ cl_assert(ret >= 0);
+ if (ret > 0) {
+ cl_assert_equal_i(i, N);
+ break;
+ }
+ cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+ }
+
+ for (i = 0; i < N; i++) {
+ reftable_buf_reset(&want);
+ cl_assert(reftable_buf_addstr(&want, recs[i].u.log.refname) == 0);
+
+ ret = block_iter_seek_key(&it, &want);
+ cl_assert_equal_i(ret, 0);
+
+ ret = block_iter_next(&it, &rec);
+ cl_assert_equal_i(ret, 0);
+
+ cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+
+ want.len--;
+ ret = block_iter_seek_key(&it, &want);
+ cl_assert_equal_i(ret, 0);
+
+ ret = block_iter_next(&it, &rec);
+ cl_assert_equal_i(ret, 0);
+ cl_assert_equal_i(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+ }
+
+ reftable_block_release(&block);
+ block_iter_close(&it);
+ reftable_record_release(&rec);
+ reftable_buf_release(&want);
+ reftable_buf_release(&block_data);
+ for (i = 0; i < N; i++)
+ reftable_record_release(&recs[i]);
+}
+
+void test_reftable_block__obj_read_write(void)
+{
+ const int header_off = 21;
+ struct reftable_record recs[30];
+ const size_t N = ARRAY_SIZE(recs);
+ const size_t block_size = 1024;
+ struct reftable_block_source source = { 0 };
+ struct block_writer bw = {
+ .last_key = REFTABLE_BUF_INIT,
+ };
+ struct reftable_record rec = {
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
+ };
+ size_t i = 0;
+ int ret;
+ struct reftable_block block = { 0 };
+ struct block_iter it = BLOCK_ITER_INIT;
+ struct reftable_buf want = REFTABLE_BUF_INIT;
+ struct reftable_buf block_data = REFTABLE_BUF_INIT;
+
+ REFTABLE_CALLOC_ARRAY(block_data.buf, block_size);
+ cl_assert(block_data.buf != NULL);
+ block_data.len = block_size;
+
+ ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_OBJ, (uint8_t *) block_data.buf, block_size,
+ header_off, hash_size(REFTABLE_HASH_SHA1));
+ cl_assert(!ret);
+
+ for (i = 0; i < N; i++) {
+ uint8_t bytes[] = { i, i + 1, i + 2, i + 3, i + 5 }, *allocated;
+ DUP_ARRAY(allocated, bytes, ARRAY_SIZE(bytes));
+
+ rec.u.obj.hash_prefix = allocated;
+ rec.u.obj.hash_prefix_len = 5;
+
+ recs[i] = rec;
+ ret = block_writer_add(&bw, &rec);
+ rec.u.obj.hash_prefix = NULL;
+ rec.u.obj.hash_prefix_len = 0;
+ cl_assert_equal_i(ret, 0);
+ }
+
+ ret = block_writer_finish(&bw);
+ cl_assert(ret > 0);
+
+ block_writer_release(&bw);
+
+ block_source_from_buf(&source, &block_data);
+ reftable_block_init(&block, &source, 0, header_off, block_size,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_OBJ);
+
+ block_iter_init(&it, &block);
+
+ for (i = 0; ; i++) {
+ ret = block_iter_next(&it, &rec);
+ cl_assert(ret >= 0);
+ if (ret > 0) {
+ cl_assert_equal_i(i, N);
+ break;
+ }
+ cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+ }
+
+ for (i = 0; i < N; i++) {
+ reftable_record_key(&recs[i], &want);
+
+ ret = block_iter_seek_key(&it, &want);
+ cl_assert_equal_i(ret, 0);
+
+ ret = block_iter_next(&it, &rec);
+ cl_assert_equal_i(ret, 0);
+
+ cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+ }
+
+ reftable_block_release(&block);
+ block_iter_close(&it);
+ reftable_record_release(&rec);
+ reftable_buf_release(&want);
+ reftable_buf_release(&block_data);
+ for (i = 0; i < N; i++)
+ reftable_record_release(&recs[i]);
+}
+
+void test_reftable_block__ref_read_write(void)
+{
+ const int header_off = 21;
+ struct reftable_record recs[30];
+ const size_t N = ARRAY_SIZE(recs);
+ const size_t block_size = 1024;
+ struct reftable_block_source source = { 0 };
+ struct block_writer bw = {
+ .last_key = REFTABLE_BUF_INIT,
+ };
+ struct reftable_record rec = {
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
+ .u.idx.last_key = REFTABLE_BUF_INIT,
+ };
+ size_t i = 0;
+ int ret;
+ struct reftable_block block = { 0 };
+ struct block_iter it = BLOCK_ITER_INIT;
+ struct reftable_buf want = REFTABLE_BUF_INIT;
+ struct reftable_buf block_data = REFTABLE_BUF_INIT;
+
+ REFTABLE_CALLOC_ARRAY(block_data.buf, block_size);
+ cl_assert(block_data.buf != NULL);
+ block_data.len = block_size;
+
+ ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_INDEX, (uint8_t *) block_data.buf, block_size,
+ header_off, hash_size(REFTABLE_HASH_SHA1));
+ cl_assert(!ret);
+
+ for (i = 0; i < N; i++) {
+ char buf[128];
+
+ snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i);
+
+ reftable_buf_init(&recs[i].u.idx.last_key);
+ recs[i].type = REFTABLE_BLOCK_TYPE_INDEX;
+ cl_assert(!reftable_buf_addstr(&recs[i].u.idx.last_key, buf));
+ recs[i].u.idx.offset = i;
+
+ ret = block_writer_add(&bw, &recs[i]);
+ cl_assert_equal_i(ret, 0);
+ }
+
+ ret = block_writer_finish(&bw);
+ cl_assert(ret > 0);
+
+ block_writer_release(&bw);
+
+ block_source_from_buf(&source, &block_data);
+ reftable_block_init(&block, &source, 0, header_off, block_size,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_INDEX);
+
+ block_iter_init(&it, &block);
+
+ for (i = 0; ; i++) {
+ ret = block_iter_next(&it, &rec);
+ cl_assert(ret >= 0);
+ if (ret > 0) {
+ cl_assert_equal_i(i, N);
+ break;
+ }
+ cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+ }
+
+ for (i = 0; i < N; i++) {
+ reftable_record_key(&recs[i], &want);
+
+ ret = block_iter_seek_key(&it, &want);
+ cl_assert_equal_i(ret, 0);
+
+ ret = block_iter_next(&it, &rec);
+ cl_assert_equal_i(ret, 0);
+
+ cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+
+ want.len--;
+ ret = block_iter_seek_key(&it, &want);
+ cl_assert_equal_i(ret, 0);
+
+ ret = block_iter_next(&it, &rec);
+ cl_assert_equal_i(ret, 0);
+ cl_assert_equal_i(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
+ }
+
+ reftable_block_release(&block);
+ block_iter_close(&it);
+ reftable_record_release(&rec);
+ reftable_buf_release(&want);
+ reftable_buf_release(&block_data);
+ for (i = 0; i < N; i++)
+ reftable_record_release(&recs[i]);
+}
+
+void test_reftable_block__iterator(void)
+{
+ struct reftable_block_source source = { 0 };
+ struct block_writer writer = {
+ .last_key = REFTABLE_BUF_INIT,
+ };
+ struct reftable_record expected_refs[20];
+ struct reftable_ref_record ref = { 0 };
+ struct reftable_iterator it = { 0 };
+ struct reftable_block block = { 0 };
+ struct reftable_buf data;
+ int err;
+
+ data.len = 1024;
+ REFTABLE_CALLOC_ARRAY(data.buf, data.len);
+ cl_assert(data.buf != NULL);
+
+ err = block_writer_init(&writer, REFTABLE_BLOCK_TYPE_REF,
+ (uint8_t *) data.buf, data.len,
+ 0, hash_size(REFTABLE_HASH_SHA1));
+ cl_assert(!err);
+
+ for (size_t i = 0; i < ARRAY_SIZE(expected_refs); i++) {
+ expected_refs[i] = (struct reftable_record) {
+ .type = REFTABLE_BLOCK_TYPE_REF,
+ .u.ref = {
+ .value_type = REFTABLE_REF_VAL1,
+ .refname = xstrfmt("refs/heads/branch-%02"PRIuMAX, (uintmax_t)i),
+ },
+ };
+ memset(expected_refs[i].u.ref.value.val1, i, REFTABLE_HASH_SIZE_SHA1);
+
+ err = block_writer_add(&writer, &expected_refs[i]);
+ cl_assert_equal_i(err, 0);
+ }
+
+ err = block_writer_finish(&writer);
+ cl_assert(err > 0);
+
+ block_source_from_buf(&source, &data);
+ reftable_block_init(&block, &source, 0, 0, data.len,
+ REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_REF);
+
+ err = reftable_block_init_iterator(&block, &it);
+ cl_assert_equal_i(err, 0);
+
+ for (size_t i = 0; ; i++) {
+ err = reftable_iterator_next_ref(&it, &ref);
+ if (err > 0) {
+ cl_assert_equal_i(i, ARRAY_SIZE(expected_refs));
+ break;
+ }
+ cl_assert_equal_i(err, 0);
+
+ cl_assert(reftable_ref_record_equal(&ref,
+ &expected_refs[i].u.ref, REFTABLE_HASH_SIZE_SHA1));
+ }
+
+ err = reftable_iterator_seek_ref(&it, "refs/heads/does-not-exist");
+ cl_assert_equal_i(err, 0);
+ err = reftable_iterator_next_ref(&it, &ref);
+ cl_assert_equal_i(err, 1);
+
+ err = reftable_iterator_seek_ref(&it, "refs/heads/branch-13");
+ cl_assert_equal_i(err, 0);
+ err = reftable_iterator_next_ref(&it, &ref);
+ cl_assert_equal_i(err, 0);
+ cl_assert(reftable_ref_record_equal(&ref,
+ &expected_refs[13].u.ref,REFTABLE_HASH_SIZE_SHA1));
+
+ for (size_t i = 0; i < ARRAY_SIZE(expected_refs); i++)
+ reftable_free(expected_refs[i].u.ref.refname);
+ reftable_ref_record_release(&ref);
+ reftable_iterator_destroy(&it);
+ reftable_block_release(&block);
+ block_writer_release(&writer);
+ reftable_buf_release(&data);
+}
diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/u-reftable-merged.c
index 60836f80d6..54cb7fc2a7 100644
--- a/t/unit-tests/t-reftable-merged.c
+++ b/t/unit-tests/u-reftable-merged.c
@@ -6,12 +6,12 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
-#include "test-lib.h"
+#include "unit-test.h"
#include "lib-reftable.h"
#include "reftable/blocksource.h"
#include "reftable/constants.h"
#include "reftable/merged.h"
-#include "reftable/reader.h"
+#include "reftable/table.h"
#include "reftable/reftable-error.h"
#include "reftable/reftable-merged.h"
#include "reftable/reftable-writer.h"
@@ -19,7 +19,7 @@ https://developers.google.com/open-source/licenses/bsd
static struct reftable_merged_table *
merged_table_from_records(struct reftable_ref_record **refs,
struct reftable_block_source **source,
- struct reftable_reader ***readers, const size_t *sizes,
+ struct reftable_table ***tables, const size_t *sizes,
struct reftable_buf *buf, const size_t n)
{
struct reftable_merged_table *mt = NULL;
@@ -28,33 +28,33 @@ merged_table_from_records(struct reftable_ref_record **refs,
};
int err;
- REFTABLE_CALLOC_ARRAY(*readers, n);
- check(*readers != NULL);
+ REFTABLE_CALLOC_ARRAY(*tables, n);
+ cl_assert(*tables != NULL);
REFTABLE_CALLOC_ARRAY(*source, n);
- check(*source != NULL);
+ cl_assert(*source != NULL);
for (size_t i = 0; i < n; i++) {
- t_reftable_write_to_buf(&buf[i], refs[i], sizes[i], NULL, 0, &opts);
+ cl_reftable_write_to_buf(&buf[i], refs[i], sizes[i], NULL, 0, &opts);
block_source_from_buf(&(*source)[i], &buf[i]);
- err = reftable_reader_new(&(*readers)[i], &(*source)[i],
- "name");
- check(!err);
+ err = reftable_table_new(&(*tables)[i], &(*source)[i],
+ "name");
+ cl_assert(!err);
}
- err = reftable_merged_table_new(&mt, *readers, n, REFTABLE_HASH_SHA1);
- check(!err);
+ err = reftable_merged_table_new(&mt, *tables, n, REFTABLE_HASH_SHA1);
+ cl_assert(!err);
return mt;
}
-static void readers_destroy(struct reftable_reader **readers, const size_t n)
+static void tables_destroy(struct reftable_table **tables, const size_t n)
{
for (size_t i = 0; i < n; i++)
- reftable_reader_decref(readers[i]);
- reftable_free(readers);
+ reftable_table_decref(tables[i]);
+ reftable_free(tables);
}
-static void t_merged_single_record(void)
+void test_reftable_merged__single_record(void)
{
struct reftable_ref_record r1[] = { {
.refname = (char *) "b",
@@ -77,31 +77,32 @@ static void t_merged_single_record(void)
size_t sizes[] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) };
struct reftable_buf bufs[3] = { REFTABLE_BUF_INIT, REFTABLE_BUF_INIT, REFTABLE_BUF_INIT };
struct reftable_block_source *bs = NULL;
- struct reftable_reader **readers = NULL;
+ struct reftable_table **tables = NULL;
struct reftable_merged_table *mt =
- merged_table_from_records(refs, &bs, &readers, sizes, bufs, 3);
+ merged_table_from_records(refs, &bs, &tables, sizes, bufs, 3);
struct reftable_ref_record ref = { 0 };
struct reftable_iterator it = { 0 };
int err;
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
- check(!err);
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, "a");
- check(!err);
+ cl_assert(!err);
err = reftable_iterator_next_ref(&it, &ref);
- check(!err);
- check(reftable_ref_record_equal(&r2[0], &ref, REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(!err);
+ cl_assert(reftable_ref_record_equal(&r2[0], &ref,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_ref_record_release(&ref);
reftable_iterator_destroy(&it);
- readers_destroy(readers, 3);
+ tables_destroy(tables, 3);
reftable_merged_table_free(mt);
for (size_t i = 0; i < ARRAY_SIZE(bufs); i++)
reftable_buf_release(&bufs[i]);
reftable_free(bs);
}
-static void t_merged_refs(void)
+void test_reftable_merged__refs(void)
{
struct reftable_ref_record r1[] = {
{
@@ -154,9 +155,9 @@ static void t_merged_refs(void)
size_t sizes[3] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) };
struct reftable_buf bufs[3] = { REFTABLE_BUF_INIT, REFTABLE_BUF_INIT, REFTABLE_BUF_INIT };
struct reftable_block_source *bs = NULL;
- struct reftable_reader **readers = NULL;
+ struct reftable_table **tables = NULL;
struct reftable_merged_table *mt =
- merged_table_from_records(refs, &bs, &readers, sizes, bufs, 3);
+ merged_table_from_records(refs, &bs, &tables, sizes, bufs, 3);
struct reftable_iterator it = { 0 };
int err;
struct reftable_ref_record *out = NULL;
@@ -164,13 +165,13 @@ static void t_merged_refs(void)
size_t cap = 0;
size_t i;
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
- check(!err);
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, "a");
- check(!err);
- check_int(reftable_merged_table_hash_id(mt), ==, REFTABLE_HASH_SHA1);
- check_int(reftable_merged_table_min_update_index(mt), ==, 1);
- check_int(reftable_merged_table_max_update_index(mt), ==, 3);
+ cl_assert(err == 0);
+ cl_assert_equal_i(reftable_merged_table_hash_id(mt), REFTABLE_HASH_SHA1);
+ cl_assert_equal_i(reftable_merged_table_min_update_index(mt), 1);
+ cl_assert_equal_i(reftable_merged_table_max_update_index(mt), 3);
while (len < 100) { /* cap loops/recursion. */
struct reftable_ref_record ref = { 0 };
@@ -178,27 +179,27 @@ static void t_merged_refs(void)
if (err > 0)
break;
- check(!REFTABLE_ALLOC_GROW(out, len + 1, cap));
+ cl_assert(REFTABLE_ALLOC_GROW(out, len + 1, cap) == 0);
out[len++] = ref;
}
reftable_iterator_destroy(&it);
- check_int(ARRAY_SIZE(want), ==, len);
+ cl_assert_equal_i(ARRAY_SIZE(want), len);
for (i = 0; i < len; i++)
- check(reftable_ref_record_equal(want[i], &out[i],
- REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(reftable_ref_record_equal(want[i], &out[i],
+ REFTABLE_HASH_SIZE_SHA1) != 0);
for (i = 0; i < len; i++)
reftable_ref_record_release(&out[i]);
reftable_free(out);
for (i = 0; i < 3; i++)
reftable_buf_release(&bufs[i]);
- readers_destroy(readers, 3);
+ tables_destroy(tables, 3);
reftable_merged_table_free(mt);
reftable_free(bs);
}
-static void t_merged_seek_multiple_times(void)
+void test_reftable_merged__seek_multiple_times(void)
{
struct reftable_ref_record r1[] = {
{
@@ -238,42 +239,39 @@ static void t_merged_seek_multiple_times(void)
REFTABLE_BUF_INIT, REFTABLE_BUF_INIT,
};
struct reftable_block_source *sources = NULL;
- struct reftable_reader **readers = NULL;
+ struct reftable_table **tables = NULL;
struct reftable_ref_record rec = { 0 };
struct reftable_iterator it = { 0 };
struct reftable_merged_table *mt;
- mt = merged_table_from_records(refs, &sources, &readers, sizes, bufs, 2);
- merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
+ mt = merged_table_from_records(refs, &sources, &tables, sizes, bufs, 2);
+ merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
for (size_t i = 0; i < 5; i++) {
int err = reftable_iterator_seek_ref(&it, "c");
- check(!err);
+ cl_assert(!err);
- err = reftable_iterator_next_ref(&it, &rec);
- check(!err);
- err = reftable_ref_record_equal(&rec, &r1[1], REFTABLE_HASH_SIZE_SHA1);
- check(err == 1);
+ cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
+ cl_assert_equal_i(reftable_ref_record_equal(&rec, &r1[1],
+ REFTABLE_HASH_SIZE_SHA1), 1);
- err = reftable_iterator_next_ref(&it, &rec);
- check(!err);
- err = reftable_ref_record_equal(&rec, &r2[1], REFTABLE_HASH_SIZE_SHA1);
- check(err == 1);
+ cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
+ cl_assert_equal_i(reftable_ref_record_equal(&rec, &r2[1],
+ REFTABLE_HASH_SIZE_SHA1), 1);
- err = reftable_iterator_next_ref(&it, &rec);
- check(err > 0);
+ cl_assert(reftable_iterator_next_ref(&it, &rec) > 0);
}
for (size_t i = 0; i < ARRAY_SIZE(bufs); i++)
reftable_buf_release(&bufs[i]);
- readers_destroy(readers, ARRAY_SIZE(refs));
+ tables_destroy(tables, ARRAY_SIZE(refs));
reftable_ref_record_release(&rec);
reftable_iterator_destroy(&it);
reftable_merged_table_free(mt);
reftable_free(sources);
}
-static void t_merged_seek_multiple_times_without_draining(void)
+void test_reftable_merged__seek_multiple_times_no_drain(void)
{
struct reftable_ref_record r1[] = {
{
@@ -313,32 +311,27 @@ static void t_merged_seek_multiple_times_without_draining(void)
REFTABLE_BUF_INIT, REFTABLE_BUF_INIT,
};
struct reftable_block_source *sources = NULL;
- struct reftable_reader **readers = NULL;
+ struct reftable_table **tables = NULL;
struct reftable_ref_record rec = { 0 };
struct reftable_iterator it = { 0 };
struct reftable_merged_table *mt;
- int err;
- mt = merged_table_from_records(refs, &sources, &readers, sizes, bufs, 2);
- merged_table_init_iter(mt, &it, BLOCK_TYPE_REF);
+ mt = merged_table_from_records(refs, &sources, &tables, sizes, bufs, 2);
+ merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
- err = reftable_iterator_seek_ref(&it, "b");
- check(!err);
- err = reftable_iterator_next_ref(&it, &rec);
- check(!err);
- err = reftable_ref_record_equal(&rec, &r2[0], REFTABLE_HASH_SIZE_SHA1);
- check(err == 1);
+ cl_assert(reftable_iterator_seek_ref(&it, "b") == 0);
+ cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
+ cl_assert_equal_i(reftable_ref_record_equal(&rec, &r2[0],
+ REFTABLE_HASH_SIZE_SHA1), 1);
- err = reftable_iterator_seek_ref(&it, "a");
- check(!err);
- err = reftable_iterator_next_ref(&it, &rec);
- check(!err);
- err = reftable_ref_record_equal(&rec, &r1[0], REFTABLE_HASH_SIZE_SHA1);
- check(err == 1);
+ cl_assert(reftable_iterator_seek_ref(&it, "a") == 0);
+ cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
+ cl_assert_equal_i(reftable_ref_record_equal(&rec, &r1[0],
+ REFTABLE_HASH_SIZE_SHA1), 1);
for (size_t i = 0; i < ARRAY_SIZE(bufs); i++)
reftable_buf_release(&bufs[i]);
- readers_destroy(readers, ARRAY_SIZE(refs));
+ tables_destroy(tables, ARRAY_SIZE(refs));
reftable_ref_record_release(&rec);
reftable_iterator_destroy(&it);
reftable_merged_table_free(mt);
@@ -348,7 +341,7 @@ static void t_merged_seek_multiple_times_without_draining(void)
static struct reftable_merged_table *
merged_table_from_log_records(struct reftable_log_record **logs,
struct reftable_block_source **source,
- struct reftable_reader ***readers, const size_t *sizes,
+ struct reftable_table ***tables, const size_t *sizes,
struct reftable_buf *buf, const size_t n)
{
struct reftable_merged_table *mt = NULL;
@@ -358,26 +351,26 @@ merged_table_from_log_records(struct reftable_log_record **logs,
};
int err;
- REFTABLE_CALLOC_ARRAY(*readers, n);
- check(*readers != NULL);
+ REFTABLE_CALLOC_ARRAY(*tables, n);
+ cl_assert(*tables != NULL);
REFTABLE_CALLOC_ARRAY(*source, n);
- check(*source != NULL);
+ cl_assert(*source != NULL);
for (size_t i = 0; i < n; i++) {
- t_reftable_write_to_buf(&buf[i], NULL, 0, logs[i], sizes[i], &opts);
+ cl_reftable_write_to_buf(&buf[i], NULL, 0, logs[i], sizes[i], &opts);
block_source_from_buf(&(*source)[i], &buf[i]);
- err = reftable_reader_new(&(*readers)[i], &(*source)[i],
- "name");
- check(!err);
+ err = reftable_table_new(&(*tables)[i], &(*source)[i],
+ "name");
+ cl_assert(!err);
}
- err = reftable_merged_table_new(&mt, *readers, n, REFTABLE_HASH_SHA1);
- check(!err);
+ err = reftable_merged_table_new(&mt, *tables, n, REFTABLE_HASH_SHA1);
+ cl_assert(!err);
return mt;
}
-static void t_merged_logs(void)
+void test_reftable_merged__logs(void)
{
struct reftable_log_record r1[] = {
{
@@ -435,23 +428,23 @@ static void t_merged_logs(void)
size_t sizes[3] = { ARRAY_SIZE(r1), ARRAY_SIZE(r2), ARRAY_SIZE(r3) };
struct reftable_buf bufs[3] = { REFTABLE_BUF_INIT, REFTABLE_BUF_INIT, REFTABLE_BUF_INIT };
struct reftable_block_source *bs = NULL;
- struct reftable_reader **readers = NULL;
+ struct reftable_table **tables = NULL;
struct reftable_merged_table *mt = merged_table_from_log_records(
- logs, &bs, &readers, sizes, bufs, 3);
+ logs, &bs, &tables, sizes, bufs, 3);
struct reftable_iterator it = { 0 };
- int err;
struct reftable_log_record *out = NULL;
size_t len = 0;
size_t cap = 0;
size_t i;
+ int err;
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
- check(!err);
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_LOG);
+ cl_assert(!err);
err = reftable_iterator_seek_log(&it, "a");
- check(!err);
- check_int(reftable_merged_table_hash_id(mt), ==, REFTABLE_HASH_SHA1);
- check_int(reftable_merged_table_min_update_index(mt), ==, 1);
- check_int(reftable_merged_table_max_update_index(mt), ==, 3);
+ cl_assert(!err);
+ cl_assert_equal_i(reftable_merged_table_hash_id(mt), REFTABLE_HASH_SHA1);
+ cl_assert_equal_i(reftable_merged_table_min_update_index(mt), 1);
+ cl_assert_equal_i(reftable_merged_table_max_update_index(mt), 3);
while (len < 100) { /* cap loops/recursion. */
struct reftable_log_record log = { 0 };
@@ -459,24 +452,24 @@ static void t_merged_logs(void)
if (err > 0)
break;
- check(!REFTABLE_ALLOC_GROW(out, len + 1, cap));
+ cl_assert(REFTABLE_ALLOC_GROW(out, len + 1, cap) == 0);
out[len++] = log;
}
reftable_iterator_destroy(&it);
- check_int(ARRAY_SIZE(want), ==, len);
+ cl_assert_equal_i(ARRAY_SIZE(want), len);
for (i = 0; i < len; i++)
- check(reftable_log_record_equal(want[i], &out[i],
- REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(reftable_log_record_equal(want[i], &out[i],
+ REFTABLE_HASH_SIZE_SHA1) != 0);
- err = merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
- check(!err);
+ err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_LOG);
+ cl_assert(!err);
err = reftable_iterator_seek_log_at(&it, "a", 2);
- check(!err);
+ cl_assert(!err);
reftable_log_record_release(&out[0]);
- err = reftable_iterator_next_log(&it, &out[0]);
- check(!err);
- check(reftable_log_record_equal(&out[0], &r3[0], REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(reftable_iterator_next_log(&it, &out[0]) == 0);
+ cl_assert(reftable_log_record_equal(&out[0], &r3[0],
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_iterator_destroy(&it);
for (i = 0; i < len; i++)
@@ -485,16 +478,16 @@ static void t_merged_logs(void)
for (i = 0; i < 3; i++)
reftable_buf_release(&bufs[i]);
- readers_destroy(readers, 3);
+ tables_destroy(tables, 3);
reftable_merged_table_free(mt);
reftable_free(bs);
}
-static void t_default_write_opts(void)
+void test_reftable_merged__default_write_opts(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
struct reftable_ref_record rec = {
.refname = (char *) "master",
.update_index = 1,
@@ -502,45 +495,30 @@ static void t_default_write_opts(void)
int err;
struct reftable_block_source source = { 0 };
uint32_t hash_id;
- struct reftable_reader *rd = NULL;
+ struct reftable_table *table = NULL;
struct reftable_merged_table *merged = NULL;
reftable_writer_set_limits(w, 1, 1);
- err = reftable_writer_add_ref(w, &rec);
- check(!err);
+ cl_assert_equal_i(reftable_writer_add_ref(w, &rec), 0);
- err = reftable_writer_close(w);
- check(!err);
+ cl_assert_equal_i(reftable_writer_close(w), 0);
reftable_writer_free(w);
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&rd, &source, "filename");
- check(!err);
+ err = reftable_table_new(&table, &source, "filename");
+ cl_assert(!err);
- hash_id = reftable_reader_hash_id(rd);
- check_int(hash_id, ==, REFTABLE_HASH_SHA1);
+ hash_id = reftable_table_hash_id(table);
+ cl_assert_equal_i(hash_id, REFTABLE_HASH_SHA1);
- err = reftable_merged_table_new(&merged, &rd, 1, REFTABLE_HASH_SHA256);
- check_int(err, ==, REFTABLE_FORMAT_ERROR);
- err = reftable_merged_table_new(&merged, &rd, 1, REFTABLE_HASH_SHA1);
- check(!err);
+ err = reftable_merged_table_new(&merged, &table, 1, REFTABLE_HASH_SHA256);
+ cl_assert_equal_i(err, REFTABLE_FORMAT_ERROR);
+ err = reftable_merged_table_new(&merged, &table, 1, REFTABLE_HASH_SHA1);
+ cl_assert(!err);
- reftable_reader_decref(rd);
+ reftable_table_decref(table);
reftable_merged_table_free(merged);
reftable_buf_release(&buf);
}
-
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- TEST(t_default_write_opts(), "merged table with default write opts");
- TEST(t_merged_logs(), "merged table with multiple log updates for same ref");
- TEST(t_merged_refs(), "merged table with multiple updates to same ref");
- TEST(t_merged_seek_multiple_times(), "merged table can seek multiple times");
- TEST(t_merged_seek_multiple_times_without_draining(), "merged table can seek multiple times without draining");
- TEST(t_merged_single_record(), "ref occurring in only one record can be fetched");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/u-reftable-pq.c
index f3f8a0cdf3..f8a28f6e07 100644
--- a/t/unit-tests/t-reftable-pq.c
+++ b/t/unit-tests/u-reftable-pq.c
@@ -6,7 +6,8 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
-#include "test-lib.h"
+#include "unit-test.h"
+#include "lib-reftable.h"
#include "reftable/constants.h"
#include "reftable/pq.h"
#include "strbuf.h"
@@ -15,16 +16,18 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)
{
for (size_t i = 1; i < pq->len; i++) {
size_t parent = (i - 1) / 2;
- check(pq_less(&pq->heap[parent], &pq->heap[i]));
+ cl_assert(pq_less(&pq->heap[parent], &pq->heap[i]) != 0);
}
}
static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)
{
- return !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index);
+ int cmp;
+ cl_assert_equal_i(reftable_record_cmp(a->rec, b->rec, &cmp), 0);
+ return !cmp && (a->index == b->index);
}
-static void t_pq_record(void)
+void test_reftable_pq__record(void)
{
struct merged_iter_pqueue pq = { 0 };
struct reftable_record recs[54];
@@ -32,7 +35,8 @@ static void t_pq_record(void)
char *last = NULL;
for (i = 0; i < N; i++) {
- reftable_record_init(&recs[i], BLOCK_TYPE_REF);
+ cl_assert(!reftable_record_init(&recs[i],
+ REFTABLE_BLOCK_TYPE_REF));
recs[i].u.ref.refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i);
}
@@ -49,13 +53,15 @@ static void t_pq_record(void)
while (!merged_iter_pqueue_is_empty(pq)) {
struct pq_entry top = merged_iter_pqueue_top(pq);
- struct pq_entry e = merged_iter_pqueue_remove(&pq);
+ struct pq_entry e;
+
+ cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
merged_iter_pqueue_check(&pq);
- check(pq_entry_equal(&top, &e));
- check(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
+ cl_assert(pq_entry_equal(&top, &e));
+ cl_assert(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
if (last)
- check_int(strcmp(last, e.rec->u.ref.refname), <, 0);
+ cl_assert(strcmp(last, e.rec->u.ref.refname) < 0);
last = e.rec->u.ref.refname;
}
@@ -64,7 +70,7 @@ static void t_pq_record(void)
merged_iter_pqueue_release(&pq);
}
-static void t_pq_index(void)
+void test_reftable_pq__index(void)
{
struct merged_iter_pqueue pq = { 0 };
struct reftable_record recs[13];
@@ -72,7 +78,8 @@ static void t_pq_index(void)
size_t N = ARRAY_SIZE(recs), i;
for (i = 0; i < N; i++) {
- reftable_record_init(&recs[i], BLOCK_TYPE_REF);
+ cl_assert(!reftable_record_init(&recs[i],
+ REFTABLE_BLOCK_TYPE_REF));
recs[i].u.ref.refname = (char *) "refs/heads/master";
}
@@ -90,28 +97,31 @@ static void t_pq_index(void)
for (i = N - 1; i > 0; i--) {
struct pq_entry top = merged_iter_pqueue_top(pq);
- struct pq_entry e = merged_iter_pqueue_remove(&pq);
+ struct pq_entry e;
+
+ cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
merged_iter_pqueue_check(&pq);
- check(pq_entry_equal(&top, &e));
- check(reftable_record_type(e.rec) == BLOCK_TYPE_REF);
- check_int(e.index, ==, i);
+ cl_assert(pq_entry_equal(&top, &e));
+ cl_assert(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
+ cl_assert_equal_i(e.index, i);
if (last)
- check_str(last, e.rec->u.ref.refname);
+ cl_assert_equal_s(last, e.rec->u.ref.refname);
last = e.rec->u.ref.refname;
}
merged_iter_pqueue_release(&pq);
}
-static void t_merged_iter_pqueue_top(void)
+void test_reftable_pq__merged_iter_pqueue_top(void)
{
struct merged_iter_pqueue pq = { 0 };
struct reftable_record recs[13];
size_t N = ARRAY_SIZE(recs), i;
for (i = 0; i < N; i++) {
- reftable_record_init(&recs[i], BLOCK_TYPE_REF);
+ cl_assert(!reftable_record_init(&recs[i],
+ REFTABLE_BLOCK_TYPE_REF));
recs[i].u.ref.refname = (char *) "refs/heads/master";
}
@@ -129,25 +139,18 @@ static void t_merged_iter_pqueue_top(void)
for (i = N - 1; i > 0; i--) {
struct pq_entry top = merged_iter_pqueue_top(pq);
- struct pq_entry e = merged_iter_pqueue_remove(&pq);
+ struct pq_entry e;
+
+ cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
merged_iter_pqueue_check(&pq);
- check(pq_entry_equal(&top, &e));
- check(reftable_record_equal(top.rec, &recs[i], REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(pq_entry_equal(&top, &e) != 0);
+ cl_assert(reftable_record_equal(top.rec, &recs[i], REFTABLE_HASH_SIZE_SHA1) != 0);
for (size_t j = 0; i < pq.len; j++) {
- check(pq_less(&top, &pq.heap[j]));
- check_int(top.index, >, j);
+ cl_assert(pq_less(&top, &pq.heap[j]) != 0);
+ cl_assert(top.index > j);
}
}
merged_iter_pqueue_release(&pq);
}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- TEST(t_pq_record(), "pq works with record-based comparison");
- TEST(t_pq_index(), "pq works with index-based comparison");
- TEST(t_merged_iter_pqueue_top(), "merged_iter_pqueue_top works");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/u-reftable-readwrite.c
index 6b75a419b9..4d8c4be5f1 100644
--- a/t/unit-tests/t-reftable-readwrite.c
+++ b/t/unit-tests/u-reftable-readwrite.c
@@ -8,37 +8,37 @@ https://developers.google.com/open-source/licenses/bsd
#define DISABLE_SIGN_COMPARE_WARNINGS
-#include "test-lib.h"
+#include "unit-test.h"
#include "lib-reftable.h"
#include "reftable/basics.h"
#include "reftable/blocksource.h"
-#include "reftable/reader.h"
#include "reftable/reftable-error.h"
#include "reftable/reftable-writer.h"
+#include "reftable/table.h"
#include "strbuf.h"
static const int update_index = 5;
-static void t_buffer(void)
+void test_reftable_readwrite__buffer(void)
{
struct reftable_buf buf = REFTABLE_BUF_INIT;
struct reftable_block_source source = { 0 };
- struct reftable_block out = { 0 };
+ struct reftable_block_data out = { 0 };
int n;
uint8_t in[] = "hello";
- check(!reftable_buf_add(&buf, in, sizeof(in)));
+ cl_assert_equal_i(reftable_buf_add(&buf, in, sizeof(in)), 0);
block_source_from_buf(&source, &buf);
- check_int(block_source_size(&source), ==, 6);
- n = block_source_read_block(&source, &out, 0, sizeof(in));
- check_int(n, ==, sizeof(in));
- check(!memcmp(in, out.data, n));
- reftable_block_done(&out);
+ cl_assert_equal_i(block_source_size(&source), 6);
+ n = block_source_read_data(&source, &out, 0, sizeof(in));
+ cl_assert_equal_i(n, sizeof(in));
+ cl_assert(!memcmp(in, out.data, n));
+ block_source_release_data(&out);
- n = block_source_read_block(&source, &out, 1, 2);
- check_int(n, ==, 2);
- check(!memcmp(out.data, "el", 2));
+ n = block_source_read_data(&source, &out, 1, 2);
+ cl_assert_equal_i(n, 2);
+ cl_assert(!memcmp(out.data, "el", 2));
- reftable_block_done(&out);
+ block_source_release_data(&out);
block_source_close(&source);
reftable_buf_release(&buf);
}
@@ -55,41 +55,41 @@ static void write_table(char ***names, struct reftable_buf *buf, int N,
int i;
REFTABLE_CALLOC_ARRAY(*names, N + 1);
- check(*names != NULL);
+ cl_assert(*names != NULL);
REFTABLE_CALLOC_ARRAY(refs, N);
- check(refs != NULL);
+ cl_assert(refs != NULL);
REFTABLE_CALLOC_ARRAY(logs, N);
- check(logs != NULL);
+ cl_assert(logs != NULL);
for (i = 0; i < N; i++) {
refs[i].refname = (*names)[i] = xstrfmt("refs/heads/branch%02d", i);
refs[i].update_index = update_index;
refs[i].value_type = REFTABLE_REF_VAL1;
- t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(refs[i].value.val1, i,
+ REFTABLE_HASH_SHA1);
}
for (i = 0; i < N; i++) {
logs[i].refname = (*names)[i];
logs[i].update_index = update_index;
logs[i].value_type = REFTABLE_LOG_UPDATE;
- t_reftable_set_hash(logs[i].value.update.new_hash, i,
- REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i,
+ REFTABLE_HASH_SHA1);
logs[i].value.update.message = (char *) "message";
}
- t_reftable_write_to_buf(buf, refs, N, logs, N, &opts);
+ cl_reftable_write_to_buf(buf, refs, N, logs, N, &opts);
reftable_free(refs);
reftable_free(logs);
}
-static void t_log_buffer_size(void)
+void test_reftable_readwrite__log_buffer_size(void)
{
struct reftable_buf buf = REFTABLE_BUF_INIT;
struct reftable_write_options opts = {
.block_size = 4096,
};
- int err;
int i;
struct reftable_log_record
log = { .refname = (char *) "refs/heads/master",
@@ -102,32 +102,30 @@ static void t_log_buffer_size(void)
.time = 0x5e430672,
.message = (char *) "commit: 9\n",
} } };
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
+ &opts);
/* This tests buffer extension for log compression. Must use a random
hash, to ensure that the compressed part is larger than the original.
*/
for (i = 0; i < REFTABLE_HASH_SIZE_SHA1; i++) {
- log.value.update.old_hash[i] = (uint8_t)(git_rand() % 256);
- log.value.update.new_hash[i] = (uint8_t)(git_rand() % 256);
+ log.value.update.old_hash[i] = (uint8_t)(git_rand(0) % 256);
+ log.value.update.new_hash[i] = (uint8_t)(git_rand(0) % 256);
}
reftable_writer_set_limits(w, update_index, update_index);
- err = reftable_writer_add_log(w, &log);
- check(!err);
- err = reftable_writer_close(w);
- check(!err);
+ cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
+ cl_assert_equal_i(reftable_writer_close(w), 0);
reftable_writer_free(w);
reftable_buf_release(&buf);
}
-static void t_log_overflow(void)
+void test_reftable_readwrite__log_overflow(void)
{
struct reftable_buf buf = REFTABLE_BUF_INIT;
char msg[256] = { 0 };
struct reftable_write_options opts = {
.block_size = ARRAY_SIZE(msg),
};
- int err;
struct reftable_log_record log = {
.refname = (char *) "refs/heads/master",
.update_index = update_index,
@@ -144,21 +142,22 @@ static void t_log_overflow(void)
},
},
};
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
+ &opts);
memset(msg, 'x', sizeof(msg) - 1);
reftable_writer_set_limits(w, update_index, update_index);
- err = reftable_writer_add_log(w, &log);
- check_int(err, ==, REFTABLE_ENTRY_TOO_BIG_ERROR);
+ cl_assert_equal_i(reftable_writer_add_log(w, &log), REFTABLE_ENTRY_TOO_BIG_ERROR);
reftable_writer_free(w);
reftable_buf_release(&buf);
}
-static void t_log_write_limits(void)
+void test_reftable_readwrite__log_write_limits(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
+ &opts);
struct reftable_log_record log = {
.refname = (char *)"refs/head/master",
.update_index = 0,
@@ -174,29 +173,25 @@ static void t_log_write_limits(void)
},
},
};
- int err;
reftable_writer_set_limits(w, 1, 1);
/* write with update_index (0) below set limits (1, 1) */
- err = reftable_writer_add_log(w, &log);
- check_int(err, ==, 0);
+ cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
/* write with update_index (1) in the set limits (1, 1) */
log.update_index = 1;
- err = reftable_writer_add_log(w, &log);
- check_int(err, ==, 0);
+ cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
/* write with update_index (3) above set limits (1, 1) */
log.update_index = 3;
- err = reftable_writer_add_log(w, &log);
- check_int(err, ==, REFTABLE_API_ERROR);
+ cl_assert_equal_i(reftable_writer_add_log(w, &log), REFTABLE_API_ERROR);
reftable_writer_free(w);
reftable_buf_release(&buf);
}
-static void t_log_write_read(void)
+void test_reftable_readwrite__log_write_read(void)
{
struct reftable_write_options opts = {
.block_size = 256,
@@ -204,16 +199,17 @@ static void t_log_write_read(void)
struct reftable_ref_record ref = { 0 };
struct reftable_log_record log = { 0 };
struct reftable_iterator it = { 0 };
- struct reftable_reader *reader;
+ struct reftable_table *table;
struct reftable_block_source source = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
const struct reftable_stats *stats = NULL;
- int N = 2, err, i, n;
+ int N = 2, i;
char **names;
+ int err;
names = reftable_calloc(N + 1, sizeof(*names));
- check(names != NULL);
+ cl_assert(names != NULL);
reftable_writer_set_limits(w, 0, N);
@@ -225,8 +221,7 @@ static void t_log_write_read(void)
ref.refname = name;
ref.update_index = i;
- err = reftable_writer_add_ref(w, &ref);
- check(!err);
+ cl_assert_equal_i(reftable_writer_add_ref(w, &ref), 0);
}
for (i = 0; i < N; i++) {
@@ -235,81 +230,80 @@ static void t_log_write_read(void)
log.refname = names[i];
log.update_index = i;
log.value_type = REFTABLE_LOG_UPDATE;
- t_reftable_set_hash(log.value.update.old_hash, i,
- REFTABLE_HASH_SHA1);
- t_reftable_set_hash(log.value.update.new_hash, i + 1,
- REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(log.value.update.old_hash, i,
+ REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(log.value.update.new_hash, i + 1,
+ REFTABLE_HASH_SHA1);
- err = reftable_writer_add_log(w, &log);
- check(!err);
+ cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
}
- n = reftable_writer_close(w);
- check_int(n, ==, 0);
+ cl_assert_equal_i(reftable_writer_close(w), 0);
stats = reftable_writer_stats(w);
- check_int(stats->log_stats.blocks, >, 0);
+ cl_assert(stats->log_stats.blocks > 0);
reftable_writer_free(w);
w = NULL;
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&reader, &source, "file.log");
- check(!err);
+ err = reftable_table_new(&table, &source, "file.log");
+ cl_assert(!err);
- err = reftable_reader_init_ref_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_ref_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, names[N - 1]);
- check(!err);
+ cl_assert(!err);
err = reftable_iterator_next_ref(&it, &ref);
- check(!err);
+ cl_assert(!err);
/* end of iteration. */
- err = reftable_iterator_next_ref(&it, &ref);
- check_int(err, >, 0);
+ cl_assert(reftable_iterator_next_ref(&it, &ref) > 0);
reftable_iterator_destroy(&it);
reftable_ref_record_release(&ref);
- err = reftable_reader_init_log_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_log_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_log(&it, "");
- check(!err);
+ cl_assert(!err);
for (i = 0; ; i++) {
int err = reftable_iterator_next_log(&it, &log);
if (err > 0)
break;
- check(!err);
- check_str(names[i], log.refname);
- check_int(i, ==, log.update_index);
+ cl_assert(!err);
+ cl_assert_equal_s(names[i], log.refname);
+ cl_assert_equal_i(i, log.update_index);
reftable_log_record_release(&log);
}
- check_int(i, ==, N);
+ cl_assert_equal_i(i, N);
reftable_iterator_destroy(&it);
/* cleanup. */
reftable_buf_release(&buf);
free_names(names);
- reftable_reader_decref(reader);
+ reftable_table_decref(table);
}
-static void t_log_zlib_corruption(void)
+void test_reftable_readwrite__log_zlib_corruption(void)
{
struct reftable_write_options opts = {
.block_size = 256,
};
struct reftable_iterator it = { 0 };
- struct reftable_reader *reader;
+ struct reftable_table *table;
struct reftable_block_source source = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
+ &opts);
const struct reftable_stats *stats = NULL;
char message[100] = { 0 };
- int err, i, n;
+ int i;
+ int err;
struct reftable_log_record log = {
.refname = (char *) "refname",
.value_type = REFTABLE_LOG_UPDATE,
@@ -325,18 +319,15 @@ static void t_log_zlib_corruption(void)
};
for (i = 0; i < sizeof(message) - 1; i++)
- message[i] = (uint8_t)(git_rand() % 64 + ' ');
+ message[i] = (uint8_t)(git_rand(0) % 64 + ' ');
reftable_writer_set_limits(w, 1, 1);
- err = reftable_writer_add_log(w, &log);
- check(!err);
-
- n = reftable_writer_close(w);
- check_int(n, ==, 0);
+ cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
+ cl_assert_equal_i(reftable_writer_close(w), 0);
stats = reftable_writer_stats(w);
- check_int(stats->log_stats.blocks, >, 0);
+ cl_assert(stats->log_stats.blocks > 0);
reftable_writer_free(w);
w = NULL;
@@ -345,29 +336,29 @@ static void t_log_zlib_corruption(void)
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&reader, &source, "file.log");
- check(!err);
+ err = reftable_table_new(&table, &source, "file.log");
+ cl_assert(!err);
- err = reftable_reader_init_log_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_log_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_log(&it, "refname");
- check_int(err, ==, REFTABLE_ZLIB_ERROR);
+ cl_assert_equal_i(err, REFTABLE_ZLIB_ERROR);
reftable_iterator_destroy(&it);
/* cleanup. */
- reftable_reader_decref(reader);
+ reftable_table_decref(table);
reftable_buf_release(&buf);
}
-static void t_table_read_write_sequential(void)
+void test_reftable_readwrite__table_read_write_sequential(void)
{
char **names;
struct reftable_buf buf = REFTABLE_BUF_INIT;
int N = 50;
struct reftable_iterator it = { 0 };
struct reftable_block_source source = { 0 };
- struct reftable_reader *reader;
+ struct reftable_table *table;
int err = 0;
int j = 0;
@@ -375,73 +366,73 @@ static void t_table_read_write_sequential(void)
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&reader, &source, "file.ref");
- check(!err);
+ err = reftable_table_new(&table, &source, "file.ref");
+ cl_assert(!err);
- err = reftable_reader_init_ref_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_ref_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, "");
- check(!err);
+ cl_assert(!err);
for (j = 0; ; j++) {
struct reftable_ref_record ref = { 0 };
int r = reftable_iterator_next_ref(&it, &ref);
- check_int(r, >=, 0);
+ cl_assert(r >= 0);
if (r > 0)
break;
- check_str(names[j], ref.refname);
- check_int(update_index, ==, ref.update_index);
+ cl_assert_equal_s(names[j], ref.refname);
+ cl_assert_equal_i(update_index, ref.update_index);
reftable_ref_record_release(&ref);
}
- check_int(j, ==, N);
+ cl_assert_equal_i(j, N);
reftable_iterator_destroy(&it);
- reftable_reader_decref(reader);
+ reftable_table_decref(table);
reftable_buf_release(&buf);
free_names(names);
}
-static void t_table_write_small_table(void)
+void test_reftable_readwrite__table_write_small_table(void)
{
char **names;
struct reftable_buf buf = REFTABLE_BUF_INIT;
int N = 1;
write_table(&names, &buf, N, 4096, REFTABLE_HASH_SHA1);
- check_int(buf.len, <, 200);
+ cl_assert(buf.len < 200);
reftable_buf_release(&buf);
free_names(names);
}
-static void t_table_read_api(void)
+void test_reftable_readwrite__table_read_api(void)
{
char **names;
struct reftable_buf buf = REFTABLE_BUF_INIT;
int N = 50;
- struct reftable_reader *reader;
+ struct reftable_table *table;
struct reftable_block_source source = { 0 };
- int err;
struct reftable_log_record log = { 0 };
struct reftable_iterator it = { 0 };
+ int err;
write_table(&names, &buf, N, 256, REFTABLE_HASH_SHA1);
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&reader, &source, "file.ref");
- check(!err);
+ err = reftable_table_new(&table, &source, "file.ref");
+ cl_assert(!err);
- err = reftable_reader_init_ref_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_ref_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, names[0]);
- check(!err);
+ cl_assert(!err);
err = reftable_iterator_next_log(&it, &log);
- check_int(err, ==, REFTABLE_API_ERROR);
+ cl_assert_equal_i(err, REFTABLE_API_ERROR);
reftable_buf_release(&buf);
free_names(names);
reftable_iterator_destroy(&it);
- reftable_reader_decref(reader);
+ reftable_table_decref(table);
reftable_buf_release(&buf);
}
@@ -450,7 +441,7 @@ static void t_table_read_write_seek(int index, enum reftable_hash hash_id)
char **names;
struct reftable_buf buf = REFTABLE_BUF_INIT;
int N = 50;
- struct reftable_reader *reader;
+ struct reftable_table *table;
struct reftable_block_source source = { 0 };
int err;
int i = 0;
@@ -463,43 +454,44 @@ static void t_table_read_write_seek(int index, enum reftable_hash hash_id)
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&reader, &source, "file.ref");
- check(!err);
- check_int(hash_id, ==, reftable_reader_hash_id(reader));
+ err = reftable_table_new(&table, &source, "file.ref");
+ cl_assert(!err);
+ cl_assert_equal_i(hash_id, reftable_table_hash_id(table));
if (!index) {
- reader->ref_offsets.index_offset = 0;
+ table->ref_offsets.index_offset = 0;
} else {
- check_int(reader->ref_offsets.index_offset, >, 0);
+ cl_assert(table->ref_offsets.index_offset > 0);
}
for (i = 1; i < N; i++) {
- err = reftable_reader_init_ref_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_ref_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, names[i]);
- check(!err);
+ cl_assert(!err);
err = reftable_iterator_next_ref(&it, &ref);
- check(!err);
- check_str(names[i], ref.refname);
- check_int(REFTABLE_REF_VAL1, ==, ref.value_type);
- check_int(i, ==, ref.value.val1[0]);
+ cl_assert(!err);
+ cl_assert_equal_s(names[i], ref.refname);
+ cl_assert_equal_i(REFTABLE_REF_VAL1, ref.value_type);
+ cl_assert_equal_i(i, ref.value.val1[0]);
reftable_ref_record_release(&ref);
reftable_iterator_destroy(&it);
}
- check(!reftable_buf_addstr(&pastLast, names[N - 1]));
- check(!reftable_buf_addstr(&pastLast, "/"));
+ cl_assert_equal_i(reftable_buf_addstr(&pastLast, names[N - 1]),
+ 0);
+ cl_assert_equal_i(reftable_buf_addstr(&pastLast, "/"), 0);
- err = reftable_reader_init_ref_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_ref_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, pastLast.buf);
if (err == 0) {
struct reftable_ref_record ref = { 0 };
int err = reftable_iterator_next_ref(&it, &ref);
- check_int(err, >, 0);
+ cl_assert(err > 0);
} else {
- check_int(err, >, 0);
+ cl_assert(err > 0);
}
reftable_buf_release(&pastLast);
@@ -507,20 +499,20 @@ static void t_table_read_write_seek(int index, enum reftable_hash hash_id)
reftable_buf_release(&buf);
free_names(names);
- reftable_reader_decref(reader);
+ reftable_table_decref(table);
}
-static void t_table_read_write_seek_linear(void)
+void test_reftable_readwrite__table_read_write_seek_linear(void)
{
t_table_read_write_seek(0, REFTABLE_HASH_SHA1);
}
-static void t_table_read_write_seek_linear_sha256(void)
+void test_reftable_readwrite__table_read_write_seek_linear_sha256(void)
{
t_table_read_write_seek(0, REFTABLE_HASH_SHA256);
}
-static void t_table_read_write_seek_index(void)
+void test_reftable_readwrite__table_read_write_seek_index(void)
{
t_table_read_write_seek(1, REFTABLE_HASH_SHA1);
}
@@ -535,17 +527,19 @@ static void t_table_refs_for(int indexed)
.block_size = 256,
};
struct reftable_ref_record ref = { 0 };
- struct reftable_reader *reader;
+ struct reftable_table *table;
struct reftable_block_source source = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
+ &opts);
struct reftable_iterator it = { 0 };
- int N = 50, n, j, err, i;
+ int N = 50, j, i;
+ int err;
want_names = reftable_calloc(N + 1, sizeof(*want_names));
- check(want_names != NULL);
+ cl_assert(want_names != NULL);
- t_reftable_set_hash(want_hash, 4, REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(want_hash, 4, REFTABLE_HASH_SHA1);
for (i = 0; i < N; i++) {
uint8_t hash[REFTABLE_HASH_SIZE_SHA1];
@@ -561,121 +555,117 @@ static void t_table_refs_for(int indexed)
ref.refname = name;
ref.value_type = REFTABLE_REF_VAL2;
- t_reftable_set_hash(ref.value.val2.value, i / 4,
- REFTABLE_HASH_SHA1);
- t_reftable_set_hash(ref.value.val2.target_value, 3 + i / 4,
- REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(ref.value.val2.value, i / 4,
+ REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(ref.value.val2.target_value,
+ 3 + i / 4, REFTABLE_HASH_SHA1);
/* 80 bytes / entry, so 3 entries per block. Yields 17
*/
/* blocks. */
- n = reftable_writer_add_ref(w, &ref);
- check_int(n, ==, 0);
+ cl_assert_equal_i(reftable_writer_add_ref(w, &ref), 0);
if (!memcmp(ref.value.val2.value, want_hash, REFTABLE_HASH_SIZE_SHA1) ||
!memcmp(ref.value.val2.target_value, want_hash, REFTABLE_HASH_SIZE_SHA1))
want_names[want_names_len++] = xstrdup(name);
}
- n = reftable_writer_close(w);
- check_int(n, ==, 0);
+ cl_assert_equal_i(reftable_writer_close(w), 0);
reftable_writer_free(w);
w = NULL;
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&reader, &source, "file.ref");
- check(!err);
+ err = reftable_table_new(&table, &source, "file.ref");
+ cl_assert(!err);
if (!indexed)
- reader->obj_offsets.is_present = 0;
+ table->obj_offsets.is_present = 0;
- err = reftable_reader_init_ref_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_ref_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, "");
- check(!err);
+ cl_assert(!err);
reftable_iterator_destroy(&it);
- err = reftable_reader_refs_for(reader, &it, want_hash);
- check(!err);
+ err = reftable_table_refs_for(table, &it, want_hash);
+ cl_assert(!err);
for (j = 0; ; j++) {
int err = reftable_iterator_next_ref(&it, &ref);
- check_int(err, >=, 0);
+ cl_assert(err >= 0);
if (err > 0)
break;
- check_int(j, <, want_names_len);
- check_str(ref.refname, want_names[j]);
+ cl_assert(j < want_names_len);
+ cl_assert_equal_s(ref.refname, want_names[j]);
reftable_ref_record_release(&ref);
}
- check_int(j, ==, want_names_len);
+ cl_assert_equal_i(j, want_names_len);
reftable_buf_release(&buf);
free_names(want_names);
reftable_iterator_destroy(&it);
- reftable_reader_decref(reader);
+ reftable_table_decref(table);
}
-static void t_table_refs_for_no_index(void)
+void test_reftable_readwrite__table_refs_for_no_index(void)
{
t_table_refs_for(0);
}
-static void t_table_refs_for_obj_index(void)
+void test_reftable_readwrite__table_refs_for_obj_index(void)
{
t_table_refs_for(1);
}
-static void t_write_empty_table(void)
+void test_reftable_readwrite__write_empty_table(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
struct reftable_block_source source = { 0 };
- struct reftable_reader *rd = NULL;
+ struct reftable_table *table = NULL;
struct reftable_ref_record rec = { 0 };
struct reftable_iterator it = { 0 };
int err;
reftable_writer_set_limits(w, 1, 1);
- err = reftable_writer_close(w);
- check_int(err, ==, REFTABLE_EMPTY_TABLE_ERROR);
+ cl_assert_equal_i(reftable_writer_close(w), REFTABLE_EMPTY_TABLE_ERROR);
reftable_writer_free(w);
- check_int(buf.len, ==, header_size(1) + footer_size(1));
+ cl_assert_equal_i(buf.len, header_size(1) + footer_size(1));
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&rd, &source, "filename");
- check(!err);
+ err = reftable_table_new(&table, &source, "filename");
+ cl_assert(!err);
- err = reftable_reader_init_ref_iterator(rd, &it);
- check(!err);
+ err = reftable_table_init_ref_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, "");
- check(!err);
+ cl_assert(!err);
err = reftable_iterator_next_ref(&it, &rec);
- check_int(err, >, 0);
+ cl_assert(err > 0);
reftable_iterator_destroy(&it);
- reftable_reader_decref(rd);
+ reftable_table_decref(table);
reftable_buf_release(&buf);
}
-static void t_write_object_id_min_length(void)
+void test_reftable_readwrite__write_object_id_min_length(void)
{
struct reftable_write_options opts = {
.block_size = 75,
};
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
struct reftable_ref_record ref = {
.update_index = 1,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = {42},
};
- int err;
int i;
reftable_writer_set_limits(w, 1, 1);
@@ -686,30 +676,27 @@ static void t_write_object_id_min_length(void)
char name[256];
snprintf(name, sizeof(name), "ref%05d", i);
ref.refname = name;
- err = reftable_writer_add_ref(w, &ref);
- check(!err);
+ cl_assert_equal_i(reftable_writer_add_ref(w, &ref), 0);
}
- err = reftable_writer_close(w);
- check(!err);
- check_int(reftable_writer_stats(w)->object_id_len, ==, 2);
+ cl_assert_equal_i(reftable_writer_close(w), 0);
+ cl_assert_equal_i(reftable_writer_stats(w)->object_id_len, 2);
reftable_writer_free(w);
reftable_buf_release(&buf);
}
-static void t_write_object_id_length(void)
+void test_reftable_readwrite__write_object_id_length(void)
{
struct reftable_write_options opts = {
.block_size = 75,
};
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
struct reftable_ref_record ref = {
.update_index = 1,
.value_type = REFTABLE_REF_VAL1,
.value.val1 = {42},
};
- int err;
int i;
reftable_writer_set_limits(w, 1, 1);
@@ -721,44 +708,39 @@ static void t_write_object_id_length(void)
snprintf(name, sizeof(name), "ref%05d", i);
ref.refname = name;
ref.value.val1[15] = i;
- err = reftable_writer_add_ref(w, &ref);
- check(!err);
+ cl_assert(reftable_writer_add_ref(w, &ref) == 0);
}
- err = reftable_writer_close(w);
- check(!err);
- check_int(reftable_writer_stats(w)->object_id_len, ==, 16);
+ cl_assert_equal_i(reftable_writer_close(w), 0);
+ cl_assert_equal_i(reftable_writer_stats(w)->object_id_len, 16);
reftable_writer_free(w);
reftable_buf_release(&buf);
}
-static void t_write_empty_key(void)
+void test_reftable_readwrite__write_empty_key(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
struct reftable_ref_record ref = {
.refname = (char *) "",
.update_index = 1,
.value_type = REFTABLE_REF_DELETION,
};
- int err;
reftable_writer_set_limits(w, 1, 1);
- err = reftable_writer_add_ref(w, &ref);
- check_int(err, ==, REFTABLE_API_ERROR);
-
- err = reftable_writer_close(w);
- check_int(err, ==, REFTABLE_EMPTY_TABLE_ERROR);
+ cl_assert_equal_i(reftable_writer_add_ref(w, &ref), REFTABLE_API_ERROR);
+ cl_assert_equal_i(reftable_writer_close(w),
+ REFTABLE_EMPTY_TABLE_ERROR);
reftable_writer_free(w);
reftable_buf_release(&buf);
}
-static void t_write_key_order(void)
+void test_reftable_readwrite__write_key_order(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
- struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
+ struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
struct reftable_ref_record refs[2] = {
{
.refname = (char *) "b",
@@ -776,24 +758,21 @@ static void t_write_key_order(void)
},
}
};
- int err;
reftable_writer_set_limits(w, 1, 1);
- err = reftable_writer_add_ref(w, &refs[0]);
- check(!err);
- err = reftable_writer_add_ref(w, &refs[1]);
- check_int(err, ==, REFTABLE_API_ERROR);
+ cl_assert_equal_i(reftable_writer_add_ref(w, &refs[0]), 0);
+ cl_assert_equal_i(reftable_writer_add_ref(w, &refs[1]),
+ REFTABLE_API_ERROR);
refs[0].update_index = 2;
- err = reftable_writer_add_ref(w, &refs[0]);
- check_int(err, ==, REFTABLE_API_ERROR);
+ cl_assert_equal_i(reftable_writer_add_ref(w, &refs[0]), REFTABLE_API_ERROR);
reftable_writer_close(w);
reftable_writer_free(w);
reftable_buf_release(&buf);
}
-static void t_write_multiple_indices(void)
+void test_reftable_readwrite__write_multiple_indices(void)
{
struct reftable_write_options opts = {
.block_size = 100,
@@ -803,11 +782,12 @@ static void t_write_multiple_indices(void)
struct reftable_iterator it = { 0 };
const struct reftable_stats *stats;
struct reftable_writer *writer;
- struct reftable_reader *reader;
+ struct reftable_table *table;
char buf[128];
- int err, i;
+ int i;
+ int err;
- writer = t_reftable_strbuf_writer(&writer_buf, &opts);
+ writer = cl_reftable_strbuf_writer(&writer_buf, &opts);
reftable_writer_set_limits(writer, 1, 1);
for (i = 0; i < 100; i++) {
struct reftable_ref_record ref = {
@@ -819,8 +799,7 @@ static void t_write_multiple_indices(void)
snprintf(buf, sizeof(buf), "refs/heads/%04d", i);
ref.refname = buf;
- err = reftable_writer_add_ref(writer, &ref);
- check(!err);
+ cl_assert_equal_i(reftable_writer_add_ref(writer, &ref), 0);
}
for (i = 0; i < 100; i++) {
@@ -836,8 +815,7 @@ static void t_write_multiple_indices(void)
snprintf(buf, sizeof(buf), "refs/heads/%04d", i);
log.refname = buf;
- err = reftable_writer_add_log(writer, &log);
- check(!err);
+ cl_assert_equal_i(reftable_writer_add_log(writer, &log), 0);
}
reftable_writer_close(writer);
@@ -847,30 +825,30 @@ static void t_write_multiple_indices(void)
* for each of the block types.
*/
stats = reftable_writer_stats(writer);
- check_int(stats->ref_stats.index_offset, >, 0);
- check_int(stats->obj_stats.index_offset, >, 0);
- check_int(stats->log_stats.index_offset, >, 0);
+ cl_assert(stats->ref_stats.index_offset > 0);
+ cl_assert(stats->obj_stats.index_offset > 0);
+ cl_assert(stats->log_stats.index_offset > 0);
block_source_from_buf(&source, &writer_buf);
- err = reftable_reader_new(&reader, &source, "filename");
- check(!err);
+ err = reftable_table_new(&table, &source, "filename");
+ cl_assert(!err);
/*
* Seeking the log uses the log index now. In case there is any
* confusion regarding indices we would notice here.
*/
- err = reftable_reader_init_log_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_log_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_log(&it, "");
- check(!err);
+ cl_assert(!err);
reftable_iterator_destroy(&it);
reftable_writer_free(writer);
- reftable_reader_decref(reader);
+ reftable_table_decref(table);
reftable_buf_release(&writer_buf);
}
-static void t_write_multi_level_index(void)
+void test_reftable_readwrite__write_multi_level_index(void)
{
struct reftable_write_options opts = {
.block_size = 100,
@@ -880,10 +858,10 @@ static void t_write_multi_level_index(void)
struct reftable_iterator it = { 0 };
const struct reftable_stats *stats;
struct reftable_writer *writer;
- struct reftable_reader *reader;
+ struct reftable_table *table;
int err;
- writer = t_reftable_strbuf_writer(&writer_buf, &opts);
+ writer = cl_reftable_strbuf_writer(&writer_buf, &opts);
reftable_writer_set_limits(writer, 1, 1);
for (size_t i = 0; i < 200; i++) {
struct reftable_ref_record ref = {
@@ -896,8 +874,7 @@ static void t_write_multi_level_index(void)
snprintf(buf, sizeof(buf), "refs/heads/%03" PRIuMAX, (uintmax_t)i);
ref.refname = buf;
- err = reftable_writer_add_ref(writer, &ref);
- check(!err);
+ cl_assert_equal_i(reftable_writer_add_ref(writer, &ref), 0);
}
reftable_writer_close(writer);
@@ -906,80 +883,52 @@ static void t_write_multi_level_index(void)
* multi-level index.
*/
stats = reftable_writer_stats(writer);
- check_int(stats->ref_stats.max_index_level, ==, 2);
+ cl_assert_equal_i(stats->ref_stats.max_index_level, 2);
block_source_from_buf(&source, &writer_buf);
- err = reftable_reader_new(&reader, &source, "filename");
- check(!err);
+ err = reftable_table_new(&table, &source, "filename");
+ cl_assert(!err);
/*
* Seeking the last ref should work as expected.
*/
- err = reftable_reader_init_ref_iterator(reader, &it);
- check(!err);
+ err = reftable_table_init_ref_iterator(table, &it);
+ cl_assert(!err);
err = reftable_iterator_seek_ref(&it, "refs/heads/199");
- check(!err);
+ cl_assert(!err);
reftable_iterator_destroy(&it);
reftable_writer_free(writer);
- reftable_reader_decref(reader);
+ reftable_table_decref(table);
reftable_buf_release(&writer_buf);
reftable_buf_release(&buf);
}
-static void t_corrupt_table_empty(void)
+void test_reftable_readwrite__corrupt_table_empty(void)
{
struct reftable_buf buf = REFTABLE_BUF_INIT;
struct reftable_block_source source = { 0 };
- struct reftable_reader *reader;
+ struct reftable_table *table;
int err;
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&reader, &source, "file.log");
- check_int(err, ==, REFTABLE_FORMAT_ERROR);
+ err = reftable_table_new(&table, &source, "file.log");
+ cl_assert_equal_i(err, REFTABLE_FORMAT_ERROR);
}
-static void t_corrupt_table(void)
+void test_reftable_readwrite__corrupt_table(void)
{
uint8_t zeros[1024] = { 0 };
struct reftable_buf buf = REFTABLE_BUF_INIT;
struct reftable_block_source source = { 0 };
- struct reftable_reader *reader;
+ struct reftable_table *table;
int err;
- check(!reftable_buf_add(&buf, zeros, sizeof(zeros)));
+
+ cl_assert(!reftable_buf_add(&buf, zeros, sizeof(zeros)));
block_source_from_buf(&source, &buf);
- err = reftable_reader_new(&reader, &source, "file.log");
- check_int(err, ==, REFTABLE_FORMAT_ERROR);
+ err = reftable_table_new(&table, &source, "file.log");
+ cl_assert_equal_i(err, REFTABLE_FORMAT_ERROR);
reftable_buf_release(&buf);
}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- TEST(t_buffer(), "strbuf works as blocksource");
- TEST(t_corrupt_table(), "read-write on corrupted table");
- TEST(t_corrupt_table_empty(), "read-write on an empty table");
- TEST(t_log_buffer_size(), "buffer extension for log compression");
- TEST(t_log_overflow(), "log overflow returns expected error");
- TEST(t_log_write_limits(), "writer limits for writing log records");
- TEST(t_log_write_read(), "read-write on log records");
- TEST(t_log_zlib_corruption(), "reading corrupted log record returns expected error");
- TEST(t_table_read_api(), "read on a table");
- TEST(t_table_read_write_seek_index(), "read-write on a table with index");
- TEST(t_table_read_write_seek_linear(), "read-write on a table without index (SHA1)");
- TEST(t_table_read_write_seek_linear_sha256(), "read-write on a table without index (SHA256)");
- TEST(t_table_read_write_sequential(), "sequential read-write on a table");
- TEST(t_table_refs_for_no_index(), "refs-only table with no index");
- TEST(t_table_refs_for_obj_index(), "refs-only table with index");
- TEST(t_table_write_small_table(), "write_table works");
- TEST(t_write_empty_key(), "write on refs with empty keys");
- TEST(t_write_empty_table(), "read-write on empty tables");
- TEST(t_write_key_order(), "refs must be written in increasing order");
- TEST(t_write_multi_level_index(), "table with multi-level index");
- TEST(t_write_multiple_indices(), "table with indices for multiple block types");
- TEST(t_write_object_id_length(), "prefix compression on writing refs");
- TEST(t_write_object_id_min_length(), "prefix compression on writing refs");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/u-reftable-record.c
index 42bc64cec8..6c8c0d5374 100644
--- a/t/unit-tests/t-reftable-record.c
+++ b/t/unit-tests/u-reftable-record.c
@@ -6,7 +6,8 @@
https://developers.google.com/open-source/licenses/bsd
*/
-#include "test-lib.h"
+#include "unit-test.h"
+#include "lib-reftable.h"
#include "reftable/basics.h"
#include "reftable/constants.h"
#include "reftable/record.h"
@@ -17,16 +18,17 @@ static void t_copy(struct reftable_record *rec)
uint8_t typ;
typ = reftable_record_type(rec);
- reftable_record_init(&copy, typ);
+ cl_assert_equal_i(reftable_record_init(&copy, typ), 0);
reftable_record_copy_from(&copy, rec, REFTABLE_HASH_SIZE_SHA1);
/* do it twice to catch memory leaks */
reftable_record_copy_from(&copy, rec, REFTABLE_HASH_SIZE_SHA1);
- check(reftable_record_equal(rec, &copy, REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(reftable_record_equal(rec, &copy,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_record_release(&copy);
}
-static void t_varint_roundtrip(void)
+void test_reftable_record__varint_roundtrip(void)
{
uint64_t inputs[] = { 0,
1,
@@ -49,54 +51,75 @@ static void t_varint_roundtrip(void)
int n = put_var_int(&out, in);
uint64_t got = 0;
- check_int(n, >, 0);
+ cl_assert(n > 0);
out.len = n;
n = get_var_int(&got, &out);
- check_int(n, >, 0);
+ cl_assert(n > 0);
- check_int(got, ==, in);
+ cl_assert_equal_i(got, in);
}
}
+void test_reftable_record__varint_overflow(void)
+{
+ unsigned char buf[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0x00,
+ };
+ struct string_view view = {
+ .buf = buf,
+ .len = sizeof(buf),
+ };
+ uint64_t value;
+ cl_assert_equal_i(get_var_int(&value, &view), -1);
+}
+
static void set_hash(uint8_t *h, int j)
{
- for (int i = 0; i < hash_size(REFTABLE_HASH_SHA1); i++)
+ for (size_t i = 0; i < hash_size(REFTABLE_HASH_SHA1); i++)
h[i] = (j >> i) & 0xff;
}
-static void t_reftable_ref_record_comparison(void)
+void test_reftable_record__ref_record_comparison(void)
{
struct reftable_record in[3] = {
{
- .type = BLOCK_TYPE_REF,
+ .type = REFTABLE_BLOCK_TYPE_REF,
.u.ref.refname = (char *) "refs/heads/master",
.u.ref.value_type = REFTABLE_REF_VAL1,
},
{
- .type = BLOCK_TYPE_REF,
+ .type = REFTABLE_BLOCK_TYPE_REF,
.u.ref.refname = (char *) "refs/heads/master",
.u.ref.value_type = REFTABLE_REF_DELETION,
},
{
- .type = BLOCK_TYPE_REF,
+ .type = REFTABLE_BLOCK_TYPE_REF,
.u.ref.refname = (char *) "HEAD",
.u.ref.value_type = REFTABLE_REF_SYMREF,
.u.ref.value.symref = (char *) "refs/heads/master",
},
};
+ int cmp;
- check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
- check(!reftable_record_cmp(&in[0], &in[1]));
+ cl_assert(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1) == 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
+ cl_assert(!cmp);
- check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
- check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
+ cl_assert(reftable_record_equal(&in[1], &in[2],
+ REFTABLE_HASH_SIZE_SHA1) == 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[1], &in[2], &cmp), 0);
+ cl_assert(cmp > 0);
in[1].u.ref.value_type = in[0].u.ref.value_type;
- check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
- check(!reftable_record_cmp(&in[0], &in[1]));
+ cl_assert(reftable_record_equal(&in[0], &in[1],
+ REFTABLE_HASH_SIZE_SHA1) != 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
+ cl_assert(!cmp);
}
-static void t_reftable_ref_record_compare_name(void)
+void test_reftable_record__ref_record_compare_name(void)
{
struct reftable_ref_record recs[3] = {
{
@@ -110,21 +133,24 @@ static void t_reftable_ref_record_compare_name(void)
},
};
- check_int(reftable_ref_record_compare_name(&recs[0], &recs[1]), <, 0);
- check_int(reftable_ref_record_compare_name(&recs[1], &recs[0]), >, 0);
- check_int(reftable_ref_record_compare_name(&recs[0], &recs[2]), ==, 0);
+ cl_assert(reftable_ref_record_compare_name(&recs[0],
+ &recs[1]) < 0);
+ cl_assert(reftable_ref_record_compare_name(&recs[1],
+ &recs[0]) > 0);
+ cl_assert_equal_i(reftable_ref_record_compare_name(&recs[0],
+ &recs[2]), 0);
}
-static void t_reftable_ref_record_roundtrip(void)
+void test_reftable_record__ref_record_roundtrip(void)
{
struct reftable_buf scratch = REFTABLE_BUF_INIT;
for (int i = REFTABLE_REF_DELETION; i < REFTABLE_NR_REF_VALUETYPES; i++) {
struct reftable_record in = {
- .type = BLOCK_TYPE_REF,
+ .type = REFTABLE_BLOCK_TYPE_REF,
.u.ref.value_type = i,
};
- struct reftable_record out = { .type = BLOCK_TYPE_REF };
+ struct reftable_record out = { .type = REFTABLE_BLOCK_TYPE_REF };
struct reftable_buf key = REFTABLE_BUF_INIT;
uint8_t buffer[1024] = { 0 };
struct string_view dest = {
@@ -152,19 +178,21 @@ static void t_reftable_ref_record_roundtrip(void)
t_copy(&in);
- check_int(reftable_record_val_type(&in), ==, i);
- check_int(reftable_record_is_deletion(&in), ==, i == REFTABLE_REF_DELETION);
+ cl_assert_equal_i(reftable_record_val_type(&in), i);
+ cl_assert_equal_i(reftable_record_is_deletion(&in),
+ i == REFTABLE_REF_DELETION);
reftable_record_key(&in, &key);
n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
- check_int(n, >, 0);
+ cl_assert(n > 0);
/* decode into a non-zero reftable_record to test for leaks. */
m = reftable_record_decode(&out, key, i, dest, REFTABLE_HASH_SIZE_SHA1, &scratch);
- check_int(n, ==, m);
+ cl_assert_equal_i(n, m);
- check(reftable_ref_record_equal(&in.u.ref, &out.u.ref,
- REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(reftable_ref_record_equal(&in.u.ref,
+ &out.u.ref,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_record_release(&in);
reftable_buf_release(&key);
@@ -174,39 +202,45 @@ static void t_reftable_ref_record_roundtrip(void)
reftable_buf_release(&scratch);
}
-static void t_reftable_log_record_comparison(void)
+void test_reftable_record__log_record_comparison(void)
{
struct reftable_record in[3] = {
{
- .type = BLOCK_TYPE_LOG,
+ .type = REFTABLE_BLOCK_TYPE_LOG,
.u.log.refname = (char *) "refs/heads/master",
.u.log.update_index = 42,
},
{
- .type = BLOCK_TYPE_LOG,
+ .type = REFTABLE_BLOCK_TYPE_LOG,
.u.log.refname = (char *) "refs/heads/master",
.u.log.update_index = 22,
},
{
- .type = BLOCK_TYPE_LOG,
+ .type = REFTABLE_BLOCK_TYPE_LOG,
.u.log.refname = (char *) "refs/heads/main",
.u.log.update_index = 22,
},
};
-
- check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
- check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
- check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
+ int cmp;
+
+ cl_assert_equal_i(reftable_record_equal(&in[0], &in[1],
+ REFTABLE_HASH_SIZE_SHA1), 0);
+ cl_assert_equal_i(reftable_record_equal(&in[1], &in[2],
+ REFTABLE_HASH_SIZE_SHA1), 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[1], &in[2], &cmp), 0);
+ cl_assert(cmp > 0);
/* comparison should be reversed for equal keys, because
* comparison is now performed on the basis of update indices */
- check_int(reftable_record_cmp(&in[0], &in[1]), <, 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
+ cl_assert(cmp < 0);
in[1].u.log.update_index = in[0].u.log.update_index;
- check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
- check(!reftable_record_cmp(&in[0], &in[1]));
+ cl_assert(reftable_record_equal(&in[0], &in[1],
+ REFTABLE_HASH_SIZE_SHA1) != 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
}
-static void t_reftable_log_record_compare_key(void)
+void test_reftable_record__log_record_compare_key(void)
{
struct reftable_log_record logs[3] = {
{
@@ -223,19 +257,24 @@ static void t_reftable_log_record_compare_key(void)
},
};
- check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0);
- check_int(reftable_log_record_compare_key(&logs[1], &logs[0]), >, 0);
+ cl_assert(reftable_log_record_compare_key(&logs[0],
+ &logs[1]) < 0);
+ cl_assert(reftable_log_record_compare_key(&logs[1],
+ &logs[0]) > 0);
logs[1].update_index = logs[0].update_index;
- check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0);
+ cl_assert(reftable_log_record_compare_key(&logs[0],
+ &logs[1]) < 0);
- check_int(reftable_log_record_compare_key(&logs[0], &logs[2]), >, 0);
- check_int(reftable_log_record_compare_key(&logs[2], &logs[0]), <, 0);
+ cl_assert(reftable_log_record_compare_key(&logs[0],
+ &logs[2]) > 0);
+ cl_assert(reftable_log_record_compare_key(&logs[2],
+ &logs[0]) < 0);
logs[2].update_index = logs[0].update_index;
- check_int(reftable_log_record_compare_key(&logs[0], &logs[2]), ==, 0);
+ cl_assert_equal_i(reftable_log_record_compare_key(&logs[0], &logs[2]), 0);
}
-static void t_reftable_log_record_roundtrip(void)
+void test_reftable_record__log_record_roundtrip(void)
{
struct reftable_log_record in[] = {
{
@@ -269,12 +308,12 @@ static void t_reftable_log_record_roundtrip(void)
set_hash(in[2].value.update.new_hash, 3);
set_hash(in[2].value.update.old_hash, 4);
- check(!reftable_log_record_is_deletion(&in[0]));
- check(reftable_log_record_is_deletion(&in[1]));
- check(!reftable_log_record_is_deletion(&in[2]));
+ cl_assert_equal_i(reftable_log_record_is_deletion(&in[0]), 0);
+ cl_assert(reftable_log_record_is_deletion(&in[1]) != 0);
+ cl_assert_equal_i(reftable_log_record_is_deletion(&in[2]), 0);
for (size_t i = 0; i < ARRAY_SIZE(in); i++) {
- struct reftable_record rec = { .type = BLOCK_TYPE_LOG };
+ struct reftable_record rec = { .type = REFTABLE_BLOCK_TYPE_LOG };
struct reftable_buf key = REFTABLE_BUF_INIT;
uint8_t buffer[1024] = { 0 };
struct string_view dest = {
@@ -283,7 +322,7 @@ static void t_reftable_log_record_roundtrip(void)
};
/* populate out, to check for leaks. */
struct reftable_record out = {
- .type = BLOCK_TYPE_LOG,
+ .type = REFTABLE_BLOCK_TYPE_LOG,
.u.log = {
.refname = xstrdup("old name"),
.value_type = REFTABLE_LOG_UPDATE,
@@ -305,14 +344,14 @@ static void t_reftable_log_record_roundtrip(void)
reftable_record_key(&rec, &key);
n = reftable_record_encode(&rec, dest, REFTABLE_HASH_SIZE_SHA1);
- check_int(n, >=, 0);
+ cl_assert(n >= 0);
valtype = reftable_record_val_type(&rec);
m = reftable_record_decode(&out, key, valtype, dest,
REFTABLE_HASH_SIZE_SHA1, &scratch);
- check_int(n, ==, m);
+ cl_assert_equal_i(n, m);
- check(reftable_log_record_equal(&in[i], &out.u.log,
- REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(reftable_log_record_equal(&in[i], &out.u.log,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_log_record_release(&in[i]);
reftable_buf_release(&key);
reftable_record_release(&out);
@@ -321,7 +360,7 @@ static void t_reftable_log_record_roundtrip(void)
reftable_buf_release(&scratch);
}
-static void t_key_roundtrip(void)
+void test_reftable_record__key_roundtrip(void)
{
uint8_t buffer[1024] = { 0 };
struct string_view dest = {
@@ -336,63 +375,72 @@ static void t_key_roundtrip(void)
int n, m;
uint8_t rt_extra;
- check(!reftable_buf_addstr(&last_key, "refs/heads/master"));
- check(!reftable_buf_addstr(&key, "refs/tags/bla"));
+ cl_assert_equal_i(reftable_buf_addstr(&last_key,
+ "refs/heads/master"), 0);
+ cl_assert_equal_i(reftable_buf_addstr(&key,
+ "refs/tags/bla"), 0);
extra = 6;
n = reftable_encode_key(&restart, dest, last_key, key, extra);
- check(!restart);
- check_int(n, >, 0);
+ cl_assert(!restart);
+ cl_assert(n > 0);
- check(!reftable_buf_addstr(&roundtrip, "refs/heads/master"));
+ cl_assert_equal_i(reftable_buf_addstr(&roundtrip,
+ "refs/heads/master"), 0);
m = reftable_decode_key(&roundtrip, &rt_extra, dest);
- check_int(n, ==, m);
- check(!reftable_buf_cmp(&key, &roundtrip));
- check_int(rt_extra, ==, extra);
+ cl_assert_equal_i(n, m);
+ cl_assert_equal_i(reftable_buf_cmp(&key, &roundtrip), 0);
+ cl_assert_equal_i(rt_extra, extra);
reftable_buf_release(&last_key);
reftable_buf_release(&key);
reftable_buf_release(&roundtrip);
}
-static void t_reftable_obj_record_comparison(void)
+void test_reftable_record__obj_record_comparison(void)
{
uint8_t id_bytes[] = { 0, 1, 2, 3, 4, 5, 6 };
uint64_t offsets[] = { 0, 16, 32, 48, 64, 80, 96, 112};
struct reftable_record in[3] = {
{
- .type = BLOCK_TYPE_OBJ,
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
.u.obj.hash_prefix = id_bytes,
.u.obj.hash_prefix_len = 7,
.u.obj.offsets = offsets,
.u.obj.offset_len = 8,
},
{
- .type = BLOCK_TYPE_OBJ,
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
.u.obj.hash_prefix = id_bytes,
.u.obj.hash_prefix_len = 7,
.u.obj.offsets = offsets,
.u.obj.offset_len = 5,
},
{
- .type = BLOCK_TYPE_OBJ,
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
.u.obj.hash_prefix = id_bytes,
.u.obj.hash_prefix_len = 5,
},
};
+ int cmp;
- check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
- check(!reftable_record_cmp(&in[0], &in[1]));
+ cl_assert_equal_i(reftable_record_equal(&in[0], &in[1],
+ REFTABLE_HASH_SIZE_SHA1), 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
+ cl_assert(!cmp);
- check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
- check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
+ cl_assert_equal_i(reftable_record_equal(&in[1], &in[2],
+ REFTABLE_HASH_SIZE_SHA1), 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[1], &in[2], &cmp), 0);
+ cl_assert(cmp > 0);
in[1].u.obj.offset_len = in[0].u.obj.offset_len;
- check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
- check(!reftable_record_cmp(&in[0], &in[1]));
+ cl_assert(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1) != 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
+ cl_assert(!cmp);
}
-static void t_reftable_obj_record_roundtrip(void)
+void test_reftable_record__obj_record_roundtrip(void)
{
uint8_t testHash1[REFTABLE_HASH_SIZE_SHA1] = { 1, 2, 3, 4, 0 };
uint64_t till9[] = { 1, 2, 3, 4, 500, 600, 700, 800, 9000 };
@@ -423,27 +471,28 @@ static void t_reftable_obj_record_roundtrip(void)
.len = sizeof(buffer),
};
struct reftable_record in = {
- .type = BLOCK_TYPE_OBJ,
+ .type = REFTABLE_BLOCK_TYPE_OBJ,
.u = {
.obj = recs[i],
},
};
struct reftable_buf key = REFTABLE_BUF_INIT;
- struct reftable_record out = { .type = BLOCK_TYPE_OBJ };
+ struct reftable_record out = { .type = REFTABLE_BLOCK_TYPE_OBJ };
int n, m;
uint8_t extra;
- check(!reftable_record_is_deletion(&in));
+ cl_assert_equal_i(reftable_record_is_deletion(&in), 0);
t_copy(&in);
reftable_record_key(&in, &key);
n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
- check_int(n, >, 0);
+ cl_assert(n > 0);
extra = reftable_record_val_type(&in);
m = reftable_record_decode(&out, key, extra, dest,
REFTABLE_HASH_SIZE_SHA1, &scratch);
- check_int(n, ==, m);
+ cl_assert_equal_i(n, m);
- check(reftable_record_equal(&in, &out, REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(reftable_record_equal(&in, &out,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_buf_release(&key);
reftable_record_release(&out);
}
@@ -451,47 +500,57 @@ static void t_reftable_obj_record_roundtrip(void)
reftable_buf_release(&scratch);
}
-static void t_reftable_index_record_comparison(void)
+void test_reftable_record__index_record_comparison(void)
{
struct reftable_record in[3] = {
{
- .type = BLOCK_TYPE_INDEX,
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
.u.idx.offset = 22,
.u.idx.last_key = REFTABLE_BUF_INIT,
},
{
- .type = BLOCK_TYPE_INDEX,
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
.u.idx.offset = 32,
.u.idx.last_key = REFTABLE_BUF_INIT,
},
{
- .type = BLOCK_TYPE_INDEX,
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
.u.idx.offset = 32,
.u.idx.last_key = REFTABLE_BUF_INIT,
},
};
- check(!reftable_buf_addstr(&in[0].u.idx.last_key, "refs/heads/master"));
- check(!reftable_buf_addstr(&in[1].u.idx.last_key, "refs/heads/master"));
- check(!reftable_buf_addstr(&in[2].u.idx.last_key, "refs/heads/branch"));
+ int cmp;
+
+ cl_assert_equal_i(reftable_buf_addstr(&in[0].u.idx.last_key,
+ "refs/heads/master"), 0);
+ cl_assert_equal_i(reftable_buf_addstr(&in[1].u.idx.last_key, "refs/heads/master"), 0);
+ cl_assert(reftable_buf_addstr(&in[2].u.idx.last_key,
+ "refs/heads/branch") == 0);
- check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
- check(!reftable_record_cmp(&in[0], &in[1]));
+ cl_assert_equal_i(reftable_record_equal(&in[0], &in[1],
+ REFTABLE_HASH_SIZE_SHA1), 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
+ cl_assert(!cmp);
- check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
- check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
+ cl_assert_equal_i(reftable_record_equal(&in[1], &in[2],
+ REFTABLE_HASH_SIZE_SHA1), 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[1], &in[2], &cmp), 0);
+ cl_assert(cmp > 0);
in[1].u.idx.offset = in[0].u.idx.offset;
- check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
- check(!reftable_record_cmp(&in[0], &in[1]));
+ cl_assert(reftable_record_equal(&in[0], &in[1],
+ REFTABLE_HASH_SIZE_SHA1) != 0);
+ cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
+ cl_assert(!cmp);
for (size_t i = 0; i < ARRAY_SIZE(in); i++)
reftable_record_release(&in[i]);
}
-static void t_reftable_index_record_roundtrip(void)
+void test_reftable_record__index_record_roundtrip(void)
{
struct reftable_record in = {
- .type = BLOCK_TYPE_INDEX,
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
.u.idx = {
.offset = 42,
.last_key = REFTABLE_BUF_INIT,
@@ -505,48 +564,32 @@ static void t_reftable_index_record_roundtrip(void)
struct reftable_buf scratch = REFTABLE_BUF_INIT;
struct reftable_buf key = REFTABLE_BUF_INIT;
struct reftable_record out = {
- .type = BLOCK_TYPE_INDEX,
+ .type = REFTABLE_BLOCK_TYPE_INDEX,
.u.idx = { .last_key = REFTABLE_BUF_INIT },
};
int n, m;
uint8_t extra;
- check(!reftable_buf_addstr(&in.u.idx.last_key, "refs/heads/master"));
+ cl_assert_equal_i(reftable_buf_addstr(&in.u.idx.last_key,
+ "refs/heads/master"), 0);
reftable_record_key(&in, &key);
t_copy(&in);
- check(!reftable_record_is_deletion(&in));
- check(!reftable_buf_cmp(&key, &in.u.idx.last_key));
+ cl_assert_equal_i(reftable_record_is_deletion(&in), 0);
+ cl_assert_equal_i(reftable_buf_cmp(&key, &in.u.idx.last_key), 0);
n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
- check_int(n, >, 0);
+ cl_assert(n > 0);
extra = reftable_record_val_type(&in);
- m = reftable_record_decode(&out, key, extra, dest, REFTABLE_HASH_SIZE_SHA1,
- &scratch);
- check_int(m, ==, n);
+ m = reftable_record_decode(&out, key, extra, dest,
+ REFTABLE_HASH_SIZE_SHA1, &scratch);
+ cl_assert_equal_i(m, n);
- check(reftable_record_equal(&in, &out, REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(reftable_record_equal(&in, &out,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_record_release(&out);
reftable_buf_release(&key);
reftable_buf_release(&scratch);
reftable_buf_release(&in.u.idx.last_key);
}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
- TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
- TEST(t_reftable_index_record_comparison(), "comparison operations work on index record");
- TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record");
- TEST(t_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works");
- TEST(t_reftable_log_record_compare_key(), "reftable_log_record_compare_key works");
- TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
- TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
- TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");
- TEST(t_key_roundtrip(), "reftable_encode_key and reftable_decode_key work");
- TEST(t_reftable_obj_record_roundtrip(), "record operations work on obj record");
- TEST(t_reftable_index_record_roundtrip(), "record operations work on index record");
-
- return test_done();
-}
diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/u-reftable-stack.c
index aeec195b2b..a8b91812e8 100644
--- a/t/unit-tests/t-reftable-stack.c
+++ b/t/unit-tests/u-reftable-stack.c
@@ -8,13 +8,13 @@ https://developers.google.com/open-source/licenses/bsd
#define DISABLE_SIGN_COMPARE_WARNINGS
-#include "test-lib.h"
-#include "lib-reftable.h"
+#include "unit-test.h"
#include "dir.h"
+#include "lib-reftable.h"
#include "reftable/merged.h"
-#include "reftable/reader.h"
#include "reftable/reftable-error.h"
#include "reftable/stack.h"
+#include "reftable/table.h"
#include "strbuf.h"
#include "tempfile.h"
#include <dirent.h>
@@ -70,11 +70,11 @@ static char *get_tmp_template(int linenumber)
static char *get_tmp_dir(int linenumber)
{
char *dir = get_tmp_template(linenumber);
- check(mkdtemp(dir) != NULL);
+ cl_assert(mkdtemp(dir) != NULL);
return dir;
}
-static void t_read_file(void)
+void test_reftable_stack__read_file(void)
{
char *fn = get_tmp_template(__LINE__);
struct tempfile *tmp = mks_tempfile(fn);
@@ -84,17 +84,17 @@ static void t_read_file(void)
char **names = NULL;
const char *want[] = { "line1", "line2", "line3" };
- check_int(fd, >, 0);
+ cl_assert(fd > 0);
n = write_in_full(fd, out, strlen(out));
- check_int(n, ==, strlen(out));
+ cl_assert_equal_i(n, strlen(out));
err = close(fd);
- check_int(err, >=, 0);
+ cl_assert(err >= 0);
err = read_lines(fn, &names);
- check(!err);
+ cl_assert(!err);
for (size_t i = 0; names[i]; i++)
- check_str(want[i], names[i]);
+ cl_assert_equal_s(want[i], names[i]);
free_names(names);
(void) remove(fn);
delete_tempfile(&tmp);
@@ -103,7 +103,8 @@ static void t_read_file(void)
static int write_test_ref(struct reftable_writer *wr, void *arg)
{
struct reftable_ref_record *ref = arg;
- reftable_writer_set_limits(wr, ref->update_index, ref->update_index);
+ cl_assert_equal_i(reftable_writer_set_limits(wr,
+ ref->update_index, ref->update_index), 0);
return reftable_writer_add_ref(wr, ref);
}
@@ -111,7 +112,6 @@ static void write_n_ref_tables(struct reftable_stack *st,
size_t n)
{
int disable_auto_compact;
- int err;
disable_auto_compact = st->opts.disable_auto_compact;
st->opts.disable_auto_compact = 1;
@@ -125,10 +125,10 @@ static void write_n_ref_tables(struct reftable_stack *st,
snprintf(buf, sizeof(buf), "refs/heads/branch-%04"PRIuMAX, (uintmax_t)i);
ref.refname = buf;
- t_reftable_set_hash(ref.value.val1, i, REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(ref.value.val1, i, REFTABLE_HASH_SHA1);
- err = reftable_stack_add(st, &write_test_ref, &ref);
- check(!err);
+ cl_assert_equal_i(reftable_stack_add(st,
+ &write_test_ref, &ref, 0), 0);
}
st->opts.disable_auto_compact = disable_auto_compact;
@@ -143,11 +143,13 @@ static int write_test_log(struct reftable_writer *wr, void *arg)
{
struct write_log_arg *wla = arg;
- reftable_writer_set_limits(wr, wla->update_index, wla->update_index);
+ cl_assert_equal_i(reftable_writer_set_limits(wr,
+ wla->update_index,
+ wla->update_index), 0);
return reftable_writer_add_log(wr, wla->log);
}
-static void t_reftable_stack_add_one(void)
+void test_reftable_stack__add_one(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_buf scratch = REFTABLE_BUF_INIT;
@@ -156,7 +158,6 @@ static void t_reftable_stack_add_one(void)
.default_permissions = 0660,
};
struct reftable_stack *st = NULL;
- int err;
struct reftable_ref_record ref = {
.refname = (char *) "HEAD",
.update_index = 1,
@@ -165,32 +166,37 @@ static void t_reftable_stack_add_one(void)
};
struct reftable_ref_record dest = { 0 };
struct stat stat_result = { 0 };
+ int err;
+
err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert(!err);
- err = reftable_stack_add(st, write_test_ref, &ref);
- check(!err);
+ err = reftable_stack_add(st, write_test_ref, &ref, 0);
+ cl_assert(!err);
err = reftable_stack_read_ref(st, ref.refname, &dest);
- check(!err);
- check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
- check_int(st->readers_len, >, 0);
+ cl_assert(!err);
+ cl_assert(reftable_ref_record_equal(&ref, &dest,
+ REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(st->tables_len > 0);
#ifndef GIT_WINDOWS_NATIVE
- check(!reftable_buf_addstr(&scratch, dir));
- check(!reftable_buf_addstr(&scratch, "/tables.list"));
- err = stat(scratch.buf, &stat_result);
- check(!err);
- check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
+ cl_assert_equal_i(reftable_buf_addstr(&scratch, dir), 0);
+ cl_assert_equal_i(reftable_buf_addstr(&scratch,
+ "/tables.list"), 0);
+ cl_assert_equal_i(stat(scratch.buf, &stat_result), 0);
+ cl_assert_equal_i((stat_result.st_mode & 0777),
+ opts.default_permissions);
reftable_buf_reset(&scratch);
- check(!reftable_buf_addstr(&scratch, dir));
- check(!reftable_buf_addstr(&scratch, "/"));
+ cl_assert_equal_i(reftable_buf_addstr(&scratch, dir), 0);
+ cl_assert_equal_i(reftable_buf_addstr(&scratch, "/"), 0);
/* do not try at home; not an external API for reftable. */
- check(!reftable_buf_addstr(&scratch, st->readers[0]->name));
+ cl_assert(!reftable_buf_addstr(&scratch, st->tables[0]->name));
err = stat(scratch.buf, &stat_result);
- check(!err);
- check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
+ cl_assert(!err);
+ cl_assert_equal_i((stat_result.st_mode & 0777),
+ opts.default_permissions);
#else
(void) stat_result;
#endif
@@ -202,14 +208,13 @@ static void t_reftable_stack_add_one(void)
umask(mask);
}
-static void t_reftable_stack_uptodate(void)
+void test_reftable_stack__uptodate(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st1 = NULL;
struct reftable_stack *st2 = NULL;
char *dir = get_tmp_dir(__LINE__);
- int err;
struct reftable_ref_record ref1 = {
.refname = (char *) "HEAD",
.update_index = 1,
@@ -227,34 +232,25 @@ static void t_reftable_stack_uptodate(void)
/* simulate multi-process access to the same stack
by creating two stacks for the same directory.
*/
- err = reftable_new_stack(&st1, dir, &opts);
- check(!err);
-
- err = reftable_new_stack(&st2, dir, &opts);
- check(!err);
-
- err = reftable_stack_add(st1, write_test_ref, &ref1);
- check(!err);
-
- err = reftable_stack_add(st2, write_test_ref, &ref2);
- check_int(err, ==, REFTABLE_OUTDATED_ERROR);
-
- err = reftable_stack_reload(st2);
- check(!err);
-
- err = reftable_stack_add(st2, write_test_ref, &ref2);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
+ cl_assert_equal_i(reftable_stack_add(st1, write_test_ref,
+ &ref1, 0), 0);
+ cl_assert_equal_i(reftable_stack_add(st2, write_test_ref,
+ &ref2, 0), REFTABLE_OUTDATED_ERROR);
+ cl_assert_equal_i(reftable_stack_reload(st2), 0);
+ cl_assert_equal_i(reftable_stack_add(st2, write_test_ref,
+ &ref2, 0), 0);
reftable_stack_destroy(st1);
reftable_stack_destroy(st2);
clear_dir(dir);
}
-static void t_reftable_stack_transaction_api(void)
+void test_reftable_stack__transaction_api(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
- int err;
struct reftable_addition *add = NULL;
struct reftable_ref_record ref = {
@@ -265,37 +261,32 @@ static void t_reftable_stack_transaction_api(void)
};
struct reftable_ref_record dest = { 0 };
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
reftable_addition_destroy(add);
- err = reftable_stack_new_addition(&add, st, 0);
- check(!err);
-
- err = reftable_addition_add(add, write_test_ref, &ref);
- check(!err);
-
- err = reftable_addition_commit(add);
- check(!err);
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st, 0), 0);
+ cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
+ &ref), 0);
+ cl_assert_equal_i(reftable_addition_commit(add), 0);
reftable_addition_destroy(add);
- err = reftable_stack_read_ref(st, ref.refname, &dest);
- check(!err);
- check_int(REFTABLE_REF_SYMREF, ==, dest.value_type);
- check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
+ cl_assert_equal_i(reftable_stack_read_ref(st, ref.refname,
+ &dest), 0);
+ cl_assert_equal_i(REFTABLE_REF_SYMREF, dest.value_type);
+ cl_assert(reftable_ref_record_equal(&ref, &dest,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_ref_record_release(&dest);
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void t_reftable_stack_transaction_with_reload(void)
+void test_reftable_stack__transaction_with_reload(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_stack *st1 = NULL, *st2 = NULL;
- int err;
struct reftable_addition *add = NULL;
struct reftable_ref_record refs[2] = {
{
@@ -313,17 +304,12 @@ static void t_reftable_stack_transaction_with_reload(void)
};
struct reftable_ref_record ref = { 0 };
- err = reftable_new_stack(&st1, dir, NULL);
- check(!err);
- err = reftable_new_stack(&st2, dir, NULL);
- check(!err);
-
- err = reftable_stack_new_addition(&add, st1, 0);
- check(!err);
- err = reftable_addition_add(add, write_test_ref, &refs[0]);
- check(!err);
- err = reftable_addition_commit(add);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, NULL), 0);
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, NULL), 0);
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st1, 0), 0);
+ cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
+ &refs[0]), 0);
+ cl_assert_equal_i(reftable_addition_commit(add), 0);
reftable_addition_destroy(add);
/*
@@ -331,20 +317,20 @@ static void t_reftable_stack_transaction_with_reload(void)
* create the addition and lock the stack by default, but allow the
* reload to happen when REFTABLE_STACK_NEW_ADDITION_RELOAD is set.
*/
- err = reftable_stack_new_addition(&add, st2, 0);
- check_int(err, ==, REFTABLE_OUTDATED_ERROR);
- err = reftable_stack_new_addition(&add, st2, REFTABLE_STACK_NEW_ADDITION_RELOAD);
- check(!err);
- err = reftable_addition_add(add, write_test_ref, &refs[1]);
- check(!err);
- err = reftable_addition_commit(add);
- check(!err);
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st2, 0),
+ REFTABLE_OUTDATED_ERROR);
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st2,
+ REFTABLE_STACK_NEW_ADDITION_RELOAD), 0);
+ cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
+ &refs[1]), 0);
+ cl_assert_equal_i(reftable_addition_commit(add), 0);
reftable_addition_destroy(add);
for (size_t i = 0; i < ARRAY_SIZE(refs); i++) {
- err = reftable_stack_read_ref(st2, refs[i].refname, &ref);
- check(!err);
- check(reftable_ref_record_equal(&refs[i], &ref, REFTABLE_HASH_SIZE_SHA1));
+ cl_assert_equal_i(reftable_stack_read_ref(st2,
+ refs[i].refname, &ref) , 0);
+ cl_assert(reftable_ref_record_equal(&refs[i], &ref,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
}
reftable_ref_record_release(&ref);
@@ -353,17 +339,15 @@ static void t_reftable_stack_transaction_with_reload(void)
clear_dir(dir);
}
-static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
+void test_reftable_stack__transaction_api_performs_auto_compaction(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = {0};
struct reftable_addition *add = NULL;
struct reftable_stack *st = NULL;
size_t n = 20;
- int err;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
for (size_t i = 0; i <= n; i++) {
struct reftable_ref_record ref = {
@@ -383,14 +367,11 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
*/
st->opts.disable_auto_compact = i != n;
- err = reftable_stack_new_addition(&add, st, 0);
- check(!err);
-
- err = reftable_addition_add(add, write_test_ref, &ref);
- check(!err);
-
- err = reftable_addition_commit(add);
- check(!err);
+ cl_assert_equal_i(reftable_stack_new_addition(&add,
+ st, 0), 0);
+ cl_assert_equal_i(reftable_addition_add(add,
+ write_test_ref, &ref), 0);
+ cl_assert_equal_i(reftable_addition_commit(add), 0);
reftable_addition_destroy(add);
@@ -400,16 +381,16 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
* all tables in the stack.
*/
if (i != n)
- check_int(st->merged->readers_len, ==, i + 1);
+ cl_assert_equal_i(st->merged->tables_len, i + 1);
else
- check_int(st->merged->readers_len, ==, 1);
+ cl_assert_equal_i(st->merged->tables_len, 1);
}
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void t_reftable_stack_auto_compaction_fails_gracefully(void)
+void test_reftable_stack__auto_compaction_fails_gracefully(void)
{
struct reftable_ref_record ref = {
.refname = (char *) "refs/heads/master",
@@ -423,32 +404,31 @@ static void t_reftable_stack_auto_compaction_fails_gracefully(void)
char *dir = get_tmp_dir(__LINE__);
int err;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
-
- err = reftable_stack_add(st, write_test_ref, &ref);
- check(!err);
- check_int(st->merged->readers_len, ==, 1);
- check_int(st->stats.attempts, ==, 0);
- check_int(st->stats.failures, ==, 0);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
+ &ref, 0), 0);
+ cl_assert_equal_i(st->merged->tables_len, 1);
+ cl_assert_equal_i(st->stats.attempts, 0);
+ cl_assert_equal_i(st->stats.failures, 0);
/*
* Lock the newly written table such that it cannot be compacted.
* Adding a new table to the stack should not be impacted by this, even
* though auto-compaction will now fail.
*/
- check(!reftable_buf_addstr(&table_path, dir));
- check(!reftable_buf_addstr(&table_path, "/"));
- check(!reftable_buf_addstr(&table_path, st->readers[0]->name));
- check(!reftable_buf_addstr(&table_path, ".lock"));
+ cl_assert(!reftable_buf_addstr(&table_path, dir));
+ cl_assert(!reftable_buf_addstr(&table_path, "/"));
+ cl_assert(!reftable_buf_addstr(&table_path,
+ st->tables[0]->name));
+ cl_assert(!reftable_buf_addstr(&table_path, ".lock"));
write_file_buf(table_path.buf, "", 0);
ref.update_index = 2;
- err = reftable_stack_add(st, write_test_ref, &ref);
- check(!err);
- check_int(st->merged->readers_len, ==, 2);
- check_int(st->stats.attempts, ==, 1);
- check_int(st->stats.failures, ==, 1);
+ err = reftable_stack_add(st, write_test_ref, &ref, 0);
+ cl_assert(!err);
+ cl_assert_equal_i(st->merged->tables_len, 2);
+ cl_assert_equal_i(st->stats.attempts, 1);
+ cl_assert_equal_i(st->stats.failures, 1);
reftable_stack_destroy(st);
reftable_buf_release(&table_path);
@@ -460,12 +440,11 @@ static int write_error(struct reftable_writer *wr UNUSED, void *arg)
return *((int *)arg);
}
-static void t_reftable_stack_update_index_check(void)
+void test_reftable_stack__update_index_check(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
- int err;
struct reftable_ref_record ref1 = {
.refname = (char *) "name1",
.update_index = 1,
@@ -479,39 +458,33 @@ static void t_reftable_stack_update_index_check(void)
.value.symref = (char *) "master",
};
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
-
- err = reftable_stack_add(st, write_test_ref, &ref1);
- check(!err);
-
- err = reftable_stack_add(st, write_test_ref, &ref2);
- check_int(err, ==, REFTABLE_API_ERROR);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
+ &ref1, 0), 0);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
+ &ref2, 0), REFTABLE_API_ERROR);
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void t_reftable_stack_lock_failure(void)
+void test_reftable_stack__lock_failure(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
- int err, i;
+ int i;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
- for (i = -1; i != REFTABLE_EMPTY_TABLE_ERROR; i--) {
- err = reftable_stack_add(st, write_error, &i);
- check_int(err, ==, i);
- }
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
+ for (i = -1; i != REFTABLE_EMPTY_TABLE_ERROR; i--)
+ cl_assert_equal_i(reftable_stack_add(st, write_error,
+ &i, 0), i);
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void t_reftable_stack_add(void)
+void test_reftable_stack__add(void)
{
- int err = 0;
struct reftable_write_options opts = {
.exact_log_message = 1,
.default_permissions = 0660,
@@ -524,9 +497,10 @@ static void t_reftable_stack_add(void)
struct reftable_buf path = REFTABLE_BUF_INIT;
struct stat stat_result;
size_t i, N = ARRAY_SIZE(refs);
+ int err = 0;
err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert(!err);
for (i = 0; i < N; i++) {
char buf[256];
@@ -534,66 +508,66 @@ static void t_reftable_stack_add(void)
refs[i].refname = xstrdup(buf);
refs[i].update_index = i + 1;
refs[i].value_type = REFTABLE_REF_VAL1;
- t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(refs[i].value.val1, i,
+ REFTABLE_HASH_SHA1);
logs[i].refname = xstrdup(buf);
logs[i].update_index = N + i + 1;
logs[i].value_type = REFTABLE_LOG_UPDATE;
logs[i].value.update.email = xstrdup("identity@invalid");
- t_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i,
+ REFTABLE_HASH_SHA1);
}
- for (i = 0; i < N; i++) {
- int err = reftable_stack_add(st, write_test_ref, &refs[i]);
- check(!err);
- }
+ for (i = 0; i < N; i++)
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
+ &refs[i], 0), 0);
for (i = 0; i < N; i++) {
struct write_log_arg arg = {
.log = &logs[i],
.update_index = reftable_stack_next_update_index(st),
};
- int err = reftable_stack_add(st, write_test_log, &arg);
- check(!err);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
+ &arg, 0), 0);
}
- err = reftable_stack_compact_all(st, NULL);
- check(!err);
+ cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
for (i = 0; i < N; i++) {
struct reftable_ref_record dest = { 0 };
- int err = reftable_stack_read_ref(st, refs[i].refname, &dest);
- check(!err);
- check(reftable_ref_record_equal(&dest, refs + i,
- REFTABLE_HASH_SIZE_SHA1));
+ cl_assert_equal_i(reftable_stack_read_ref(st,
+ refs[i].refname, &dest), 0);
+ cl_assert(reftable_ref_record_equal(&dest, refs + i,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_ref_record_release(&dest);
}
for (i = 0; i < N; i++) {
struct reftable_log_record dest = { 0 };
- int err = reftable_stack_read_log(st, refs[i].refname, &dest);
- check(!err);
- check(reftable_log_record_equal(&dest, logs + i,
- REFTABLE_HASH_SIZE_SHA1));
+ cl_assert_equal_i(reftable_stack_read_log(st,
+ refs[i].refname, &dest), 0);
+ cl_assert(reftable_log_record_equal(&dest, logs + i,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_log_record_release(&dest);
}
#ifndef GIT_WINDOWS_NATIVE
- check(!reftable_buf_addstr(&path, dir));
- check(!reftable_buf_addstr(&path, "/tables.list"));
- err = stat(path.buf, &stat_result);
- check(!err);
- check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
+ cl_assert_equal_i(reftable_buf_addstr(&path, dir), 0);
+ cl_assert_equal_i(reftable_buf_addstr(&path, "/tables.list"), 0);
+ cl_assert_equal_i(stat(path.buf, &stat_result), 0);
+ cl_assert_equal_i((stat_result.st_mode & 0777), opts.default_permissions);
reftable_buf_reset(&path);
- check(!reftable_buf_addstr(&path, dir));
- check(!reftable_buf_addstr(&path, "/"));
+ cl_assert_equal_i(reftable_buf_addstr(&path, dir), 0);
+ cl_assert_equal_i(reftable_buf_addstr(&path, "/"), 0);
/* do not try at home; not an external API for reftable. */
- check(!reftable_buf_addstr(&path, st->readers[0]->name));
+ cl_assert(!reftable_buf_addstr(&path, st->tables[0]->name));
err = stat(path.buf, &stat_result);
- check(!err);
- check_int((stat_result.st_mode & 0777), ==, opts.default_permissions);
+ cl_assert(!err);
+ cl_assert_equal_i((stat_result.st_mode & 0777),
+ opts.default_permissions);
#else
(void) stat_result;
#endif
@@ -608,7 +582,7 @@ static void t_reftable_stack_add(void)
clear_dir(dir);
}
-static void t_reftable_stack_iterator(void)
+void test_reftable_stack__iterator(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
@@ -619,27 +593,27 @@ static void t_reftable_stack_iterator(void)
size_t N = ARRAY_SIZE(refs), i;
int err;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
for (i = 0; i < N; i++) {
refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
refs[i].update_index = i + 1;
refs[i].value_type = REFTABLE_REF_VAL1;
- t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(refs[i].value.val1, i,
+ REFTABLE_HASH_SHA1);
logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
logs[i].update_index = i + 1;
logs[i].value_type = REFTABLE_LOG_UPDATE;
logs[i].value.update.email = xstrdup("johndoe@invalid");
logs[i].value.update.message = xstrdup("commit\n");
- t_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i,
+ REFTABLE_HASH_SHA1);
}
- for (i = 0; i < N; i++) {
- err = reftable_stack_add(st, write_test_ref, &refs[i]);
- check(!err);
- }
+ for (i = 0; i < N; i++)
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
+ &refs[i], 0), 0);
for (i = 0; i < N; i++) {
struct write_log_arg arg = {
@@ -647,8 +621,8 @@ static void t_reftable_stack_iterator(void)
.update_index = reftable_stack_next_update_index(st),
};
- err = reftable_stack_add(st, write_test_log, &arg);
- check(!err);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
+ &arg, 0), 0);
}
reftable_stack_init_ref_iterator(st, &it);
@@ -659,16 +633,16 @@ static void t_reftable_stack_iterator(void)
err = reftable_iterator_next_ref(&it, &ref);
if (err > 0)
break;
- check(!err);
- check(reftable_ref_record_equal(&ref, &refs[i], REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(!err);
+ cl_assert(reftable_ref_record_equal(&ref, &refs[i],
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_ref_record_release(&ref);
}
- check_int(i, ==, N);
+ cl_assert_equal_i(i, N);
reftable_iterator_destroy(&it);
- err = reftable_stack_init_log_iterator(st, &it);
- check(!err);
+ cl_assert_equal_i(reftable_stack_init_log_iterator(st, &it), 0);
reftable_iterator_seek_log(&it, logs[0].refname);
for (i = 0; ; i++) {
@@ -677,11 +651,12 @@ static void t_reftable_stack_iterator(void)
err = reftable_iterator_next_log(&it, &log);
if (err > 0)
break;
- check(!err);
- check(reftable_log_record_equal(&log, &logs[i], REFTABLE_HASH_SIZE_SHA1));
+ cl_assert(!err);
+ cl_assert(reftable_log_record_equal(&log, &logs[i],
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_log_record_release(&log);
}
- check_int(i, ==, N);
+ cl_assert_equal_i(i, N);
reftable_stack_destroy(st);
reftable_iterator_destroy(&it);
@@ -692,9 +667,8 @@ static void t_reftable_stack_iterator(void)
clear_dir(dir);
}
-static void t_reftable_stack_log_normalize(void)
+void test_reftable_stack__log_normalize(void)
{
- int err = 0;
struct reftable_write_options opts = {
0,
};
@@ -719,28 +693,26 @@ static void t_reftable_stack_log_normalize(void)
.update_index = 1,
};
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
input.value.update.message = (char *) "one\ntwo";
- err = reftable_stack_add(st, write_test_log, &arg);
- check_int(err, ==, REFTABLE_API_ERROR);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
+ &arg, 0), REFTABLE_API_ERROR);
input.value.update.message = (char *) "one";
- err = reftable_stack_add(st, write_test_log, &arg);
- check(!err);
-
- err = reftable_stack_read_log(st, input.refname, &dest);
- check(!err);
- check_str(dest.value.update.message, "one\n");
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
+ &arg, 0), 0);
+ cl_assert_equal_i(reftable_stack_read_log(st, input.refname,
+ &dest), 0);
+ cl_assert_equal_s(dest.value.update.message, "one\n");
input.value.update.message = (char *) "two\n";
arg.update_index = 2;
- err = reftable_stack_add(st, write_test_log, &arg);
- check(!err);
- err = reftable_stack_read_log(st, input.refname, &dest);
- check(!err);
- check_str(dest.value.update.message, "two\n");
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
+ &arg, 0), 0);
+ cl_assert_equal_i(reftable_stack_read_log(st, input.refname,
+ &dest), 0);
+ cl_assert_equal_s(dest.value.update.message, "two\n");
/* cleanup */
reftable_stack_destroy(st);
@@ -748,20 +720,18 @@ static void t_reftable_stack_log_normalize(void)
clear_dir(dir);
}
-static void t_reftable_stack_tombstone(void)
+void test_reftable_stack__tombstone(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
- int err;
struct reftable_ref_record refs[2] = { 0 };
struct reftable_log_record logs[2] = { 0 };
size_t i, N = ARRAY_SIZE(refs);
struct reftable_ref_record dest = { 0 };
struct reftable_log_record log_dest = { 0 };
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
/* even entries add the refs, odd entries delete them. */
for (i = 0; i < N; i++) {
@@ -770,8 +740,8 @@ static void t_reftable_stack_tombstone(void)
refs[i].update_index = i + 1;
if (i % 2 == 0) {
refs[i].value_type = REFTABLE_REF_VAL1;
- t_reftable_set_hash(refs[i].value.val1, i,
- REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(refs[i].value.val1, i,
+ REFTABLE_HASH_SHA1);
}
logs[i].refname = xstrdup(buf);
@@ -783,42 +753,37 @@ static void t_reftable_stack_tombstone(void)
logs[i].update_index = 1;
if (i % 2 == 0) {
logs[i].value_type = REFTABLE_LOG_UPDATE;
- t_reftable_set_hash(logs[i].value.update.new_hash, i,
- REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
logs[i].value.update.email =
xstrdup("identity@invalid");
}
}
- for (i = 0; i < N; i++) {
- int err = reftable_stack_add(st, write_test_ref, &refs[i]);
- check(!err);
- }
+ for (i = 0; i < N; i++)
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
+ &refs[i], 0), 0);
for (i = 0; i < N; i++) {
struct write_log_arg arg = {
.log = &logs[i],
.update_index = reftable_stack_next_update_index(st),
};
- int err = reftable_stack_add(st, write_test_log, &arg);
- check(!err);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
+ &arg, 0), 0);
}
- err = reftable_stack_read_ref(st, "branch", &dest);
- check_int(err, ==, 1);
+ cl_assert_equal_i(reftable_stack_read_ref(st, "branch",
+ &dest), 1);
reftable_ref_record_release(&dest);
- err = reftable_stack_read_log(st, "branch", &log_dest);
- check_int(err, ==, 1);
+ cl_assert_equal_i(reftable_stack_read_log(st, "branch",
+ &log_dest), 1);
reftable_log_record_release(&log_dest);
- err = reftable_stack_compact_all(st, NULL);
- check(!err);
-
- err = reftable_stack_read_ref(st, "branch", &dest);
- check_int(err, ==, 1);
-
- err = reftable_stack_read_log(st, "branch", &log_dest);
- check_int(err, ==, 1);
+ cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
+ cl_assert_equal_i(reftable_stack_read_ref(st, "branch",
+ &dest), 1);
+ cl_assert_equal_i(reftable_stack_read_log(st, "branch",
+ &log_dest), 1);
reftable_ref_record_release(&dest);
reftable_log_record_release(&log_dest);
@@ -831,12 +796,11 @@ static void t_reftable_stack_tombstone(void)
clear_dir(dir);
}
-static void t_reftable_stack_hash_id(void)
+void test_reftable_stack__hash_id(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
- int err;
struct reftable_ref_record ref = {
.refname = (char *) "master",
@@ -850,62 +814,57 @@ static void t_reftable_stack_hash_id(void)
struct reftable_stack *st_default = NULL;
struct reftable_ref_record dest = { 0 };
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
-
- err = reftable_stack_add(st, write_test_ref, &ref);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
+ &ref, 0), 0);
/* can't read it with the wrong hash ID. */
- err = reftable_new_stack(&st32, dir, &opts32);
- check_int(err, ==, REFTABLE_FORMAT_ERROR);
+ cl_assert_equal_i(reftable_new_stack(&st32, dir,
+ &opts32), REFTABLE_FORMAT_ERROR);
/* check that we can read it back with default opts too. */
- err = reftable_new_stack(&st_default, dir, &opts_default);
- check(!err);
-
- err = reftable_stack_read_ref(st_default, "master", &dest);
- check(!err);
-
- check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
+ cl_assert_equal_i(reftable_new_stack(&st_default, dir,
+ &opts_default), 0);
+ cl_assert_equal_i(reftable_stack_read_ref(st_default, "master",
+ &dest), 0);
+ cl_assert(reftable_ref_record_equal(&ref, &dest,
+ REFTABLE_HASH_SIZE_SHA1) != 0);
reftable_ref_record_release(&dest);
reftable_stack_destroy(st);
reftable_stack_destroy(st_default);
clear_dir(dir);
}
-static void t_suggest_compaction_segment(void)
+void test_reftable_stack__suggest_compaction_segment(void)
{
uint64_t sizes[] = { 512, 64, 17, 16, 9, 9, 9, 16, 2, 16 };
struct segment min =
suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2);
- check_int(min.start, ==, 1);
- check_int(min.end, ==, 10);
+ cl_assert_equal_i(min.start, 1);
+ cl_assert_equal_i(min.end, 10);
}
-static void t_suggest_compaction_segment_nothing(void)
+void test_reftable_stack__suggest_compaction_segment_nothing(void)
{
uint64_t sizes[] = { 64, 32, 16, 8, 4, 2 };
struct segment result =
suggest_compaction_segment(sizes, ARRAY_SIZE(sizes), 2);
- check_int(result.start, ==, result.end);
+ cl_assert_equal_i(result.start, result.end);
}
-static void t_reflog_expire(void)
+void test_reftable_stack__reflog_expire(void)
{
char *dir = get_tmp_dir(__LINE__);
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
struct reftable_log_record logs[20] = { 0 };
size_t i, N = ARRAY_SIZE(logs) - 1;
- int err;
struct reftable_log_expiry_config expiry = {
.time = 10,
};
struct reftable_log_record log = { 0 };
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
for (i = 1; i <= N; i++) {
char buf[256];
@@ -916,8 +875,8 @@ static void t_reflog_expire(void)
logs[i].value_type = REFTABLE_LOG_UPDATE;
logs[i].value.update.time = i;
logs[i].value.update.email = xstrdup("identity@invalid");
- t_reftable_set_hash(logs[i].value.update.new_hash, i,
- REFTABLE_HASH_SHA1);
+ cl_reftable_set_hash(logs[i].value.update.new_hash, i,
+ REFTABLE_HASH_SHA1);
}
for (i = 1; i <= N; i++) {
@@ -925,31 +884,23 @@ static void t_reflog_expire(void)
.log = &logs[i],
.update_index = reftable_stack_next_update_index(st),
};
- int err = reftable_stack_add(st, write_test_log, &arg);
- check(!err);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_log,
+ &arg, 0), 0);
}
- err = reftable_stack_compact_all(st, NULL);
- check(!err);
-
- err = reftable_stack_compact_all(st, &expiry);
- check(!err);
-
- err = reftable_stack_read_log(st, logs[9].refname, &log);
- check_int(err, ==, 1);
-
- err = reftable_stack_read_log(st, logs[11].refname, &log);
- check(!err);
+ cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
+ cl_assert_equal_i(reftable_stack_compact_all(st, &expiry), 0);
+ cl_assert_equal_i(reftable_stack_read_log(st, logs[9].refname,
+ &log), 1);
+ cl_assert_equal_i(reftable_stack_read_log(st, logs[11].refname,
+ &log), 0);
expiry.min_update_index = 15;
- err = reftable_stack_compact_all(st, &expiry);
- check(!err);
-
- err = reftable_stack_read_log(st, logs[14].refname, &log);
- check_int(err, ==, 1);
-
- err = reftable_stack_read_log(st, logs[16].refname, &log);
- check(!err);
+ cl_assert_equal_i(reftable_stack_compact_all(st, &expiry), 0);
+ cl_assert_equal_i(reftable_stack_read_log(st, logs[14].refname,
+ &log), 1);
+ cl_assert_equal_i(reftable_stack_read_log(st, logs[16].refname,
+ &log), 0);
/* cleanup */
reftable_stack_destroy(st);
@@ -961,26 +912,21 @@ static void t_reflog_expire(void)
static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
{
- reftable_writer_set_limits(wr, 1, 1);
+ cl_assert_equal_i(reftable_writer_set_limits(wr, 1, 1), 0);
return 0;
}
-static void t_empty_add(void)
+void test_reftable_stack__empty_add(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
- int err;
char *dir = get_tmp_dir(__LINE__);
struct reftable_stack *st2 = NULL;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
-
- err = reftable_stack_add(st, write_nothing, NULL);
- check(!err);
-
- err = reftable_new_stack(&st2, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
+ cl_assert_equal_i(reftable_stack_add(st, write_nothing,
+ NULL, 0), 0);
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
clear_dir(dir);
reftable_stack_destroy(st);
reftable_stack_destroy(st2);
@@ -996,18 +942,17 @@ static int fastlogN(uint64_t sz, uint64_t N)
return l - 1;
}
-static void t_reftable_stack_auto_compaction(void)
+void test_reftable_stack__auto_compaction(void)
{
struct reftable_write_options opts = {
.disable_auto_compact = 1,
};
struct reftable_stack *st = NULL;
char *dir = get_tmp_dir(__LINE__);
- int err;
size_t i, N = 100;
+ int err;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
for (i = 0; i < N; i++) {
char name[100];
@@ -1019,33 +964,32 @@ static void t_reftable_stack_auto_compaction(void)
};
snprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
- err = reftable_stack_add(st, write_test_ref, &ref);
- check(!err);
+ err = reftable_stack_add(st, write_test_ref, &ref, 0);
+ cl_assert(!err);
err = reftable_stack_auto_compact(st);
- check(!err);
- check(i < 2 || st->merged->readers_len < 2 * fastlogN(i, 2));
+ cl_assert(!err);
+ cl_assert(i < 2 || st->merged->tables_len < 2 * fastlogN(i, 2));
}
- check_int(reftable_stack_compaction_stats(st)->entries_written, <,
- (uint64_t)(N * fastlogN(N, 2)));
+ cl_assert(reftable_stack_compaction_stats(st)->entries_written <
+ (uint64_t)(N * fastlogN(N, 2)));
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void t_reftable_stack_auto_compaction_factor(void)
+void test_reftable_stack__auto_compaction_factor(void)
{
struct reftable_write_options opts = {
.auto_compaction_factor = 5,
};
struct reftable_stack *st = NULL;
char *dir = get_tmp_dir(__LINE__);
- int err;
size_t N = 100;
+ int err;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
for (size_t i = 0; i < N; i++) {
char name[20];
@@ -1056,17 +1000,17 @@ static void t_reftable_stack_auto_compaction_factor(void)
};
xsnprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
- err = reftable_stack_add(st, &write_test_ref, &ref);
- check(!err);
+ err = reftable_stack_add(st, &write_test_ref, &ref, 0);
+ cl_assert(!err);
- check(i < 5 || st->merged->readers_len < 5 * fastlogN(i, 5));
+ cl_assert(i < 5 || st->merged->tables_len < 5 * fastlogN(i, 5));
}
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void t_reftable_stack_auto_compaction_with_locked_tables(void)
+void test_reftable_stack__auto_compaction_with_locked_tables(void)
{
struct reftable_write_options opts = {
.disable_auto_compact = 1,
@@ -1076,21 +1020,20 @@ static void t_reftable_stack_auto_compaction_with_locked_tables(void)
char *dir = get_tmp_dir(__LINE__);
int err;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
write_n_ref_tables(st, 5);
- check_int(st->merged->readers_len, ==, 5);
+ cl_assert_equal_i(st->merged->tables_len, 5);
/*
* Given that all tables we have written should be roughly the same
* size, we expect that auto-compaction will want to compact all of the
* tables. Locking any of the tables will keep it from doing so.
*/
- check(!reftable_buf_addstr(&buf, dir));
- check(!reftable_buf_addstr(&buf, "/"));
- check(!reftable_buf_addstr(&buf, st->readers[2]->name));
- check(!reftable_buf_addstr(&buf, ".lock"));
+ cl_assert(!reftable_buf_addstr(&buf, dir));
+ cl_assert(!reftable_buf_addstr(&buf, "/"));
+ cl_assert(!reftable_buf_addstr(&buf, st->tables[2]->name));
+ cl_assert(!reftable_buf_addstr(&buf, ".lock"));
write_file_buf(buf.buf, "", 0);
/*
@@ -1100,25 +1043,23 @@ static void t_reftable_stack_auto_compaction_with_locked_tables(void)
* only compact the newest two tables.
*/
err = reftable_stack_auto_compact(st);
- check(!err);
- check_int(st->stats.failures, ==, 0);
- check_int(st->merged->readers_len, ==, 4);
+ cl_assert(!err);
+ cl_assert_equal_i(st->stats.failures, 0);
+ cl_assert_equal_i(st->merged->tables_len, 4);
reftable_stack_destroy(st);
reftable_buf_release(&buf);
clear_dir(dir);
}
-static void t_reftable_stack_add_performs_auto_compaction(void)
+void test_reftable_stack__add_performs_auto_compaction(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
char *dir = get_tmp_dir(__LINE__);
- int err;
size_t i, n = 20;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
for (i = 0; i <= n; i++) {
struct reftable_ref_record ref = {
@@ -1138,8 +1079,8 @@ static void t_reftable_stack_add_performs_auto_compaction(void)
snprintf(buf, sizeof(buf), "branch-%04"PRIuMAX, (uintmax_t)i);
ref.refname = buf;
- err = reftable_stack_add(st, write_test_ref, &ref);
- check(!err);
+ cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
+ &ref, 0), 0);
/*
* The stack length should grow continuously for all runs where
@@ -1147,16 +1088,16 @@ static void t_reftable_stack_add_performs_auto_compaction(void)
* all tables in the stack.
*/
if (i != n)
- check_int(st->merged->readers_len, ==, i + 1);
+ cl_assert_equal_i(st->merged->tables_len, i + 1);
else
- check_int(st->merged->readers_len, ==, 1);
+ cl_assert_equal_i(st->merged->tables_len, 1);
}
reftable_stack_destroy(st);
clear_dir(dir);
}
-static void t_reftable_stack_compaction_with_locked_tables(void)
+void test_reftable_stack__compaction_with_locked_tables(void)
{
struct reftable_write_options opts = {
.disable_auto_compact = 1,
@@ -1166,17 +1107,16 @@ static void t_reftable_stack_compaction_with_locked_tables(void)
char *dir = get_tmp_dir(__LINE__);
int err;
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
write_n_ref_tables(st, 3);
- check_int(st->merged->readers_len, ==, 3);
+ cl_assert_equal_i(st->merged->tables_len, 3);
/* Lock one of the tables that we're about to compact. */
- check(!reftable_buf_addstr(&buf, dir));
- check(!reftable_buf_addstr(&buf, "/"));
- check(!reftable_buf_addstr(&buf, st->readers[1]->name));
- check(!reftable_buf_addstr(&buf, ".lock"));
+ cl_assert(!reftable_buf_addstr(&buf, dir));
+ cl_assert(!reftable_buf_addstr(&buf, "/"));
+ cl_assert(!reftable_buf_addstr(&buf, st->tables[1]->name));
+ cl_assert(!reftable_buf_addstr(&buf, ".lock"));
write_file_buf(buf.buf, "", 0);
/*
@@ -1184,74 +1124,61 @@ static void t_reftable_stack_compaction_with_locked_tables(void)
* compact all tables.
*/
err = reftable_stack_compact_all(st, NULL);
- check_int(err, ==, REFTABLE_LOCK_ERROR);
- check_int(st->stats.failures, ==, 1);
- check_int(st->merged->readers_len, ==, 3);
+ cl_assert_equal_i(err, REFTABLE_LOCK_ERROR);
+ cl_assert_equal_i(st->stats.failures, 1);
+ cl_assert_equal_i(st->merged->tables_len, 3);
reftable_stack_destroy(st);
reftable_buf_release(&buf);
clear_dir(dir);
}
-static void t_reftable_stack_compaction_concurrent(void)
+void test_reftable_stack__compaction_concurrent(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st1 = NULL, *st2 = NULL;
char *dir = get_tmp_dir(__LINE__);
- int err;
- err = reftable_new_stack(&st1, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
write_n_ref_tables(st1, 3);
- err = reftable_new_stack(&st2, dir, &opts);
- check(!err);
-
- err = reftable_stack_compact_all(st1, NULL);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
+ cl_assert_equal_i(reftable_stack_compact_all(st1, NULL), 0);
reftable_stack_destroy(st1);
reftable_stack_destroy(st2);
- check_int(count_dir_entries(dir), ==, 2);
+ cl_assert_equal_i(count_dir_entries(dir), 2);
clear_dir(dir);
}
static void unclean_stack_close(struct reftable_stack *st)
{
/* break abstraction boundary to simulate unclean shutdown. */
- for (size_t i = 0; i < st->readers_len; i++)
- reftable_reader_decref(st->readers[i]);
- st->readers_len = 0;
- REFTABLE_FREE_AND_NULL(st->readers);
+ for (size_t i = 0; i < st->tables_len; i++)
+ reftable_table_decref(st->tables[i]);
+ st->tables_len = 0;
+ REFTABLE_FREE_AND_NULL(st->tables);
}
-static void t_reftable_stack_compaction_concurrent_clean(void)
+void test_reftable_stack__compaction_concurrent_clean(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st1 = NULL, *st2 = NULL, *st3 = NULL;
char *dir = get_tmp_dir(__LINE__);
- int err;
- err = reftable_new_stack(&st1, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
write_n_ref_tables(st1, 3);
- err = reftable_new_stack(&st2, dir, &opts);
- check(!err);
-
- err = reftable_stack_compact_all(st1, NULL);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
+ cl_assert_equal_i(reftable_stack_compact_all(st1, NULL), 0);
unclean_stack_close(st1);
unclean_stack_close(st2);
- err = reftable_new_stack(&st3, dir, &opts);
- check(!err);
-
- err = reftable_stack_clean(st3);
- check(!err);
- check_int(count_dir_entries(dir), ==, 2);
+ cl_assert_equal_i(reftable_new_stack(&st3, dir, &opts), 0);
+ cl_assert_equal_i(reftable_stack_clean(st3), 0);
+ cl_assert_equal_i(count_dir_entries(dir), 2);
reftable_stack_destroy(st1);
reftable_stack_destroy(st2);
@@ -1260,7 +1187,7 @@ static void t_reftable_stack_compaction_concurrent_clean(void)
clear_dir(dir);
}
-static void t_reftable_stack_read_across_reload(void)
+void test_reftable_stack__read_across_reload(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st1 = NULL, *st2 = NULL;
@@ -1270,37 +1197,35 @@ static void t_reftable_stack_read_across_reload(void)
int err;
/* Create a first stack and set up an iterator for it. */
- err = reftable_new_stack(&st1, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
write_n_ref_tables(st1, 2);
- check_int(st1->merged->readers_len, ==, 2);
+ cl_assert_equal_i(st1->merged->tables_len, 2);
reftable_stack_init_ref_iterator(st1, &it);
- err = reftable_iterator_seek_ref(&it, "");
- check(!err);
+ cl_assert_equal_i(reftable_iterator_seek_ref(&it, ""), 0);
/* Set up a second stack for the same directory and compact it. */
err = reftable_new_stack(&st2, dir, &opts);
- check(!err);
- check_int(st2->merged->readers_len, ==, 2);
+ cl_assert(!err);
+ cl_assert_equal_i(st2->merged->tables_len, 2);
err = reftable_stack_compact_all(st2, NULL);
- check(!err);
- check_int(st2->merged->readers_len, ==, 1);
+ cl_assert(!err);
+ cl_assert_equal_i(st2->merged->tables_len, 1);
/*
* Verify that we can continue to use the old iterator even after we
* have reloaded its stack.
*/
err = reftable_stack_reload(st1);
- check(!err);
- check_int(st1->merged->readers_len, ==, 1);
+ cl_assert(!err);
+ cl_assert_equal_i(st1->merged->tables_len, 1);
err = reftable_iterator_next_ref(&it, &rec);
- check(!err);
- check_str(rec.refname, "refs/heads/branch-0000");
+ cl_assert(!err);
+ cl_assert_equal_s(rec.refname, "refs/heads/branch-0000");
err = reftable_iterator_next_ref(&it, &rec);
- check(!err);
- check_str(rec.refname, "refs/heads/branch-0001");
+ cl_assert(!err);
+ cl_assert_equal_s(rec.refname, "refs/heads/branch-0001");
err = reftable_iterator_next_ref(&it, &rec);
- check_int(err, >, 0);
+ cl_assert(err > 0);
reftable_ref_record_release(&rec);
reftable_iterator_destroy(&it);
@@ -1309,7 +1234,7 @@ static void t_reftable_stack_read_across_reload(void)
clear_dir(dir);
}
-static void t_reftable_stack_reload_with_missing_table(void)
+void test_reftable_stack__reload_with_missing_table(void)
{
struct reftable_write_options opts = { 0 };
struct reftable_stack *st = NULL;
@@ -1320,46 +1245,40 @@ static void t_reftable_stack_reload_with_missing_table(void)
int err;
/* Create a first stack and set up an iterator for it. */
- err = reftable_new_stack(&st, dir, &opts);
- check(!err);
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
write_n_ref_tables(st, 2);
- check_int(st->merged->readers_len, ==, 2);
+ cl_assert_equal_i(st->merged->tables_len, 2);
reftable_stack_init_ref_iterator(st, &it);
- err = reftable_iterator_seek_ref(&it, "");
- check(!err);
+ cl_assert_equal_i(reftable_iterator_seek_ref(&it, ""), 0);
/*
* Update the tables.list file with some garbage data, while reusing
- * our old readers. This should trigger a partial reload of the stack,
- * where we try to reuse our old readers.
+ * our old tables. This should trigger a partial reload of the stack,
+ * where we try to reuse our old tables.
*/
- check(!reftable_buf_addstr(&content, st->readers[0]->name));
- check(!reftable_buf_addstr(&content, "\n"));
- check(!reftable_buf_addstr(&content, st->readers[1]->name));
- check(!reftable_buf_addstr(&content, "\n"));
- check(!reftable_buf_addstr(&content, "garbage\n"));
- check(!reftable_buf_addstr(&table_path, st->list_file));
- check(!reftable_buf_addstr(&table_path, ".lock"));
+ cl_assert(!reftable_buf_addstr(&content, st->tables[0]->name));
+ cl_assert(!reftable_buf_addstr(&content, "\n"));
+ cl_assert(!reftable_buf_addstr(&content, st->tables[1]->name));
+ cl_assert(!reftable_buf_addstr(&content, "\n"));
+ cl_assert(!reftable_buf_addstr(&content, "garbage\n"));
+ cl_assert(!reftable_buf_addstr(&table_path, st->list_file));
+ cl_assert(!reftable_buf_addstr(&table_path, ".lock"));
write_file_buf(table_path.buf, content.buf, content.len);
- err = rename(table_path.buf, st->list_file);
- check(!err);
+ cl_assert_equal_i(rename(table_path.buf, st->list_file), 0);
err = reftable_stack_reload(st);
- check_int(err, ==, -4);
- check_int(st->merged->readers_len, ==, 2);
+ cl_assert_equal_i(err, -4);
+ cl_assert_equal_i(st->merged->tables_len, 2);
/*
* Even though the reload has failed, we should be able to continue
* using the iterator.
*/
- err = reftable_iterator_next_ref(&it, &rec);
- check(!err);
- check_str(rec.refname, "refs/heads/branch-0000");
- err = reftable_iterator_next_ref(&it, &rec);
- check(!err);
- check_str(rec.refname, "refs/heads/branch-0001");
- err = reftable_iterator_next_ref(&it, &rec);
- check_int(err, >, 0);
+ cl_assert_equal_i(reftable_iterator_next_ref(&it, &rec), 0);
+ cl_assert_equal_s(rec.refname, "refs/heads/branch-0000");
+ cl_assert_equal_i(reftable_iterator_next_ref(&it, &rec), 0);
+ cl_assert_equal_s(rec.refname, "refs/heads/branch-0001");
+ cl_assert(reftable_iterator_next_ref(&it, &rec) > 0);
reftable_ref_record_release(&rec);
reftable_iterator_destroy(&it);
@@ -1369,35 +1288,45 @@ static void t_reftable_stack_reload_with_missing_table(void)
clear_dir(dir);
}
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
+static int write_limits_after_ref(struct reftable_writer *wr, void *arg)
+{
+ struct reftable_ref_record *ref = arg;
+ cl_assert_equal_i(reftable_writer_set_limits(wr,
+ ref->update_index, ref->update_index), 0);
+ cl_assert_equal_i(reftable_writer_add_ref(wr, ref), 0);
+ return reftable_writer_set_limits(wr, ref->update_index, ref->update_index);
+}
+
+void test_reftable_stack__invalid_limit_updates(void)
{
- TEST(t_empty_add(), "empty addition to stack");
- TEST(t_read_file(), "read_lines works");
- TEST(t_reflog_expire(), "expire reflog entries");
- TEST(t_reftable_stack_add(), "add multiple refs and logs to stack");
- TEST(t_reftable_stack_add_one(), "add a single ref record to stack");
- TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction");
- TEST(t_reftable_stack_auto_compaction(), "stack must form geometric sequence after compaction");
- TEST(t_reftable_stack_auto_compaction_factor(), "auto-compaction with non-default geometric factor");
- TEST(t_reftable_stack_auto_compaction_fails_gracefully(), "failure on auto-compaction");
- TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables");
- TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack");
- TEST(t_reftable_stack_compaction_concurrent_clean(), "compaction with unclean stack shutdown");
- TEST(t_reftable_stack_compaction_with_locked_tables(), "compaction with locked tables");
- TEST(t_reftable_stack_hash_id(), "read stack with wrong hash ID");
- TEST(t_reftable_stack_iterator(), "log and ref iterator for reftable stack");
- TEST(t_reftable_stack_lock_failure(), "stack addition with lockfile failure");
- TEST(t_reftable_stack_log_normalize(), "log messages should be normalized");
- TEST(t_reftable_stack_read_across_reload(), "stack iterators work across reloads");
- TEST(t_reftable_stack_reload_with_missing_table(), "stack iteration with garbage tables");
- TEST(t_reftable_stack_tombstone(), "'tombstone' refs in stack");
- TEST(t_reftable_stack_transaction_api(), "update transaction to stack");
- TEST(t_reftable_stack_transaction_with_reload(), "transaction with reload");
- TEST(t_reftable_stack_transaction_api_performs_auto_compaction(), "update transaction triggers auto-compaction");
- TEST(t_reftable_stack_update_index_check(), "update transactions with equal update indices");
- TEST(t_reftable_stack_uptodate(), "stack must be reloaded before ref update");
- TEST(t_suggest_compaction_segment(), "suggest_compaction_segment with basic input");
- TEST(t_suggest_compaction_segment_nothing(), "suggest_compaction_segment with pre-compacted input");
-
- return test_done();
+ struct reftable_ref_record ref = {
+ .refname = (char *) "HEAD",
+ .update_index = 1,
+ .value_type = REFTABLE_REF_SYMREF,
+ .value.symref = (char *) "master",
+ };
+ struct reftable_write_options opts = {
+ .default_permissions = 0660,
+ };
+ struct reftable_addition *add = NULL;
+ char *dir = get_tmp_dir(__LINE__);
+ struct reftable_stack *st = NULL;
+
+ cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
+
+ reftable_addition_destroy(add);
+
+ cl_assert_equal_i(reftable_stack_new_addition(&add, st, 0), 0);
+
+ /*
+ * write_limits_after_ref also updates the update indexes after adding
+ * the record. This should cause an err to be returned, since the limits
+ * must be set at the start.
+ */
+ cl_assert_equal_i(reftable_addition_add(add,
+ write_limits_after_ref, &ref), REFTABLE_API_ERROR);
+
+ reftable_addition_destroy(add);
+ reftable_stack_destroy(st);
+ clear_dir(dir);
}
diff --git a/t/unit-tests/u-reftable-table.c b/t/unit-tests/u-reftable-table.c
new file mode 100644
index 0000000000..14fae8b199
--- /dev/null
+++ b/t/unit-tests/u-reftable-table.c
@@ -0,0 +1,201 @@
+#include "unit-test.h"
+#include "lib-reftable.h"
+#include "reftable/blocksource.h"
+#include "reftable/constants.h"
+#include "reftable/iter.h"
+#include "reftable/table.h"
+#include "strbuf.h"
+
+void test_reftable_table__seek_once(void)
+{
+ struct reftable_ref_record records[] = {
+ {
+ .refname = (char *) "refs/heads/main",
+ .value_type = REFTABLE_REF_VAL1,
+ .value.val1 = { 42 },
+ },
+ };
+ struct reftable_block_source source = { 0 };
+ struct reftable_ref_record ref = { 0 };
+ struct reftable_iterator it = { 0 };
+ struct reftable_table *table;
+ struct reftable_buf buf = REFTABLE_BUF_INIT;
+ int ret;
+
+ cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
+ block_source_from_buf(&source, &buf);
+
+ ret = reftable_table_new(&table, &source, "name");
+ cl_assert(!ret);
+
+ reftable_table_init_ref_iterator(table, &it);
+ ret = reftable_iterator_seek_ref(&it, "");
+ cl_assert(!ret);
+ ret = reftable_iterator_next_ref(&it, &ref);
+ cl_assert(!ret);
+
+ ret = reftable_ref_record_equal(&ref, &records[0],
+ REFTABLE_HASH_SIZE_SHA1);
+ cl_assert_equal_i(ret, 1);
+
+ ret = reftable_iterator_next_ref(&it, &ref);
+ cl_assert_equal_i(ret, 1);
+
+ reftable_ref_record_release(&ref);
+ reftable_iterator_destroy(&it);
+ reftable_table_decref(table);
+ reftable_buf_release(&buf);
+}
+
+void test_reftable_table__reseek(void)
+{
+ struct reftable_ref_record records[] = {
+ {
+ .refname = (char *) "refs/heads/main",
+ .value_type = REFTABLE_REF_VAL1,
+ .value.val1 = { 42 },
+ },
+ };
+ struct reftable_block_source source = { 0 };
+ struct reftable_ref_record ref = { 0 };
+ struct reftable_iterator it = { 0 };
+ struct reftable_table *table;
+ struct reftable_buf buf = REFTABLE_BUF_INIT;
+ int ret;
+
+ cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records),
+ NULL, 0, NULL);
+ block_source_from_buf(&source, &buf);
+
+ ret = reftable_table_new(&table, &source, "name");
+ cl_assert(!ret);
+
+ reftable_table_init_ref_iterator(table, &it);
+
+ for (size_t i = 0; i < 5; i++) {
+ ret = reftable_iterator_seek_ref(&it, "");
+ cl_assert(!ret);
+ ret = reftable_iterator_next_ref(&it, &ref);
+ cl_assert(!ret);
+
+ ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
+ cl_assert_equal_i(ret, 1);
+
+ ret = reftable_iterator_next_ref(&it, &ref);
+ cl_assert_equal_i(ret, 1);
+ }
+
+ reftable_ref_record_release(&ref);
+ reftable_iterator_destroy(&it);
+ reftable_table_decref(table);
+ reftable_buf_release(&buf);
+}
+
+void test_reftable_table__block_iterator(void)
+{
+ struct reftable_block_source source = { 0 };
+ struct reftable_table_iterator it = { 0 };
+ struct reftable_ref_record *records;
+ const struct reftable_block *block;
+ struct reftable_table *table;
+ struct reftable_buf buf = REFTABLE_BUF_INIT;
+ struct {
+ uint8_t block_type;
+ uint16_t header_off;
+ uint16_t restart_count;
+ uint16_t record_count;
+ } expected_blocks[] = {
+ {
+ .block_type = REFTABLE_BLOCK_TYPE_REF,
+ .header_off = 24,
+ .restart_count = 10,
+ .record_count = 158,
+ },
+ {
+ .block_type = REFTABLE_BLOCK_TYPE_REF,
+ .restart_count = 10,
+ .record_count = 159,
+ },
+ {
+ .block_type = REFTABLE_BLOCK_TYPE_REF,
+ .restart_count = 10,
+ .record_count = 159,
+ },
+ {
+ .block_type = REFTABLE_BLOCK_TYPE_REF,
+ .restart_count = 2,
+ .record_count = 24,
+ },
+ {
+ .block_type = REFTABLE_BLOCK_TYPE_INDEX,
+ .restart_count = 1,
+ .record_count = 4,
+ },
+ {
+ .block_type = REFTABLE_BLOCK_TYPE_OBJ,
+ .restart_count = 1,
+ .record_count = 1,
+ },
+ };
+ const size_t nrecords = 500;
+ int ret;
+
+ REFTABLE_CALLOC_ARRAY(records, nrecords);
+ for (size_t i = 0; i < nrecords; i++) {
+ records[i].value_type = REFTABLE_REF_VAL1;
+ records[i].refname = xstrfmt("refs/heads/branch-%03"PRIuMAX,
+ (uintmax_t) i);
+ }
+
+ cl_reftable_write_to_buf(&buf, records, nrecords, NULL, 0, NULL);
+ block_source_from_buf(&source, &buf);
+
+ ret = reftable_table_new(&table, &source, "name");
+ cl_assert(!ret);
+
+ ret = reftable_table_iterator_init(&it, table);
+ cl_assert(!ret);
+
+ for (size_t i = 0; i < ARRAY_SIZE(expected_blocks); i++) {
+ struct reftable_iterator record_it = { 0 };
+ struct reftable_record record = {
+ .type = expected_blocks[i].block_type,
+ };
+
+ ret = reftable_table_iterator_next(&it, &block);
+ cl_assert(!ret);
+
+ cl_assert_equal_i(block->block_type,
+ expected_blocks[i].block_type);
+ cl_assert_equal_i(block->header_off,
+ expected_blocks[i].header_off);
+ cl_assert_equal_i(block->restart_count,
+ expected_blocks[i].restart_count);
+
+ ret = reftable_block_init_iterator(block, &record_it);
+ cl_assert(!ret);
+
+ for (size_t j = 0; ; j++) {
+ ret = iterator_next(&record_it, &record);
+ if (ret > 0) {
+ cl_assert_equal_i(j,
+ expected_blocks[i].record_count);
+ break;
+ }
+ cl_assert(!ret);
+ }
+
+ reftable_iterator_destroy(&record_it);
+ reftable_record_release(&record);
+ }
+
+ ret = reftable_table_iterator_next(&it, &block);
+ cl_assert_equal_i(ret, 1);
+
+ for (size_t i = 0; i < nrecords; i++)
+ reftable_free(records[i].refname);
+ reftable_table_iterator_release(&it);
+ reftable_table_decref(table);
+ reftable_buf_release(&buf);
+ reftable_free(records);
+}
diff --git a/t/unit-tests/t-reftable-tree.c b/t/unit-tests/u-reftable-tree.c
index 79b175a45a..bcf9061071 100644
--- a/t/unit-tests/t-reftable-tree.c
+++ b/t/unit-tests/u-reftable-tree.c
@@ -6,7 +6,7 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
-#include "test-lib.h"
+#include "unit-test.h"
#include "reftable/tree.h"
static int t_compare(const void *a, const void *b)
@@ -25,7 +25,7 @@ static void store(void *arg, void *key)
c->arr[c->len++] = key;
}
-static void t_tree_search(void)
+void test_reftable_tree__tree_search(void)
{
struct tree_node *root = NULL;
void *values[11] = { 0 };
@@ -38,20 +38,20 @@ static void t_tree_search(void)
*/
do {
nodes[i] = tree_insert(&root, &values[i], &t_compare);
- check(nodes[i] != NULL);
+ cl_assert(nodes[i] != NULL);
i = (i * 7) % 11;
} while (i != 1);
for (i = 1; i < ARRAY_SIZE(nodes); i++) {
- check_pointer_eq(&values[i], nodes[i]->key);
- check_pointer_eq(nodes[i], tree_search(root, &values[i], &t_compare));
+ cl_assert_equal_p(&values[i], nodes[i]->key);
+ cl_assert_equal_p(nodes[i], tree_search(root, &values[i], &t_compare));
}
- check(!tree_search(root, values, t_compare));
+ cl_assert(tree_search(root, values, t_compare) == NULL);
tree_free(root);
}
-static void t_infix_walk(void)
+void test_reftable_tree__infix_walk(void)
{
struct tree_node *root = NULL;
void *values[11] = { 0 };
@@ -64,23 +64,15 @@ static void t_infix_walk(void)
do {
struct tree_node *node = tree_insert(&root, &values[i], t_compare);
- check(node != NULL);
+ cl_assert(node != NULL);
i = (i * 7) % 11;
count++;
} while (i != 1);
infix_walk(root, &store, &c);
for (i = 1; i < ARRAY_SIZE(values); i++)
- check_pointer_eq(&values[i], out[i - 1]);
- check(!out[i - 1]);
- check_int(c.len, ==, count);
+ cl_assert_equal_p(&values[i], out[i - 1]);
+ cl_assert(out[i - 1] == NULL);
+ cl_assert_equal_i(c.len, count);
tree_free(root);
}
-
-int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
-{
- TEST(t_tree_search(), "tree_search works");
- TEST(t_infix_walk(), "infix_walk works");
-
- return test_done();
-}
diff --git a/t/unit-tests/u-strbuf.c b/t/unit-tests/u-strbuf.c
new file mode 100644
index 0000000000..caa5d78aa3
--- /dev/null
+++ b/t/unit-tests/u-strbuf.c
@@ -0,0 +1,119 @@
+#include "unit-test.h"
+#include "strbuf.h"
+
+/* wrapper that supplies tests with an empty, initialized strbuf */
+static void setup(void (*f)(struct strbuf*, const void*),
+ const void *data)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ f(&buf, data);
+ strbuf_release(&buf);
+ cl_assert_equal_i(buf.len, 0);
+ cl_assert_equal_i(buf.alloc, 0);
+}
+
+/* wrapper that supplies tests with a populated, initialized strbuf */
+static void setup_populated(void (*f)(struct strbuf*, const void*),
+ const char *init_str, const void *data)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ strbuf_addstr(&buf, init_str);
+ cl_assert_equal_i(buf.len, strlen(init_str));
+ f(&buf, data);
+ strbuf_release(&buf);
+ cl_assert_equal_i(buf.len, 0);
+ cl_assert_equal_i(buf.alloc, 0);
+}
+
+static void assert_sane_strbuf(struct strbuf *buf)
+{
+ /* Initialized strbufs should always have a non-NULL buffer */
+ cl_assert(buf->buf != NULL);
+ /* Buffers should always be NUL-terminated */
+ cl_assert(buf->buf[buf->len] == '\0');
+ /*
+ * In case the buffer contains anything, `alloc` must alloc must
+ * be at least one byte larger than `len`.
+ */
+ if (buf->len)
+ cl_assert(buf->len < buf->alloc);
+}
+
+void test_strbuf__static_init(void)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ cl_assert_equal_i(buf.len, 0);
+ cl_assert_equal_i(buf.alloc, 0);
+ cl_assert(buf.buf[0] == '\0');
+}
+
+void test_strbuf__dynamic_init(void)
+{
+ struct strbuf buf;
+
+ strbuf_init(&buf, 1024);
+ assert_sane_strbuf(&buf);
+ cl_assert_equal_i(buf.len, 0);
+ cl_assert(buf.alloc >= 1024);
+ cl_assert(buf.buf[0] == '\0');
+ strbuf_release(&buf);
+}
+
+static void t_addch(struct strbuf *buf, const void *data)
+{
+ const char *p_ch = data;
+ const char ch = *p_ch;
+ size_t orig_alloc = buf->alloc;
+ size_t orig_len = buf->len;
+
+ assert_sane_strbuf(buf);
+ strbuf_addch(buf, ch);
+ assert_sane_strbuf(buf);
+ cl_assert_equal_i(buf->len, orig_len + 1);
+ cl_assert(buf->alloc >= orig_alloc);
+ cl_assert(buf->buf[buf->len] == '\0');
+}
+
+static void t_addstr(struct strbuf *buf, const void *data)
+{
+ const char *text = data;
+ size_t len = strlen(text);
+ size_t orig_alloc = buf->alloc;
+ size_t orig_len = buf->len;
+
+ assert_sane_strbuf(buf);
+ strbuf_addstr(buf, text);
+ assert_sane_strbuf(buf);
+ cl_assert_equal_i(buf->len, orig_len + len);
+ cl_assert(buf->alloc >= orig_alloc);
+ cl_assert(buf->buf[buf->len] == '\0');
+ cl_assert_equal_s(buf->buf + orig_len, text);
+}
+
+void test_strbuf__add_single_char(void)
+{
+ setup(t_addch, "a");
+}
+
+void test_strbuf__add_empty_char(void)
+{
+ setup(t_addch, "");
+}
+
+void test_strbuf__add_append_char(void)
+{
+ setup_populated(t_addch, "initial value", "a");
+}
+
+void test_strbuf__add_single_str(void)
+{
+ setup(t_addstr, "hello there");
+}
+
+void test_strbuf__add_append_str(void)
+{
+ setup_populated(t_addstr, "initial value", "hello there");
+}
diff --git a/t/unit-tests/u-strcmp-offset.c b/t/unit-tests/u-strcmp-offset.c
new file mode 100644
index 0000000000..7e8e9acf3c
--- /dev/null
+++ b/t/unit-tests/u-strcmp-offset.c
@@ -0,0 +1,45 @@
+#include "unit-test.h"
+#include "read-cache-ll.h"
+
+static void check_strcmp_offset(const char *string1, const char *string2,
+ int expect_result, uintmax_t expect_offset)
+{
+ size_t offset;
+ int result = strcmp_offset(string1, string2, &offset);
+
+ /*
+ * Because different CRTs behave differently, only rely on signs of the
+ * result values.
+ */
+ result = (result < 0 ? -1 :
+ result > 0 ? 1 :
+ 0);
+
+ cl_assert_equal_i(result, expect_result);
+ cl_assert_equal_i((uintmax_t)offset, expect_offset);
+}
+
+void test_strcmp_offset__empty(void)
+{
+ check_strcmp_offset("", "", 0, 0);
+}
+
+void test_strcmp_offset__equal(void)
+{
+ check_strcmp_offset("abc", "abc", 0, 3);
+}
+
+void test_strcmp_offset__different(void)
+{
+ check_strcmp_offset("abc", "def", -1, 0);
+}
+
+void test_strcmp_offset__mismatch(void)
+{
+ check_strcmp_offset("abc", "abz", -1, 2);
+}
+
+void test_strcmp_offset__different_length(void)
+{
+ check_strcmp_offset("abc", "abcdef", -1, 3);
+}
diff --git a/t/unit-tests/u-string-list.c b/t/unit-tests/u-string-list.c
new file mode 100644
index 0000000000..a2457d7b1e
--- /dev/null
+++ b/t/unit-tests/u-string-list.c
@@ -0,0 +1,306 @@
+#include "unit-test.h"
+#include "string-list.h"
+
+static void t_vcreate_string_list_dup(struct string_list *list,
+ int free_util, va_list ap)
+{
+ const char *arg;
+
+ cl_assert(list->strdup_strings);
+
+ string_list_clear(list, free_util);
+ while ((arg = va_arg(ap, const char *)))
+ string_list_append(list, arg);
+}
+
+static void t_create_string_list_dup(struct string_list *list, int free_util, ...)
+{
+ va_list ap;
+
+ cl_assert(list->strdup_strings);
+
+ string_list_clear(list, free_util);
+ va_start(ap, free_util);
+ t_vcreate_string_list_dup(list, free_util, ap);
+ va_end(ap);
+}
+
+static void t_string_list_clear(struct string_list *list, int free_util)
+{
+ string_list_clear(list, free_util);
+ cl_assert_equal_p(list->items, NULL);
+ cl_assert_equal_i(list->nr, 0);
+ cl_assert_equal_i(list->alloc, 0);
+}
+
+static void t_string_list_equal(struct string_list *list,
+ struct string_list *expected_strings)
+{
+ cl_assert_equal_i(list->nr, expected_strings->nr);
+ cl_assert(list->nr <= list->alloc);
+ for (size_t i = 0; i < expected_strings->nr; i++)
+ cl_assert_equal_s(list->items[i].string,
+ expected_strings->items[i].string);
+}
+
+static void t_string_list_split(const char *data, const char *delim, int maxsplit, ...)
+{
+ struct string_list expected_strings = STRING_LIST_INIT_DUP;
+ struct string_list list = STRING_LIST_INIT_DUP;
+ va_list ap;
+ int len;
+
+ va_start(ap, maxsplit);
+ t_vcreate_string_list_dup(&expected_strings, 0, ap);
+ va_end(ap);
+
+ string_list_clear(&list, 0);
+ len = string_list_split(&list, data, delim, maxsplit);
+ cl_assert_equal_i(len, expected_strings.nr);
+ t_string_list_equal(&list, &expected_strings);
+
+ string_list_clear(&expected_strings, 0);
+ string_list_clear(&list, 0);
+}
+
+static void t_string_list_split_f(const char *data, const char *delim,
+ int maxsplit, unsigned flags, ...)
+{
+ struct string_list expected_strings = STRING_LIST_INIT_DUP;
+ struct string_list list = STRING_LIST_INIT_DUP;
+ va_list ap;
+ int len;
+
+ va_start(ap, flags);
+ t_vcreate_string_list_dup(&expected_strings, 0, ap);
+ va_end(ap);
+
+ string_list_clear(&list, 0);
+ len = string_list_split_f(&list, data, delim, maxsplit, flags);
+ cl_assert_equal_i(len, expected_strings.nr);
+ t_string_list_equal(&list, &expected_strings);
+
+ string_list_clear(&expected_strings, 0);
+ string_list_clear(&list, 0);
+}
+
+void test_string_list__split_f(void)
+{
+ t_string_list_split_f("::foo:bar:baz:", ":", -1, 0,
+ "", "", "foo", "bar", "baz", "", NULL);
+ t_string_list_split_f(" foo:bar : baz", ":", -1, STRING_LIST_SPLIT_TRIM,
+ "foo", "bar", "baz", NULL);
+ t_string_list_split_f(" a b c ", " ", 1, STRING_LIST_SPLIT_TRIM,
+ "a", "b c", NULL);
+ t_string_list_split_f("::foo::bar:baz:", ":", -1, STRING_LIST_SPLIT_NONEMPTY,
+ "foo", "bar", "baz", NULL);
+ t_string_list_split_f("foo:baz", ":", -1, STRING_LIST_SPLIT_NONEMPTY,
+ "foo", "baz", NULL);
+ t_string_list_split_f("foo :: : baz", ":", -1,
+ STRING_LIST_SPLIT_NONEMPTY | STRING_LIST_SPLIT_TRIM,
+ "foo", "baz", NULL);
+}
+
+static void t_string_list_split_in_place_f(const char *data_, const char *delim,
+ int maxsplit, unsigned flags, ...)
+{
+ struct string_list expected_strings = STRING_LIST_INIT_DUP;
+ struct string_list list = STRING_LIST_INIT_NODUP;
+ char *data = xstrdup(data_);
+ va_list ap;
+ int len;
+
+ va_start(ap, flags);
+ t_vcreate_string_list_dup(&expected_strings, 0, ap);
+ va_end(ap);
+
+ string_list_clear(&list, 0);
+ len = string_list_split_in_place_f(&list, data, delim, maxsplit, flags);
+ cl_assert_equal_i(len, expected_strings.nr);
+ t_string_list_equal(&list, &expected_strings);
+
+ free(data);
+ string_list_clear(&expected_strings, 0);
+ string_list_clear(&list, 0);
+}
+
+void test_string_list__split_in_place_f(void)
+{
+ t_string_list_split_in_place_f("::foo:bar:baz:", ":", -1, 0,
+ "", "", "foo", "bar", "baz", "", NULL);
+ t_string_list_split_in_place_f(" foo:bar : baz", ":", -1, STRING_LIST_SPLIT_TRIM,
+ "foo", "bar", "baz", NULL);
+ t_string_list_split_in_place_f(" a b c ", " ", 1, STRING_LIST_SPLIT_TRIM,
+ "a", "b c", NULL);
+ t_string_list_split_in_place_f("::foo::bar:baz:", ":", -1,
+ STRING_LIST_SPLIT_NONEMPTY,
+ "foo", "bar", "baz", NULL);
+ t_string_list_split_in_place_f("foo:baz", ":", -1, STRING_LIST_SPLIT_NONEMPTY,
+ "foo", "baz", NULL);
+ t_string_list_split_in_place_f("foo :: : baz", ":", -1,
+ STRING_LIST_SPLIT_NONEMPTY | STRING_LIST_SPLIT_TRIM,
+ "foo", "baz", NULL);
+}
+
+void test_string_list__split(void)
+{
+ t_string_list_split("foo:bar:baz", ":", -1, "foo", "bar", "baz", NULL);
+ t_string_list_split("foo:bar:baz", ":", 0, "foo:bar:baz", NULL);
+ t_string_list_split("foo:bar:baz", ":", 1, "foo", "bar:baz", NULL);
+ t_string_list_split("foo:bar:baz", ":", 2, "foo", "bar", "baz", NULL);
+ t_string_list_split("foo:bar:", ":", -1, "foo", "bar", "", NULL);
+ t_string_list_split("", ":", -1, "", NULL);
+ t_string_list_split(":", ":", -1, "", "", NULL);
+}
+
+static void t_string_list_split_in_place(const char *data, const char *delim,
+ int maxsplit, ...)
+{
+ struct string_list expected_strings = STRING_LIST_INIT_DUP;
+ struct string_list list = STRING_LIST_INIT_NODUP;
+ char *string = xstrdup(data);
+ va_list ap;
+ int len;
+
+ va_start(ap, maxsplit);
+ t_vcreate_string_list_dup(&expected_strings, 0, ap);
+ va_end(ap);
+
+ string_list_clear(&list, 0);
+ len = string_list_split_in_place(&list, string, delim, maxsplit);
+ cl_assert_equal_i(len, expected_strings.nr);
+ t_string_list_equal(&list, &expected_strings);
+
+ free(string);
+ string_list_clear(&expected_strings, 0);
+ string_list_clear(&list, 0);
+}
+
+void test_string_list__split_in_place(void)
+{
+ t_string_list_split_in_place("foo:;:bar:;:baz:;:", ":;", -1,
+ "foo", "", "", "bar", "", "", "baz", "", "", "", NULL);
+ t_string_list_split_in_place("foo:;:bar:;:baz", ":;", 0,
+ "foo:;:bar:;:baz", NULL);
+ t_string_list_split_in_place("foo:;:bar:;:baz", ":;", 1,
+ "foo", ";:bar:;:baz", NULL);
+ t_string_list_split_in_place("foo:;:bar:;:baz", ":;", 2,
+ "foo", "", ":bar:;:baz", NULL);
+ t_string_list_split_in_place("foo:;:bar:;:", ":;", -1,
+ "foo", "", "", "bar", "", "", "", NULL);
+}
+
+static int prefix_cb(struct string_list_item *item, void *cb_data)
+{
+ const char *prefix = (const char *)cb_data;
+ return starts_with(item->string, prefix);
+}
+
+static void t_string_list_filter(struct string_list *list, ...)
+{
+ struct string_list expected_strings = STRING_LIST_INIT_DUP;
+ const char *prefix = "y";
+ va_list ap;
+
+ va_start(ap, list);
+ t_vcreate_string_list_dup(&expected_strings, 0, ap);
+ va_end(ap);
+
+ filter_string_list(list, 0, prefix_cb, (void *)prefix);
+ t_string_list_equal(list, &expected_strings);
+
+ string_list_clear(&expected_strings, 0);
+}
+
+void test_string_list__filter(void)
+{
+ struct string_list list = STRING_LIST_INIT_DUP;
+
+ t_create_string_list_dup(&list, 0, NULL);
+ t_string_list_filter(&list, NULL);
+
+ t_create_string_list_dup(&list, 0, "no", NULL);
+ t_string_list_filter(&list, NULL);
+
+ t_create_string_list_dup(&list, 0, "yes", NULL);
+ t_string_list_filter(&list, "yes", NULL);
+
+ t_create_string_list_dup(&list, 0, "no", "yes", NULL);
+ t_string_list_filter(&list, "yes", NULL);
+
+ t_create_string_list_dup(&list, 0, "yes", "no", NULL);
+ t_string_list_filter(&list, "yes", NULL);
+
+ t_create_string_list_dup(&list, 0, "y1", "y2", NULL);
+ t_string_list_filter(&list, "y1", "y2", NULL);
+
+ t_create_string_list_dup(&list, 0, "y2", "y1", NULL);
+ t_string_list_filter(&list, "y2", "y1", NULL);
+
+ t_create_string_list_dup(&list, 0, "x1", "x2", NULL);
+ t_string_list_filter(&list, NULL);
+
+ t_string_list_clear(&list, 0);
+}
+
+static void t_string_list_remove_duplicates(struct string_list *list, ...)
+{
+ struct string_list expected_strings = STRING_LIST_INIT_DUP;
+ va_list ap;
+
+ va_start(ap, list);
+ t_vcreate_string_list_dup(&expected_strings, 0, ap);
+ va_end(ap);
+
+ string_list_remove_duplicates(list, 0);
+ t_string_list_equal(list, &expected_strings);
+
+ string_list_clear(&expected_strings, 0);
+}
+
+void test_string_list__remove_duplicates(void)
+{
+ struct string_list list = STRING_LIST_INIT_DUP;
+
+ t_create_string_list_dup(&list, 0, NULL);
+ t_string_list_remove_duplicates(&list, NULL);
+
+ t_create_string_list_dup(&list, 0, "", NULL);
+ t_string_list_remove_duplicates(&list, "", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", NULL);
+ t_string_list_remove_duplicates(&list, "a", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "a", NULL);
+ t_string_list_remove_duplicates(&list, "a", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "a", "a", NULL);
+ t_string_list_remove_duplicates(&list, "a", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "a", "b", NULL);
+ t_string_list_remove_duplicates(&list, "a", "b", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "b", "b", NULL);
+ t_string_list_remove_duplicates(&list, "a", "b", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "b", "c", NULL);
+ t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "a", "b", "c", NULL);
+ t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "b", "b", "c", NULL);
+ t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "b", "c", "c", NULL);
+ t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "a", "b", "b", "c", "c", NULL);
+ t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
+
+ t_create_string_list_dup(&list, 0, "a", "a", "a", "b", "b", "b",
+ "c", "c", "c", NULL);
+ t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
+
+ t_string_list_clear(&list, 0);
+}
diff --git a/t/unit-tests/u-trailer.c b/t/unit-tests/u-trailer.c
new file mode 100644
index 0000000000..3d60ea1603
--- /dev/null
+++ b/t/unit-tests/u-trailer.c
@@ -0,0 +1,320 @@
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
+#include "unit-test.h"
+#include "trailer.h"
+
+struct contents {
+ const char *raw;
+ const char *key;
+ const char *val;
+};
+
+static void t_trailer_iterator(const char *msg, size_t num_expected,
+ struct contents *contents)
+{
+ struct trailer_iterator iter;
+ size_t i = 0;
+
+ trailer_iterator_init(&iter, msg);
+ while (trailer_iterator_advance(&iter)) {
+ if (num_expected) {
+ cl_assert_equal_s(iter.raw, contents[i].raw);
+ cl_assert_equal_s(iter.key.buf, contents[i].key);
+ cl_assert_equal_s(iter.val.buf, contents[i].val);
+ }
+ i++;
+ }
+ trailer_iterator_release(&iter);
+
+ cl_assert_equal_i(i, num_expected);
+}
+
+void test_trailer__empty_input(void)
+{
+ struct contents expected_contents[] = { 0 };
+ t_trailer_iterator("", 0, expected_contents);
+}
+
+void test_trailer__no_newline_start(void)
+{
+ struct contents expected_contents[] = { 0 };
+
+ t_trailer_iterator("Fixes: x\n"
+ "Acked-by: x\n"
+ "Reviewed-by: x\n",
+ 0,
+ expected_contents);
+}
+
+void test_trailer__newline_start(void)
+{
+ struct contents expected_contents[] = {
+ {
+ .raw = "Fixes: x\n",
+ .key = "Fixes",
+ .val = "x",
+ },
+ {
+ .raw = "Acked-by: x\n",
+ .key = "Acked-by",
+ .val = "x",
+ },
+ {
+ .raw = "Reviewed-by: x\n",
+ .key = "Reviewed-by",
+ .val = "x",
+ },
+ {
+ 0
+ },
+ };
+
+ t_trailer_iterator("\n"
+ "Fixes: x\n"
+ "Acked-by: x\n"
+ "Reviewed-by: x\n",
+ 3,
+ expected_contents);
+}
+
+void test_trailer__no_body_text(void)
+{
+ struct contents expected_contents[] = {
+
+ {
+ .raw = "Fixes: x\n",
+ .key = "Fixes",
+ .val = "x",
+ },
+ {
+ .raw = "Acked-by: x\n",
+ .key = "Acked-by",
+ .val = "x",
+ },
+ {
+ .raw = "Reviewed-by: x\n",
+ .key = "Reviewed-by",
+ .val = "x",
+ },
+ {
+ 0
+ },
+ };
+
+ t_trailer_iterator("subject: foo bar\n"
+ "\n"
+ "Fixes: x\n"
+ "Acked-by: x\n"
+ "Reviewed-by: x\n",
+ 3,
+ expected_contents);
+}
+
+void test_trailer__body_text_no_divider(void)
+{
+ struct contents expected_contents[] = {
+ {
+ .raw = "Fixes: x\n",
+ .key = "Fixes",
+ .val = "x",
+ },
+ {
+ .raw = "Acked-by: x\n",
+ .key = "Acked-by",
+ .val = "x",
+ },
+ {
+ .raw = "Reviewed-by: x\n",
+ .key = "Reviewed-by",
+ .val = "x",
+ },
+ {
+ .raw = "Signed-off-by: x\n",
+ .key = "Signed-off-by",
+ .val = "x",
+ },
+ {
+ 0
+ },
+ };
+
+ t_trailer_iterator("my subject\n"
+ "\n"
+ "my body which is long\n"
+ "and contains some special\n"
+ "chars like : = ? !\n"
+ "hello\n"
+ "\n"
+ "Fixes: x\n"
+ "Acked-by: x\n"
+ "Reviewed-by: x\n"
+ "Signed-off-by: x\n",
+ 4,
+ expected_contents);
+}
+
+void test_trailer__body_no_divider_2nd_block(void)
+{
+ struct contents expected_contents[] = {
+ {
+ .raw = "Helped-by: x\n",
+ .key = "Helped-by",
+ .val = "x",
+ },
+ {
+ .raw = "Signed-off-by: x\n",
+ .key = "Signed-off-by",
+ .val = "x",
+ },
+ {
+ 0
+ },
+ };
+
+ t_trailer_iterator("my subject\n"
+ "\n"
+ "my body which is long\n"
+ "and contains some special\n"
+ "chars like : = ? !\n"
+ "hello\n"
+ "\n"
+ "Fixes: x\n"
+ "Acked-by: x\n"
+ "Reviewed-by: x\n"
+ "Signed-off-by: x\n"
+ "\n"
+ /*
+ * Because this is the last trailer block, it takes
+ * precedence over the first one encountered above.
+ */
+ "Helped-by: x\n"
+ "Signed-off-by: x\n",
+ 2,
+ expected_contents);
+}
+
+void test_trailer__body_and_divider(void)
+{
+ struct contents expected_contents[] = {
+ {
+ .raw = "Signed-off-by: x\n",
+ .key = "Signed-off-by",
+ .val = "x",
+ },
+ {
+ 0
+ },
+ };
+
+ t_trailer_iterator("my subject\n"
+ "\n"
+ "my body which is long\n"
+ "and contains some special\n"
+ "chars like : = ? !\n"
+ "hello\n"
+ "\n"
+ "---\n"
+ "\n"
+ /*
+ * This trailer still counts because the iterator
+ * always ignores the divider.
+ */
+ "Signed-off-by: x\n",
+ 1,
+ expected_contents);
+}
+
+void test_trailer__non_trailer_in_block(void)
+{
+ struct contents expected_contents[] = {
+ {
+ .raw = "not a trailer line\n",
+ .key = "not a trailer line",
+ .val = "",
+ },
+ {
+ .raw = "not a trailer line\n",
+ .key = "not a trailer line",
+ .val = "",
+ },
+ {
+ .raw = "not a trailer line\n",
+ .key = "not a trailer line",
+ .val = "",
+ },
+ {
+ .raw = "Signed-off-by: x\n",
+ .key = "Signed-off-by",
+ .val = "x",
+ },
+ {
+ 0
+ },
+ };
+
+ t_trailer_iterator("subject: foo bar\n"
+ "\n"
+ /*
+ * Even though this trailer block has a non-trailer line
+ * in it, it's still a valid trailer block because it's
+ * at least 25% trailers and is Git-generated (see
+ * git_generated_prefixes[] in trailer.c).
+ */
+ "not a trailer line\n"
+ "not a trailer line\n"
+ "not a trailer line\n"
+ "Signed-off-by: x\n",
+ /*
+ * Even though there is only really 1 real "trailer"
+ * (Signed-off-by), we still have 4 trailer objects
+ * because we still want to iterate through the entire
+ * block.
+ */
+ 4,
+ expected_contents);
+}
+
+void test_trailer__too_many_non_trailers(void)
+{
+ struct contents expected_contents[] = { 0 };
+
+ t_trailer_iterator("subject: foo bar\n"
+ "\n"
+ /*
+ * This block has only 20% trailers, so it's below the
+ * 25% threshold.
+ */
+ "not a trailer line\n"
+ "not a trailer line\n"
+ "not a trailer line\n"
+ "not a trailer line\n"
+ "Signed-off-by: x\n",
+ 0,
+ expected_contents);
+}
+
+void test_trailer__one_non_trailer_no_git_trailers(void)
+{
+ struct contents expected_contents[] = { 0 };
+
+ t_trailer_iterator("subject: foo bar\n"
+ "\n"
+ /*
+ * This block has only 1 non-trailer out of 10 (IOW, 90%
+ * trailers) but is not considered a trailer block
+ * because the 25% threshold only applies to cases where
+ * there was a Git-generated trailer.
+ */
+ "Reviewed-by: x\n"
+ "Reviewed-by: x\n"
+ "Reviewed-by: x\n"
+ "Helped-by: x\n"
+ "Helped-by: x\n"
+ "Helped-by: x\n"
+ "Acked-by: x\n"
+ "Acked-by: x\n"
+ "Acked-by: x\n"
+ "not a trailer line\n",
+ 0,
+ expected_contents);
+}
diff --git a/t/unit-tests/t-urlmatch-normalization.c b/t/unit-tests/u-urlmatch-normalization.c
index 1769c357b9..39f6e1ba26 100644
--- a/t/unit-tests/t-urlmatch-normalization.c
+++ b/t/unit-tests/u-urlmatch-normalization.c
@@ -1,12 +1,11 @@
-#include "test-lib.h"
+#include "unit-test.h"
#include "urlmatch.h"
static void check_url_normalizable(const char *url, unsigned int normalizable)
{
char *url_norm = url_normalize(url, NULL);
- if (!check_int(normalizable, ==, url_norm ? 1 : 0))
- test_msg("input url: %s", url);
+ cl_assert_equal_i(normalizable, url_norm ? 1 : 0);
free(url_norm);
}
@@ -14,8 +13,7 @@ static void check_normalized_url(const char *url, const char *expect)
{
char *url_norm = url_normalize(url, NULL);
- if (!check_str(url_norm, expect))
- test_msg("input url: %s", url);
+ cl_assert_equal_s(url_norm, expect);
free(url_norm);
}
@@ -26,13 +24,9 @@ static void compare_normalized_urls(const char *url1, const char *url2,
char *url2_norm = url_normalize(url2, NULL);
if (equal) {
- if (!check_str(url1_norm, url2_norm))
- test_msg("input url1: %s\n input url2: %s", url1,
- url2);
- } else if (!check_int(strcmp(url1_norm, url2_norm), !=, 0)) {
- test_msg(" normalized url1: %s\n normalized url2: %s\n"
- " input url1: %s\n input url2: %s",
- url1_norm, url2_norm, url1, url2);
+ cl_assert_equal_s(url1_norm, url2_norm);
+ } else {
+ cl_assert(strcmp(url1_norm, url2_norm) != 0);
}
free(url1_norm);
free(url2_norm);
@@ -43,14 +37,12 @@ static void check_normalized_url_length(const char *url, size_t len)
struct url_info info;
char *url_norm = url_normalize(url, &info);
- if (!check_int(info.url_len, ==, len))
- test_msg(" input url: %s\n normalized url: %s", url,
- url_norm);
+ cl_assert_equal_i(info.url_len, len);
free(url_norm);
}
/* Note that only "file:" URLs should be allowed without a host */
-static void t_url_scheme(void)
+void test_urlmatch_normalization__scheme(void)
{
check_url_normalizable("", 0);
check_url_normalizable("_", 0);
@@ -73,7 +65,7 @@ static void t_url_scheme(void)
check_normalized_url("AbCdeF://x.Y", "abcdef://x.y/");
}
-static void t_url_authority(void)
+void test_urlmatch_normalization__authority(void)
{
check_url_normalizable("scheme://user:pass@", 0);
check_url_normalizable("scheme://?", 0);
@@ -109,7 +101,7 @@ static void t_url_authority(void)
check_url_normalizable("scheme://invalid....:[", 0);
}
-static void t_url_port(void)
+void test_urlmatch_normalization__port(void)
{
check_url_normalizable("xyz://q@some.host:", 1);
check_url_normalizable("xyz://q@some.host:456/", 1);
@@ -139,7 +131,7 @@ static void t_url_port(void)
check_url_normalizable("xyz://[::1]:030f/", 0);
}
-static void t_url_port_normalization(void)
+void test_urlmatch_normalization__port_normalization(void)
{
check_normalized_url("http://x:800", "http://x:800/");
check_normalized_url("http://x:0800", "http://x:800/");
@@ -154,7 +146,7 @@ static void t_url_port_normalization(void)
check_normalized_url("https://x:000000443", "https://x/");
}
-static void t_url_general_escape(void)
+void test_urlmatch_normalization__general_escape(void)
{
check_url_normalizable("http://x.y?%fg", 0);
check_normalized_url("X://W/%7e%41^%3a", "x://w/~A%5E%3A");
@@ -164,7 +156,7 @@ static void t_url_general_escape(void)
check_normalized_url("X://W?!", "x://w/?!");
}
-static void t_url_high_bit(void)
+void test_urlmatch_normalization__high_bit(void)
{
check_normalized_url(
"x://q/\x01\x02\x03\x04\x05\x06\x07\x08\x0e\x0f\x10\x11\x12",
@@ -198,26 +190,26 @@ static void t_url_high_bit(void)
"x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF");
}
-static void t_url_utf8_escape(void)
+void test_urlmatch_normalization__utf8_escape(void)
{
check_normalized_url(
"x://q/\xc2\x80\xdf\xbf\xe0\xa0\x80\xef\xbf\xbd\xf0\x90\x80\x80\xf0\xaf\xbf\xbd",
"x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD");
}
-static void t_url_username_pass(void)
+void test_urlmatch_normalization__username_pass(void)
{
check_normalized_url("x://%41%62(^):%70+d@foo", "x://Ab(%5E):p+d@foo/");
}
-static void t_url_length(void)
+void test_urlmatch_normalization__length(void)
{
check_normalized_url_length("Http://%4d%65:%4d^%70@The.Host", 25);
check_normalized_url_length("http://%41:%42@x.y/%61/", 17);
check_normalized_url_length("http://@x.y/^", 15);
}
-static void t_url_dots(void)
+void test_urlmatch_normalization__dots(void)
{
check_normalized_url("x://y/.", "x://y/");
check_normalized_url("x://y/./", "x://y/");
@@ -244,7 +236,7 @@ static void t_url_dots(void)
* "http://foo" specifies neither a user name nor a password.
* So they should not be equivalent.
*/
-static void t_url_equivalents(void)
+void test_urlmatch_normalization__equivalents(void)
{
compare_normalized_urls("httP://x", "Http://X/", 1);
compare_normalized_urls("Http://%4d%65:%4d^%70@The.Host", "hTTP://Me:%4D^p@the.HOST:80/", 1);
@@ -253,19 +245,3 @@ static void t_url_equivalents(void)
compare_normalized_urls("https://@x.y/^/../abc", "httpS://@x.y:0443/abc", 1);
compare_normalized_urls("https://@x.y/^/..", "httpS://@x.y:0443/", 1);
}
-
-int cmd_main(int argc UNUSED, const char **argv UNUSED)
-{
- TEST(t_url_scheme(), "url scheme");
- TEST(t_url_authority(), "url authority");
- TEST(t_url_port(), "url port checks");
- TEST(t_url_port_normalization(), "url port normalization");
- TEST(t_url_general_escape(), "url general escapes");
- TEST(t_url_high_bit(), "url high-bit escapes");
- TEST(t_url_utf8_escape(), "url utf8 escapes");
- TEST(t_url_username_pass(), "url username/password escapes");
- TEST(t_url_length(), "url normalized lengths");
- TEST(t_url_dots(), "url . and .. segments");
- TEST(t_url_equivalents(), "url equivalents");
- return test_done();
-}
diff --git a/t/unit-tests/unit-test.c b/t/unit-tests/unit-test.c
index fa8818842a..5af645048a 100644
--- a/t/unit-tests/unit-test.c
+++ b/t/unit-tests/unit-test.c
@@ -1,5 +1,7 @@
#include "unit-test.h"
+#include "hex.h"
#include "parse-options.h"
+#include "strbuf.h"
#include "string-list.h"
#include "strvec.h"
diff --git a/t/unit-tests/unit-test.h b/t/unit-tests/unit-test.h
index 85e5d6a948..39a0b72a05 100644
--- a/t/unit-tests/unit-test.h
+++ b/t/unit-tests/unit-test.h
@@ -1,8 +1,13 @@
#include "git-compat-util.h"
#include "clar/clar.h"
-#include "clar-decls.h"
#include "strbuf.h"
+#ifndef GIT_CLAR_DECLS_H
+# include "clar-decls.h"
+#else
+# include GIT_CLAR_DECLS_H
+#endif
+
#define cl_failf(fmt, ...) do { \
char desc[4096]; \
snprintf(desc, sizeof(desc), fmt, __VA_ARGS__); \