Skip to content

Commit ccad859

Browse files
committed
Add options for add/status commands
1 parent 48d37c1 commit ccad859

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ inputs:
1616
description: Commit options (eg. --no-verify)
1717
required: false
1818
default: ''
19+
add_options:
20+
description: Add options (eg. -u)
21+
required: false
22+
default: ''
23+
status_options:
24+
description: Status options (eg. --untracked-files=no)
25+
required: false
26+
default: ''
1927
file_pattern:
2028
description: File pattern used for `git add`. For example `src/\*.js`
2129
required: false

entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ _switch_to_repository() {
3737
}
3838

3939
_git_is_dirty() {
40+
echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}";
41+
echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}";
42+
4043
# shellcheck disable=SC2086
41-
[ -n "$(git status -s -- $INPUT_FILE_PATTERN)" ]
44+
[ -n "$(git status -s $INPUT_STATUS_OPTIONS -- $INPUT_FILE_PATTERN)" ]
4245
}
4346

4447
_switch_to_branch() {
@@ -58,10 +61,13 @@ _switch_to_branch() {
5861
}
5962

6063
_add_files() {
64+
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
65+
echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}";
66+
6167
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
6268

6369
# shellcheck disable=SC2086
64-
git add ${INPUT_FILE_PATTERN};
70+
git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN};
6571
}
6672

6773
_local_commit() {

tests/git-auto-commit.bats

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ setup() {
1414
export INPUT_COMMIT_MESSAGE="Commit Message"
1515
export INPUT_BRANCH="master"
1616
export INPUT_COMMIT_OPTIONS=""
17+
export INPUT_ADD_OPTIONS=""
18+
export INPUT_STATUS_OPTIONS=""
1719
export INPUT_FILE_PATTERN="."
1820
export INPUT_COMMIT_USER_NAME="Test Suite"
1921
export INPUT_COMMIT_USER_EMAIL="test@github.com"
@@ -115,6 +117,20 @@ git_auto_commit() {
115117
assert_line "::debug::Push commit to remote branch master"
116118
}
117119

120+
@test "It applies INPUT_STATUS_OPTIONS when running dirty check" {
121+
INPUT_STATUS_OPTIONS="--untracked-files=no"
122+
123+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php
124+
125+
run git_auto_commit
126+
127+
assert_success
128+
129+
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
130+
assert_line "::set-output name=changes_detected::false"
131+
assert_line "Working tree clean. Nothing to commit."
132+
}
133+
118134
@test "It prints a 'Nothing to commit' message in a clean repository" {
119135
run git_auto_commit
120136

@@ -142,6 +158,28 @@ git_auto_commit() {
142158
assert_line "::debug::Apply commit options "
143159
}
144160

161+
@test "It applies INPUT_ADD_OPTIONS when adding files" {
162+
INPUT_FILE_PATTERN=""
163+
INPUT_STATUS_OPTIONS="--untracked-files=no"
164+
INPUT_ADD_OPTIONS="-u"
165+
166+
date > "${FAKE_LOCAL_REPOSITORY}"/remote-files1.txt
167+
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php
168+
169+
run git_auto_commit
170+
171+
assert_success
172+
173+
assert_line "INPUT_STATUS_OPTIONS: --untracked-files=no"
174+
assert_line "INPUT_ADD_OPTIONS: -u"
175+
assert_line "INPUT_FILE_PATTERN: "
176+
assert_line "::debug::Push commit to remote branch master"
177+
178+
# Assert that PHP files have not been added.
179+
run git status
180+
assert_output --partial 'new-file-1.php'
181+
}
182+
145183
@test "It applies INPUT_FILE_PATTERN when creating commit" {
146184
INPUT_FILE_PATTERN="*.txt *.html"
147185

0 commit comments

Comments
 (0)