Skip to content

Commit b1801b8

Browse files
sunshinecogitster
authored andcommitted
t2028: tighten grep expression to make "move worktree" test more robust
Following a rename of worktree "source" to "destination", the "move worktree" test uses grep to verify that the output of "git worktree list --porcelain" does not contain "source" (and does contain "destination"). Unfortunately, the grep expression is too loose and can match unexpectedly. For example, if component of the test trash directory path matches "source" (e.g. "/home/me/sources/git/t/trash*"), then the test will be fooled into thinking that "source" still exists. Tighten the expression to avoid such accidental matches. While at it, drop an unused variable ("toplevel") from the test and tighten a similarly too-loose expression in a related test. Reported-by: Jens Krüger <[email protected]> Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f19def commit b1801b8

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

t/t2028-worktree-move.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,11 @@ test_expect_success 'move locked worktree' '
7272
'
7373

7474
test_expect_success 'move worktree' '
75-
toplevel="$(pwd)" &&
7675
git worktree move source destination &&
7776
test_path_is_missing source &&
7877
git worktree list --porcelain >out &&
79-
grep "^worktree.*/destination" out &&
80-
! grep "^worktree.*/source" out &&
78+
grep "^worktree.*/destination$" out &&
79+
! grep "^worktree.*/source$" out &&
8180
git -C destination log --format=%s >actual2 &&
8281
echo init >expected2 &&
8382
test_cmp expected2 actual2
@@ -93,7 +92,7 @@ test_expect_success 'move worktree to another dir' '
9392
test_when_finished "git worktree move some-dir/destination destination" &&
9493
test_path_is_missing destination &&
9594
git worktree list --porcelain >out &&
96-
grep "^worktree.*/some-dir/destination" out &&
95+
grep "^worktree.*/some-dir/destination$" out &&
9796
git -C some-dir/destination log --format=%s >actual2 &&
9897
echo init >expected2 &&
9998
test_cmp expected2 actual2

0 commit comments

Comments
 (0)