Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ while IFS= read -r -d $'\0' line; do
# handle adds (A), modifications (M), and type changes (T):
[[ "$tree_status" =~ A|M|T || "$index_status" =~ A|M|T ]] && adds+=("$filename")

# handle untracked files (??):
# https://github.com/planetscale/ghcommit-action/issues/43#issuecomment-1950986790
[[ "$tree_status" == "?" && "$index_status" == "?" ]] && adds+=("$filename")

# handle deletes (D):
[[ "$tree_status" =~ D || "$index_status" =~ D ]] && deletes+=("$filename")

Expand Down
23 changes: 23 additions & 0 deletions tests/entrypoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,26 @@ setup() {
assert_file_exist "$GITHUB_OUTPUT"
assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/foo"
}

@test "handles untracked files" {
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 -- . : 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'

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"
}
3 changes: 3 additions & 0 deletions tests/fixtures/git-status.out-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
?? untracked.txt
?? new-file.md
M modified.txt
Loading