Skip to content

Commit 7382be5

Browse files
authored
Merge pull request #127 from boidushya/main
fix: handle untracked files
2 parents 186dd99 + 7e41ef4 commit 7382be5

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
@@ -50,6 +50,10 @@ while IFS= read -r -d $'\0' line; do
5050
# handle adds (A), modifications (M), and type changes (T):
5151
[[ "$tree_status" =~ A|M|T || "$index_status" =~ A|M|T ]] && adds+=("$filename")
5252

53+
# handle untracked files (??):
54+
# https://github.com/planetscale/ghcommit-action/issues/43#issuecomment-1950986790
55+
[[ "$tree_status" == "?" && "$index_status" == "?" ]] && adds+=("$filename")
56+
5357
# handle deletes (D):
5458
[[ "$tree_status" =~ D || "$index_status" =~ D ]] && deletes+=("$filename")
5559

tests/entrypoint.bats

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

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)