diff --git a/action.yml b/action.yml index fe8246c..c36ae92 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,14 @@ inputs: description: Commit options (eg. --no-verify) required: false default: '' + add_options: + description: Add options (eg. -u) + required: false + default: '' + status_options: + description: Status options (eg. --untracked-files=no) + required: false + default: '' file_pattern: description: File pattern used for `git add`. For example `src/\*.js` required: false diff --git a/entrypoint.sh b/entrypoint.sh index 0a1139c..22f01c1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,8 +37,11 @@ _switch_to_repository() { } _git_is_dirty() { + echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}"; + echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}"; + # shellcheck disable=SC2086 - [ -n "$(git status -s -- $INPUT_FILE_PATTERN)" ] + [ -n "$(git status -s $INPUT_STATUS_OPTIONS -- $INPUT_FILE_PATTERN)" ] } _switch_to_branch() { @@ -58,10 +61,13 @@ _switch_to_branch() { } _add_files() { + echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}"; + echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}"; + echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; # shellcheck disable=SC2086 - git add ${INPUT_FILE_PATTERN}; + git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN}; } _local_commit() { diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 1dae00e..b59f2a8 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -14,6 +14,8 @@ setup() { export INPUT_COMMIT_MESSAGE="Commit Message" export INPUT_BRANCH="master" export INPUT_COMMIT_OPTIONS="" + export INPUT_ADD_OPTIONS="" + export INPUT_STATUS_OPTIONS="" export INPUT_FILE_PATTERN="." export INPUT_COMMIT_USER_NAME="Test Suite" export INPUT_COMMIT_USER_EMAIL="test@github.com" @@ -115,6 +117,20 @@ git_auto_commit() { assert_line "::debug::Push commit to remote branch master" } +@test "It applies INPUT_STATUS_OPTIONS when running dirty check" { + INPUT_STATUS_OPTIONS="--untracked-files=no" + + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php + + run git_auto_commit + + assert_success + + assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" + assert_line "::set-output name=changes_detected::false" + assert_line "Working tree clean. Nothing to commit." +} + @test "It prints a 'Nothing to commit' message in a clean repository" { run git_auto_commit @@ -142,6 +158,28 @@ git_auto_commit() { assert_line "::debug::Apply commit options " } +@test "It applies INPUT_ADD_OPTIONS when adding files" { + INPUT_FILE_PATTERN="" + INPUT_STATUS_OPTIONS="--untracked-files=no" + INPUT_ADD_OPTIONS="-u" + + date > "${FAKE_LOCAL_REPOSITORY}"/remote-files1.txt + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php + + run git_auto_commit + + assert_success + + assert_line "INPUT_STATUS_OPTIONS: --untracked-files=no" + assert_line "INPUT_ADD_OPTIONS: -u" + assert_line "INPUT_FILE_PATTERN: " + assert_line "::debug::Push commit to remote branch master" + + # Assert that PHP files have not been added. + run git status + assert_output --partial 'new-file-1.php' +} + @test "It applies INPUT_FILE_PATTERN when creating commit" { INPUT_FILE_PATTERN="*.txt *.html"