From e610a5104baa0b55fd8b51e0736cf0a938799589 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 10 Apr 2021 16:53:50 +0200 Subject: [PATCH 1/5] Add failing test --- tests/git-auto-commit.bats | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 32b84e1..4447d3e 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -400,3 +400,37 @@ git_auto_commit() { assert_equal $current_sha $remote_sha } + +@test "It does not expand wildcard glob when using INPUT_PATTERN in git-status and git-add" { + + # Create additional files in a nested directory structure + echo "Create Additional files"; + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-a.py + mkdir "${FAKE_LOCAL_REPOSITORY}"/nested + touch "${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py + + # Commit changes + echo "Commit changes before running git_auto_commit"; + cd "${FAKE_LOCAL_REPOSITORY}"; + git add . > /dev/null; + git commit --quiet -m "Init Remote Repository"; + git push origin master > /dev/null; + + # Make nested file dirty + echo "foo-bar" > "${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py; + + # --- + + INPUT_FILE_PATTERN="*.py" + + run git_auto_commit + + assert_success + + assert_line "INPUT_FILE_PATTERN: *.py" + assert_line "::debug::Push commit to remote branch master" + + # Assert that py files have not been added. + run git status + refute_output --partial 'nested/new-file-b.py' +} From f4f9aedbeeb7b43f91af0984f9049b9662d835be Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 10 Apr 2021 16:58:48 +0200 Subject: [PATCH 2/5] Set noglob in git-auto-commit --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index 8449b91..f04a2fe 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/bash set -eu +set -o noglob; _main() { _switch_to_repository From be370eccae5f149a5d32e99eab65e1529881293c Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 10 Apr 2021 17:10:27 +0200 Subject: [PATCH 3/5] Create flag to disable globbing --- action.yml | 3 +++ entrypoint.sh | 5 ++++- tests/git-auto-commit.bats | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index adb0fdf..fe8246c 100644 --- a/action.yml +++ b/action.yml @@ -52,6 +52,9 @@ inputs: description: Skip the call to git-fetch. required: false default: false + disable_globbing: + description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html) + default: false outputs: changes_detected: diff --git a/entrypoint.sh b/entrypoint.sh index f04a2fe..0a1139c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,10 @@ #!/bin/bash set -eu -set -o noglob; + +if "$INPUT_DISABLE_GLOBBING"; then + set -o noglob; +fi _main() { _switch_to_repository diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 4447d3e..41239ee 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -22,6 +22,7 @@ setup() { export INPUT_PUSH_OPTIONS="" export INPUT_SKIP_DIRTY_CHECK=false export INPUT_SKIP_FETCH=false + export INPUT_DISABLE_GLOBBING=false # Configure Git if [[ -z $(git config user.name) ]]; then @@ -422,6 +423,7 @@ git_auto_commit() { # --- INPUT_FILE_PATTERN="*.py" + INPUT_DISABLE_GLOBBING=true run git_auto_commit From cfd366418e6662129cca321e305f4ee2cdf7b736 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 10 Apr 2021 17:11:30 +0200 Subject: [PATCH 4/5] Update README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d261094..b19e3f7 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,10 @@ This is a more extended example with all possible options. skip_dirty_check: true # Optional: Skip internal call to `git fetch` - skip_fetch: true + skip_fetch: true + + # Optional: Prevents the shell from expanding filenames. Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html + disable_globbing: true ``` ## Example From 3053f48bddbec118b0418e02b7a95baa912558a1 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 10 Apr 2021 17:13:22 +0200 Subject: [PATCH 5/5] Update Comments --- tests/git-auto-commit.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 41239ee..1dae00e 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -402,7 +402,7 @@ git_auto_commit() { assert_equal $current_sha $remote_sha } -@test "It does not expand wildcard glob when using INPUT_PATTERN in git-status and git-add" { +@test "It does not expand wildcard glob when using INPUT_PATTERN and INPUT_DISABLE_GLOBBING in git-status and git-add" { # Create additional files in a nested directory structure echo "Create Additional files"; @@ -432,7 +432,7 @@ git_auto_commit() { assert_line "INPUT_FILE_PATTERN: *.py" assert_line "::debug::Push commit to remote branch master" - # Assert that py files have not been added. + # Assert that the updated py file has been commited. run git status refute_output --partial 'nested/new-file-b.py' }