diff --git a/entrypoint.sh b/entrypoint.sh index 42f3f97..e35b0e5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -57,7 +57,7 @@ while IFS= read -r -d $'\0' line; do # handle deletes (D): [[ "$tree_status" =~ D || "$index_status" =~ D ]] && deletes+=("$filename") -done < <(git status -s --porcelain=v1 -z -- "${FILE_PATTERNS[@]}") +done < <(git status -s --porcelain=v1 -z -uall -- "${FILE_PATTERNS[@]}") if [[ "${#adds[@]}" -eq 0 && "${#deletes[@]}" -eq 0 && "$EMPTY" == "false" ]]; then echo "No changes detected, exiting" diff --git a/tests/entrypoint.bats b/tests/entrypoint.bats index 4255754..8b5926e 100644 --- a/tests/entrypoint.bats +++ b/tests/entrypoint.bats @@ -26,7 +26,7 @@ setup() { # of the git status output. stub git \ "config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \ - "status -s --porcelain=v1 -z -- . : cat ./tests/fixtures/git-status.out-1 | tr '\n' '\0'" + "status -s --porcelain=v1 -z -uall -- . : cat ./tests/fixtures/git-status.out-1 | tr '\n' '\0'" stub ghcommit \ '-b main -r org/repo -m msg --add=README.md --add=foo.txt --add=new.file --delete=old.file --delete=\""a path with spaces oh joy/file.txt\"" : echo Success. New commit: https://localhost/foo' @@ -47,7 +47,7 @@ setup() { stub git \ "config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \ - "status -s --porcelain=v1 -z -- . : echo" + "status -s --porcelain=v1 -z -uall -- . : echo" run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern" assert_success @@ -65,7 +65,7 @@ setup() { stub git \ "config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \ - "status -s --porcelain=v1 -z -- . : echo" + "status -s --porcelain=v1 -z -uall -- . : echo" stub ghcommit \ '-b main -r org/repo -m msg --empty : echo Success. New commit: https://localhost/foo' @@ -88,7 +88,7 @@ setup() { stub git \ "config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \ - "status -s --porcelain=v1 -z -- . : cat ./tests/fixtures/git-status.out-2 | tr '\n' '\0'" + "status -s --porcelain=v1 -z -uall -- . : cat ./tests/fixtures/git-status.out-2 | tr '\n' '\0'" stub ghcommit \ '-b main -r org/repo -m msg --add=untracked.txt --add=new-file.md --add=modified.txt : echo Success. New commit: https://localhost/bar' @@ -99,3 +99,26 @@ setup() { assert_file_exist "$GITHUB_OUTPUT" assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/bar" } + +@test "handles untracked dirs" { + local commit_message='msg' + local repo='org/repo' + local branch='main' + local empty='false' + local file_pattern='.' + + export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/github-output" + + stub git \ + "config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \ + "status -s --porcelain=v1 -z -uall -- . : cat ./tests/fixtures/git-status.out-3 | tr '\n' '\0'" + + stub ghcommit \ + '-b main -r org/repo -m msg --add=newdir/file1.txt --add=newdir/file2.txt : echo Success. New commit: https://localhost/bar' + + run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern" + assert_success + assert_output --partial "Success" + assert_file_exist "$GITHUB_OUTPUT" + assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/bar" +} diff --git a/tests/fixtures/git-status.out-3 b/tests/fixtures/git-status.out-3 new file mode 100644 index 0000000..4062a0a --- /dev/null +++ b/tests/fixtures/git-status.out-3 @@ -0,0 +1,2 @@ +?? newdir/file1.txt +?? newdir/file2.txt