mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2024-11-06 02:08:05 +00:00
Merge pull request #156 from funkjedi/status-add-options
Add options for git add/status commands
This commit is contained in:
commit
68f0d95687
@ -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
|
||||
|
@ -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() {
|
||||
|
@ -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"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user