Skip to content

Commit 6b5d830

Browse files
Merge pull request #38 from step-security/auto-cherry-pick
chore: Cherry-picked changes from upstream
2 parents 6a5df62 + 9b7b1f2 commit 6b5d830

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ while IFS= read -r -d $'\0' line; do
6969
# handle adds (A), modifications (M), and type changes (T):
7070
[[ "$tree_status" =~ A|M|T || "$index_status" =~ A|M|T ]] && adds+=("$filename")
7171

72+
# handle untracked files (??):
73+
# https://github.com/planetscale/ghcommit-action/issues/43#issuecomment-1950986790
74+
[[ "$tree_status" == "?" && "$index_status" == "?" ]] && adds+=("$filename")
75+
7276
# handle deletes (D):
7377
[[ "$tree_status" =~ D || "$index_status" =~ D ]] && deletes+=("$filename")
7478

tests/entrypoint.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,26 @@ setup() {
7777
assert_file_exist "$GITHUB_OUTPUT"
7878
assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/foo"
7979
}
80+
81+
@test "handles untracked files" {
82+
local commit_message='msg'
83+
local repo='org/repo'
84+
local branch='main'
85+
local empty='false'
86+
local file_pattern='.'
87+
88+
export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/github-output"
89+
90+
stub git \
91+
"config --global --add safe.directory $GITHUB_WORKSPACE : echo stubbed" \
92+
"status -s --porcelain=v1 -z -- . : cat ./tests/fixtures/git-status.out-2 | tr '\n' '\0'"
93+
94+
stub ghcommit \
95+
'-b main -r org/repo -m msg --add=untracked.txt --add=new-file.md --add=modified.txt : echo Success. New commit: https://localhost/bar'
96+
97+
run ./entrypoint.sh "$commit_message" "$repo" "$branch" "$empty" "$file_pattern"
98+
assert_success
99+
assert_output --partial "Success"
100+
assert_file_exist "$GITHUB_OUTPUT"
101+
assert_file_contains "$GITHUB_OUTPUT" "commit-url=https://localhost/bar"
102+
}

tests/fixtures/git-status.out-2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
?? untracked.txt
2+
?? new-file.md
3+
M modified.txt

0 commit comments

Comments
 (0)