From 9bdb8afe6a1dd7c7978be729c8433225da5d61d0 Mon Sep 17 00:00:00 2001 From: peter woodman Date: Sat, 27 Jan 2024 23:46:22 -0500 Subject: [PATCH 1/2] fix filename pattern matching git ls-files seems to match against filename strings exactly, and doesn't use the same logic as e.g. gitignore. this means that to match files by exact filename below the root, we need a */ at the start of the pattern to match more than files strictly at the root of the tree. these prefixed patterns however miss the root, so we need to include both forms. this is doable with bash array regexes to avoid changing the pattern format to work with both find and git ls-files at the same time. --- format/private/format.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format/private/format.sh b/format/private/format.sh index d020a2f9..3f67807b 100755 --- a/format/private/format.sh +++ b/format/private/format.sh @@ -62,7 +62,7 @@ function ls-files { # TODO: determine which staged changes we should format; avoid formatting unstaged changes # TODO: try to format only modified regions of the file (where supported) - git ls-files --cached --modified --other --exclude-standard ${patterns[@]} | { + git ls-files --cached --modified --other --exclude-standard "${patterns[@]}" "${patterns[@]/#/*/}" | { grep -vE "^$(git ls-files --deleted)$" || true; } else From 95056f77d1e94fc8d7816da7882087a5d48703aa Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sun, 28 Jan 2024 17:39:25 -0800 Subject: [PATCH 2/2] chore: update test now that #122 is fixed --- format/test/format_test.bats | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/format/test/format_test.bats b/format/test/format_test.bats index ba8a256f..2e7169a0 100644 --- a/format/test/format_test.bats +++ b/format/test/format_test.bats @@ -16,7 +16,7 @@ bats_load_library "bats-assert" assert_output --partial "Formatting TSX with Prettier..." assert_output --partial "+ prettier --write example/src/hello.tsx" assert_output --partial "Formatting JSON with Prettier..." - assert_output --partial "+ prettier --write renovate.json" + assert_output --partial "+ prettier --write .bcr/metadata.template.json" assert_output --partial "Formatting CSS with Prettier..." assert_output --partial "+ prettier --write example/src/hello.css" assert_output --partial "Formatting HTML with Prettier..." @@ -38,8 +38,7 @@ bats_load_library "bats-assert" assert_output --partial "Formatting Starlark with Buildifier..." assert_output --partial "+ buildifier -mode=fix BUILD.bazel" - # FIXME(#122): this was broken by #105 - # assert_output --partial "format/private/BUILD.bazel" + assert_output --partial "format/private/BUILD.bazel" } @test "should run prettier on Markdown" { @@ -47,7 +46,7 @@ bats_load_library "bats-assert" assert_success assert_output --partial "Formatting Markdown with Prettier..." - assert_output --partial "+ prettier --write CONTRIBUTING.md README.md" + assert_output --partial "+ prettier --write .bcr/README.md CONTRIBUTING.md README.md" } @test "should run prettier on SQL" {