]> git.99rst.org Git - git.git/commit
t: convert grep assertions to test_grep
authorMichael Montalbo <redacted>
Mon, 6 Jul 2026 05:01:57 +0000 (05:01 +0000)
committerJunio C Hamano <redacted>
Mon, 6 Jul 2026 20:27:00 +0000 (13:27 -0700)
commit47f79f619834acdd39d39bd1d3b33bf57f80d0a2
tree3ae4f30722d7edea421f8d6a9fb5b09ac4466c78
parent4f8f121effc5dc7fcc4fcc98c60c5b92ec6f87f4
t: convert grep assertions to test_grep

Replace bare grep with test_grep in test assertions across the
suite, including sourced test helpers (lib-*.sh, *-tests.sh).
test_grep prints the contents of the file being searched on
failure, making debugging easier than a bare grep which fails
silently.

Only assertion-style greps are converted: grep used as a filter
in pipelines, command substitutions, conditionals, or with
redirected I/O is left as-is with a "# lint-ok" annotation.
Existing '! test_grep' calls are rewritten to 'test_grep !' so
that the diagnostic output is preserved on failure.

test_grep requires the file it reads to exist, so '! grep'
assertions that inspect a file whose presence is conditional need
care.  In t5537 the '.git/shallow' file is still present after the
repack (the client remains shallow), so the assertion is
converted like any other.  In t1400 the '.git/packed-refs' file
exists only with the files backend, so its check is guarded with a
REFFILES prerequisite; the backend-agnostic 'git show-ref' check
that follows still runs under every backend.  In t7450 'git~2' is
the NTFS 8.3 short name of a '..git' file and only exists
when 8.3 short-name generation is enabled, so its check is guarded
with a 'test -f' on the path and uses test_grep inside the guard,
the same shape as t1400 (a plain test_grep would BUG when the
short name is absent).

The conversion was generated using a grep-assertion linter
(greplint.pl, added in the following commit) to identify bare
grep calls at command position.  To reproduce, from the t/
directory:

    # Step 1: annotate the two data-filter greps (grep produces
    # data, not a verdict) so the linter skips them.
    sed -i '/grep -vf before commits\.raw/s/$/ # lint-ok: data filter/' \
        t5326-multi-pack-bitmaps.sh
    sed -i '/grep -E "^\[0-9a-f\].*|| :/s/$/ # lint-ok: data filter/' \
        t5702-protocol-v2.sh

    # Step 1b: two '! grep' assertions need more than a mechanical
    # conversion; handle them by hand before the linter-driven steps
    # below so it leaves them alone.
    #
    # t1400: '.git/packed-refs' is absent under reftable, so guard the
    # check with REFFILES (a plain test_grep would BUG on the missing
    # file):
    #
    #      git update-ref -d HEAD $B &&
    #  -   ! grep "$m" .git/packed-refs &&
    #  +   if test_have_prereq REFFILES
    #  +   then
    #  +           test_grep ! "$m" .git/packed-refs
    #  +   fi &&
    #      test_must_fail git show-ref --verify -q $m
    #
    # t7450: git~2 is an NTFS 8.3 short name that exists only when
    # short-name generation is enabled, so guard the check on its
    # presence with 'test -f' and note in a comment why the path can
    # be absent (a plain test_grep would BUG when it is):
    #
    #  -   ! grep gitdir squatting-clone/d/a/git~2
    #  +   if test -f squatting-clone/d/a/git~2
    #  +   then
    #  +           test_grep ! gitdir squatting-clone/d/a/git~2
    #  +   fi

    # Step 2: reorder pre-existing '! test_grep' to 'test_grep !'
    # (must come before steps 3-4 so greplint does not see them)
    sed -i 's/! test_grep/test_grep !/' t0031-lockfile-pid.sh
    sed -i 's/! test_grep/test_grep !/' t5300-pack-object.sh
    sed -i 's/! test_grep/test_grep !/' t5319-multi-pack-index.sh

    # Step 3: convert '! grep' -> 'test_grep !'
    perl greplint.pl *.sh 2>&1 | cut -d: -f1,2 |
    while IFS=: read f l; do
        sed -i "${l}s/! *grep/test_grep !/" "$f"
    done

    # Step 4: convert remaining 'grep' -> 'test_grep'
    perl greplint.pl *.sh 2>&1 | cut -d: -f1,2 |
    while IFS=: read f l; do
        sed -i "${l}s/grep/test_grep/" "$f"
    done

To verify, run: make -C t test-greplint

Signed-off-by: Michael Montalbo <redacted>
Signed-off-by: Junio C Hamano <redacted>
338 files changed:
t/for-each-ref-tests.sh
t/lib-bitmap.sh
t/lib-bundle-uri-protocol.sh
t/lib-httpd.sh
t/pack-refs-tests.sh
t/show-ref-exists-tests.sh
t/t0000-basic.sh
t/t0001-init.sh
t/t0008-ignores.sh
t/t0009-git-dir-validation.sh
t/t0012-help.sh
t/t0013-sha1dc.sh
t/t0017-env-helper.sh
t/t0021-conversion.sh
t/t0029-core-unsetenvvars.sh
t/t0030-stripspace.sh
t/t0031-lockfile-pid.sh
t/t0040-parse-options.sh
t/t0041-usage.sh
t/t0052-simple-ipc.sh
t/t0061-run-command.sh
t/t0066-dir-iterator.sh
t/t0068-for-each-repo.sh
t/t0070-fundamental.sh
t/t0081-find-pack.sh
t/t0091-bugreport.sh
t/t0092-diagnose.sh
t/t0100-previous.sh
t/t0200-gettext-basic.sh
t/t0203-gettext-setlocale-sanity.sh
t/t0204-gettext-reencode-sanity.sh
t/t0210-trace2-normal.sh
t/t0211-trace2-perf.sh
t/t0212-trace2-event.sh
t/t0300-credentials.sh
t/t0410-partial-clone.sh
t/t0450-txt-doc-vs-help.sh
t/t0500-progress-display.sh
t/t0610-reftable-basics.sh
t/t1004-read-tree-m-u-wf.sh
t/t1006-cat-file.sh
t/t1007-hash-object.sh
t/t1011-read-tree-sparse-checkout.sh
t/t1050-large.sh
t/t1091-sparse-checkout-builtin.sh
t/t1092-sparse-checkout-compatibility.sh
t/t1300-config.sh
t/t1305-config-include.sh
t/t1308-config-set.sh
t/t1400-update-ref.sh
t/t1403-show-ref.sh
t/t1410-reflog.sh
t/t1415-worktree-refs.sh
t/t1430-bad-ref-name.sh
t/t1450-fsck.sh
t/t1451-fsck-buffer.sh
t/t1460-refs-migrate.sh
t/t1500-rev-parse.sh
t/t1502-rev-parse-parseopt.sh
t/t1503-rev-parse-verify.sh
t/t1510-repo-setup.sh
t/t1512-rev-parse-disambiguation.sh
t/t1515-rev-parse-outside-repo.sh
t/t1800-hook.sh
t/t2004-checkout-cache-temp.sh
t/t2019-checkout-ambiguous-ref.sh
t/t2024-checkout-dwim.sh
t/t2030-unresolve-info.sh
t/t2060-switch.sh
t/t2070-restore.sh
t/t2080-parallel-checkout-basics.sh
t/t2081-parallel-checkout-collisions.sh
t/t2082-parallel-checkout-attributes.sh
t/t2103-update-index-ignore-missing.sh
t/t2200-add-update.sh
t/t2203-add-intent.sh
t/t2400-worktree-add.sh
t/t2402-worktree-list.sh
t/t2403-worktree-move.sh
t/t2405-worktree-submodule.sh
t/t2407-worktree-heads.sh
t/t2500-untracked-overwriting.sh
t/t2501-cwd-empty.sh
t/t3001-ls-files-others-exclude.sh
t/t3007-ls-files-recurse-submodules.sh
t/t3200-branch.sh
t/t3202-show-branch.sh
t/t3203-branch-output.sh
t/t3206-range-diff.sh
t/t3207-branch-submodule.sh
t/t3301-notes.sh
t/t3310-notes-merge-manual-resolve.sh
t/t3320-notes-merge-worktrees.sh
t/t3400-rebase.sh
t/t3402-rebase-merge.sh
t/t3404-rebase-interactive.sh
t/t3406-rebase-message.sh
t/t3415-rebase-autosquash.sh
t/t3416-rebase-onto-threedots.sh
t/t3418-rebase-continue.sh
t/t3420-rebase-autostash.sh
t/t3422-rebase-incompatible-options.sh
t/t3429-rebase-edit-todo.sh
t/t3430-rebase-merges.sh
t/t3500-cherry.sh
t/t3501-revert-cherry-pick.sh
t/t3504-cherry-pick-rerere.sh
t/t3510-cherry-pick-sequence.sh
t/t3602-rm-sparse-checkout.sh
t/t3705-add-sparse-checkout.sh
t/t3800-mktag.sh
t/t3901-i18n-patch.sh
t/t3903-stash.sh
t/t3904-stash-patch.sh
t/t3908-stash-in-worktree.sh
t/t4000-diff-format.sh
t/t4001-diff-rename.sh
t/t4011-diff-symlink.sh
t/t4013-diff-various.sh
t/t4014-format-patch.sh
t/t4015-diff-whitespace.sh
t/t4017-diff-retval.sh
t/t4018-diff-funcname.sh
t/t4019-diff-wserror.sh
t/t4020-diff-external.sh
t/t4021-format-patch-numbered.sh
t/t4022-diff-rewrite.sh
t/t4028-format-patch-mime-headers.sh
t/t4031-diff-rewrite-binary.sh
t/t4033-diff-patience.sh
t/t4036-format-patch-signer-mime.sh
t/t4038-diff-combined.sh
t/t4051-diff-function-context.sh
t/t4053-diff-no-index.sh
t/t4063-diff-blobs.sh
t/t4065-diff-anchored.sh
t/t4067-diff-partial-clone.sh
t/t4073-diff-stat-name-width.sh
t/t4103-apply-binary.sh
t/t4120-apply-popt.sh
t/t4124-apply-ws-rule.sh
t/t4128-apply-root.sh
t/t4140-apply-ita.sh
t/t4141-apply-too-large.sh
t/t4150-am.sh
t/t4200-rerere.sh
t/t4201-shortlog.sh
t/t4202-log.sh
t/t4204-patch-id.sh
t/t4205-log-pretty-formats.sh
t/t4209-log-pickaxe.sh
t/t4211-line-log.sh
t/t4216-log-bloom.sh
t/t4252-am-options.sh
t/t4254-am-corrupt.sh
t/t4258-am-quoted-cr.sh
t/t4301-merge-tree-write-tree.sh
t/t5000-tar-tree.sh
t/t5004-archive-corner-cases.sh
t/t5100-mailinfo.sh
t/t5150-request-pull.sh
t/t5300-pack-object.sh
t/t5302-pack-index.sh
t/t5304-prune.sh
t/t5310-pack-bitmaps.sh
t/t5317-pack-objects-filter-objects.sh
t/t5318-commit-graph.sh
t/t5319-multi-pack-index.sh
t/t5324-split-commit-graph.sh
t/t5325-reverse-index.sh
t/t5326-multi-pack-bitmaps.sh
t/t5328-commit-graph-64bit-time.sh
t/t5329-pack-objects-cruft.sh
t/t5334-incremental-multi-pack-index.sh
t/t5335-compact-multi-pack-index.sh
t/t5351-unpack-large-objects.sh
t/t5402-post-merge-hook.sh
t/t5403-post-checkout-hook.sh
t/t5404-tracking-branches.sh
t/t5406-remote-rejects.sh
t/t5407-post-rewrite-hook.sh
t/t5409-colorize-remote-messages.sh
t/t5500-fetch-pack.sh
t/t5504-fetch-receive-strict.sh
t/t5505-remote.sh
t/t5510-fetch.sh
t/t5512-ls-remote.sh
t/t5514-fetch-multiple.sh
t/t5516-fetch-push.sh
t/t5520-pull.sh
t/t5524-pull-msg.sh
t/t5526-fetch-submodules.sh
t/t5529-push-errors.sh
t/t5530-upload-pack-error.sh
t/t5531-deep-submodule-push.sh
t/t5532-fetch-proxy.sh
t/t5533-push-cas.sh
t/t5534-push-signed.sh
t/t5537-fetch-shallow.sh
t/t5538-push-shallow.sh
t/t5539-fetch-http-shallow.sh
t/t5541-http-push-smart.sh
t/t5544-pack-objects-hook.sh
t/t5550-http-fetch-dumb.sh
t/t5551-http-fetch-smart.sh
t/t5552-skipping-fetch-negotiator.sh
t/t5554-noop-fetch-negotiator.sh
t/t5557-http-get.sh
t/t5558-clone-bundle-uri.sh
t/t5562-http-backend-content-length.sh
t/t5564-http-proxy.sh
t/t5581-http-curl-verbose.sh
t/t5583-push-branches.sh
t/t5601-clone.sh
t/t5604-clone-reference.sh
t/t5605-clone-local.sh
t/t5606-clone-options.sh
t/t5612-clone-refspec.sh
t/t5616-partial-clone.sh
t/t5619-clone-local-ambiguous-transport.sh
t/t5620-backfill.sh
t/t5700-protocol-v1.sh
t/t5701-git-serve.sh
t/t5702-protocol-v2.sh
t/t5703-upload-pack-ref-in-want.sh
t/t5705-session-id-in-capabilities.sh
t/t5750-bundle-uri-parse.sh
t/t5801-remote-helpers.sh
t/t5810-proto-disable-local.sh
t/t5813-proto-disable-ssh.sh
t/t6000-rev-list-misc.sh
t/t6005-rev-list-count.sh
t/t6006-rev-list-format.sh
t/t6009-rev-list-parent.sh
t/t6020-bundle-misc.sh
t/t6022-rev-list-missing.sh
t/t6030-bisect-porcelain.sh
t/t6040-tracking-info.sh
t/t6112-rev-list-filters-objects.sh
t/t6115-rev-list-du.sh
t/t6120-describe.sh
t/t6200-fmt-merge-msg.sh
t/t6402-merge-rename.sh
t/t6403-merge-file.sh
t/t6404-recursive-merge.sh
t/t6406-merge-attr.sh
t/t6417-merge-ours-theirs.sh
t/t6418-merge-text-auto.sh
t/t6422-merge-rename-corner-cases.sh
t/t6423-merge-rename-directories.sh
t/t6424-merge-unrelated-index-changes.sh
t/t6427-diff3-conflict-markers.sh
t/t6432-merge-recursive-space-options.sh
t/t6436-merge-overwrite.sh
t/t6437-submodule-merge.sh
t/t6500-gc.sh
t/t6600-test-reach.sh
t/t7001-mv.sh
t/t7002-mv-sparse-checkout.sh
t/t7003-filter-branch.sh
t/t7004-tag.sh
t/t7006-pager.sh
t/t7012-skip-worktree-writing.sh
t/t7030-verify-tag.sh
t/t7031-verify-tag-signed-ssh.sh
t/t7102-reset.sh
t/t7110-reset-merge.sh
t/t7201-co.sh
t/t7300-clean.sh
t/t7301-clean-interactive.sh
t/t7400-submodule-basic.sh
t/t7402-submodule-rebase.sh
t/t7406-submodule-update.sh
t/t7416-submodule-dash-url.sh
t/t7417-submodule-path-url.sh
t/t7450-bad-git-dotfiles.sh
t/t7501-commit-basic-functionality.sh
t/t7502-commit-porcelain.sh
t/t7507-commit-verbose.sh
t/t7508-status.sh
t/t7510-signed-commit.sh
t/t7516-commit-races.sh
t/t7519-status-fsmonitor.sh
t/t7527-builtin-fsmonitor.sh
t/t7528-signed-commit-ssh.sh
t/t7600-merge.sh
t/t7603-merge-reduce-heads.sh
t/t7606-merge-custom.sh
t/t7607-merge-state.sh
t/t7610-mergetool.sh
t/t7700-repack.sh
t/t7703-repack-geometric.sh
t/t7704-repack-cruft.sh
t/t7800-difftool.sh
t/t7810-grep.sh
t/t7814-grep-recurse-submodules.sh
t/t7900-maintenance.sh
t/t8008-blame-formats.sh
t/t8010-cat-file-filters.sh
t/t8012-blame-colors.sh
t/t9001-send-email.sh
t/t9003-help-autocorrect.sh
t/t9106-git-svn-commit-diff-clobber.sh
t/t9107-git-svn-migrate.sh
t/t9110-git-svn-use-svm-props.sh
t/t9111-git-svn-use-svnsync-props.sh
t/t9114-git-svn-dcommit-merge.sh
t/t9116-git-svn-log.sh
t/t9117-git-svn-init-clone.sh
t/t9119-git-svn-info.sh
t/t9122-git-svn-author.sh
t/t9130-git-svn-authors-file.sh
t/t9138-git-svn-authors-prog.sh
t/t9140-git-svn-reset.sh
t/t9153-git-svn-rewrite-uuid.sh
t/t9200-git-cvsexportcommit.sh
t/t9210-scalar.sh
t/t9211-scalar-clone.sh
t/t9300-fast-import.sh
t/t9350-fast-export.sh
t/t9351-fast-export-anonymize.sh
t/t9400-git-cvsserver-server.sh
t/t9501-gitweb-standalone-http-status.sh
t/t9502-gitweb-standalone-parse-output.sh
t/t9800-git-p4-basic.sh
t/t9801-git-p4-branch.sh
t/t9806-git-p4-options.sh
t/t9807-git-p4-submit.sh
t/t9810-git-p4-rcs.sh
t/t9813-git-p4-preserve-users.sh
t/t9814-git-p4-rename.sh
t/t9827-git-p4-change-filetype.sh
t/t9832-unshelve.sh
t/t9833-errors.sh
t/t9835-git-p4-metadata-encoding-python2.sh
t/t9836-git-p4-metadata-encoding-python3.sh
t/t9850-shell.sh
t/t9902-completion.sh
git clone https://git.99rst.org/PROJECT