Skip to content

Commit 4c05e3d

Browse files
Merge pull request #154 from stefanzweifel/fixes/153
Add "disable_globbing" option to prevent shell from expanding filenames
2 parents be7095c + 3053f48 commit 4c05e3d

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ This is a more extended example with all possible options.
6969
skip_dirty_check: true
7070

7171
# Optional: Skip internal call to `git fetch`
72-
skip_fetch: true
72+
skip_fetch: true
73+
74+
# Optional: Prevents the shell from expanding filenames. Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
75+
disable_globbing: true
7376
```
7477
7578
## Example

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ inputs:
5252
description: Skip the call to git-fetch.
5353
required: false
5454
default: false
55+
disable_globbing:
56+
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
57+
default: false
5558

5659
outputs:
5760
changes_detected:

entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
set -eu
44

5+
if "$INPUT_DISABLE_GLOBBING"; then
6+
set -o noglob;
7+
fi
8+
59
_main() {
610
_switch_to_repository
711

tests/git-auto-commit.bats

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ setup() {
2222
export INPUT_PUSH_OPTIONS=""
2323
export INPUT_SKIP_DIRTY_CHECK=false
2424
export INPUT_SKIP_FETCH=false
25+
export INPUT_DISABLE_GLOBBING=false
2526

2627
# Configure Git
2728
if [[ -z $(git config user.name) ]]; then
@@ -400,3 +401,38 @@ git_auto_commit() {
400401

401402
assert_equal $current_sha $remote_sha
402403
}
404+
405+
@test "It does not expand wildcard glob when using INPUT_PATTERN and INPUT_DISABLE_GLOBBING in git-status and git-add" {
406+
407+
# Create additional files in a nested directory structure
408+
echo "Create Additional files";
409+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-a.py
410+
mkdir "${FAKE_LOCAL_REPOSITORY}"/nested
411+
touch "${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py
412+
413+
# Commit changes
414+
echo "Commit changes before running git_auto_commit";
415+
cd "${FAKE_LOCAL_REPOSITORY}";
416+
git add . > /dev/null;
417+
git commit --quiet -m "Init Remote Repository";
418+
git push origin master > /dev/null;
419+
420+
# Make nested file dirty
421+
echo "foo-bar" > "${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py;
422+
423+
# ---
424+
425+
INPUT_FILE_PATTERN="*.py"
426+
INPUT_DISABLE_GLOBBING=true
427+
428+
run git_auto_commit
429+
430+
assert_success
431+
432+
assert_line "INPUT_FILE_PATTERN: *.py"
433+
assert_line "::debug::Push commit to remote branch master"
434+
435+
# Assert that the updated py file has been commited.
436+
run git status
437+
refute_output --partial 'nested/new-file-b.py'
438+
}

0 commit comments

Comments
 (0)