t2400: rewrite regex to avoid unintentional PCRE

Replace all cases of `\s` with ` ` as it is not part of POSIX BRE or ERE and therefore not all versions of grep handle it. For the same reason all cases of `\S` are replaced with `[^ ]`. It is not an exact replacement but it is close enough for this use case. Also, do not write `\+` in BRE and expect it to mean 1 or more; it is a GNU extension that may not work everywhere. Remove `.*` from the end of a pattern that is not right-anchored. Signed-off-by: Jacob Abel <jacobabel@nullpo.dev> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jacob Abel committed Jul 26, 2023 at 21:42 UTC d1b72cb36487772fa70217f4234c886db7a5892f
1 file changed +6 -6
t/t2400-worktree-add.sh
+6 -6
@@ -417,9 +417,9 @@ test_wt_add_orphan_hint () {
417 grep "hint: If you meant to create a worktree containing a new orphan branch" actual &&
418 if [ $use_branch -eq 1 ]
419 then
420 - grep -E "^hint:\s+git worktree add --orphan -b \S+ \S+\s*$" actual
420 + grep -E "^hint: +git worktree add --orphan -b [^ ]+ [^ ]+$" actual
421 else
422 - grep -E "^hint:\s+git worktree add --orphan \S+\s*$" actual
422 + grep -E "^hint: +git worktree add --orphan [^ ]+$" actual
423 fi
424
425 '
@@ -709,8 +709,8 @@ test_dwim_orphan () {
709 local info_text="No possible source branch, inferring '--orphan'" &&
710 local fetch_error_text="fatal: No local or remote refs exist despite at least one remote" &&
711 local orphan_hint="hint: If you meant to create a worktree containing a new orphan branch" &&
712 - local invalid_ref_regex="^fatal: invalid reference:\s\+.*" &&
713 - local bad_combo_regex="^fatal: '[a-z-]\+' and '[a-z-]\+' cannot be used together" &&
712 + local invalid_ref_regex="^fatal: invalid reference: " &&
713 + local bad_combo_regex="^fatal: '[-a-z]*' and '[-a-z]*' cannot be used together" &&
714
715 local git_ns="repo" &&
716 local dashc_args="-C $git_ns" &&
@@ -998,8 +998,8 @@ test_dwim_orphan () {
998 headpath=$(git $dashc_args rev-parse --path-format=absolute --git-path HEAD) &&
999 headcontents=$(cat "$headpath") &&
1000 grep "HEAD points to an invalid (or orphaned) reference" actual &&
1001 - grep "HEAD path:\s*.$headpath." actual &&
1002 - grep "HEAD contents:\s*.$headcontents." actual &&
1001 + grep "HEAD path: .$headpath." actual &&
1002 + grep "HEAD contents: .$headcontents." actual &&
1003 grep "$orphan_hint" actual &&
1004 ! grep "$info_text" actual
1005 fi &&