mirror of
https://github.com/git-for-windows/git.git
synced 2026-07-02 20:29:15 -05:00
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.
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:
# Step 1: mark bare greps that should not be converted
sed -i '/! grep "$m" \.git\/packed-refs/s/$/ # lint-ok: file may not exist (reftable)/' \
t/t1400-update-ref.sh
sed -i '/! grep dirty file3 &&/{/lint-ok/!s/$/ # lint-ok: file may not exist after --quit/}' \
t/t3420-rebase-autostash.sh
sed -i '/grep -vf before commits\.raw/s/$/ # lint-ok: data filter/' \
t/t5326-multi-pack-bitmaps.sh
sed -i '/! grep $d shallow-client\/\.git\/shallow/s/$/ # lint-ok: file may not exist after repack/' \
t/t5537-fetch-shallow.sh
sed -i '/grep -E "^\[0-9a-f\].*|| :/s/$/ # lint-ok: data filter/' \
t/t5702-protocol-v2.sh
sed -i '/! grep gitdir squatting-clone/s/$/ # lint-ok: file may not exist after failed clone/' \
t/t7450-bad-git-dotfiles.sh
# 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 !/' t/t0031-lockfile-pid.sh
sed -i 's/! test_grep/test_grep !/' t/t5300-pack-object.sh
sed -i 's/! test_grep/test_grep !/' t/t5319-multi-pack-index.sh
# Step 3: convert '! grep' -> 'test_grep !'
perl t/greplint.pl t/*.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 t/greplint.pl t/*.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 <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
95 lines
3.7 KiB
Bash
Executable File
95 lines
3.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='Combination of submodules and multiple worktrees'
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
. ./test-lib.sh
|
|
|
|
base_path=$(pwd -P)
|
|
|
|
test_expect_success 'setup: create origin repos' '
|
|
git config --global protocol.file.allow always &&
|
|
git init origin/sub &&
|
|
test_commit -C origin/sub file1 &&
|
|
git init origin/main &&
|
|
test_commit -C origin/main first &&
|
|
git -C origin/main submodule add ../sub &&
|
|
git -C origin/main commit -m "add sub" &&
|
|
test_commit -C origin/sub "file1 updated" file1 file1updated file1updated &&
|
|
git -C origin/main/sub pull &&
|
|
git -C origin/main add sub &&
|
|
git -C origin/main commit -m "sub updated"
|
|
'
|
|
|
|
test_expect_success 'setup: clone superproject to create main worktree' '
|
|
git clone --recursive "$base_path/origin/main" main
|
|
'
|
|
|
|
rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1")
|
|
rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1")
|
|
|
|
test_expect_success 'add superproject worktree' '
|
|
git -C main worktree add "$base_path/worktree" "$rev1_hash_main"
|
|
'
|
|
|
|
test_expect_failure 'submodule is checked out just after worktree add' '
|
|
git -C worktree diff --submodule main"^!" >out &&
|
|
test_grep "file1 updated" out
|
|
'
|
|
|
|
test_expect_success 'add superproject worktree and initialize submodules' '
|
|
git -C main worktree add "$base_path/worktree-submodule-update" "$rev1_hash_main" &&
|
|
git -C worktree-submodule-update submodule update
|
|
'
|
|
|
|
test_expect_success 'submodule is checked out just after submodule update in linked worktree' '
|
|
git -C worktree-submodule-update diff --submodule main"^!" >out &&
|
|
test_grep "file1 updated" out
|
|
'
|
|
|
|
test_expect_success 'add superproject worktree and manually add submodule worktree' '
|
|
git -C main worktree add "$base_path/linked_submodule" "$rev1_hash_main" &&
|
|
git -C main/sub worktree add "$base_path/linked_submodule/sub" "$rev1_hash_sub"
|
|
'
|
|
|
|
test_expect_success 'submodule is checked out after manually adding submodule worktree' '
|
|
git -C linked_submodule diff --submodule main"^!" >out &&
|
|
test_grep "file1 updated" out
|
|
'
|
|
|
|
test_expect_success 'checkout --recurse-submodules uses $GIT_DIR for submodules in a linked worktree' '
|
|
git -C main worktree add "$base_path/checkout-recurse" --detach &&
|
|
git -C checkout-recurse submodule update --init &&
|
|
echo "gitdir: ../../main/.git/worktrees/checkout-recurse/modules/sub" >expect-gitfile &&
|
|
cat checkout-recurse/sub/.git >actual-gitfile &&
|
|
test_cmp expect-gitfile actual-gitfile &&
|
|
git -C main/sub rev-parse HEAD >expect-head-main &&
|
|
git -C checkout-recurse checkout --recurse-submodules HEAD~1 &&
|
|
cat checkout-recurse/sub/.git >actual-gitfile &&
|
|
git -C main/sub rev-parse HEAD >actual-head-main &&
|
|
test_cmp expect-gitfile actual-gitfile &&
|
|
test_cmp expect-head-main actual-head-main
|
|
'
|
|
|
|
test_expect_success 'core.worktree is removed in $GIT_DIR/modules/<name>/config, not in $GIT_COMMON_DIR/modules/<name>/config' '
|
|
echo "../../../sub" >expect-main &&
|
|
git -C main/sub config --get core.worktree >actual-main &&
|
|
test_cmp expect-main actual-main &&
|
|
echo "../../../../../../checkout-recurse/sub" >expect-linked &&
|
|
git -C checkout-recurse/sub config --get core.worktree >actual-linked &&
|
|
test_cmp expect-linked actual-linked &&
|
|
git -C checkout-recurse checkout --recurse-submodules first &&
|
|
test_expect_code 1 git -C main/.git/worktrees/checkout-recurse/modules/sub config --get core.worktree >linked-config &&
|
|
test_must_be_empty linked-config &&
|
|
git -C main/sub config --get core.worktree >actual-main &&
|
|
test_cmp expect-main actual-main
|
|
'
|
|
|
|
test_expect_success 'unsetting core.worktree does not prevent running commands directly against the submodule repository' '
|
|
git -C main/.git/worktrees/checkout-recurse/modules/sub log
|
|
'
|
|
|
|
test_done
|