Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skip_checkout option #197

Merged
merged 1 commit into from Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -78,6 +78,9 @@ The following is an extended example with all possible options available for thi
# Optional. Skip internal call to `git fetch`
skip_fetch: true

# Optional. Skip internal call to `git checkout`
skip_checkout: true

# Optional. Prevents the shell from expanding filenames.
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
disable_globbing: true
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -60,6 +60,10 @@ inputs:
description: Skip the call to git-fetch.
required: false
default: false
skip_checkout:
description: Skip the call to git-checkout.
required: false
default: false
disable_globbing:
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
default: false
Expand Down
10 changes: 7 additions & 3 deletions entrypoint.sh
Expand Up @@ -55,9 +55,13 @@ _switch_to_branch() {
git fetch --depth=1;
fi

# Switch to branch from current Workflow run
# shellcheck disable=SC2086
git checkout $INPUT_BRANCH;
if "$INPUT_SKIP_CHECKOUT"; then
echo "::debug::git-checkout has not been executed";
else
# Switch to branch from current Workflow run
# shellcheck disable=SC2086
git checkout $INPUT_BRANCH;
fi
}

_add_files() {
Expand Down
14 changes: 14 additions & 0 deletions tests/git-auto-commit.bats
Expand Up @@ -24,6 +24,7 @@ setup() {
export INPUT_PUSH_OPTIONS=""
export INPUT_SKIP_DIRTY_CHECK=false
export INPUT_SKIP_FETCH=false
export INPUT_SKIP_CHECKOUT=false
export INPUT_DISABLE_GLOBBING=false

# Configure Git
Expand Down Expand Up @@ -381,6 +382,19 @@ git_auto_commit() {
assert_line "::debug::git-fetch has not been executed"
}

@test "If SKIP_CHECKOUT is true git-checkout will not be called" {

touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt

INPUT_SKIP_CHECKOUT=true

run git_auto_commit

assert_success

assert_line "::debug::git-checkout has not been executed"
}

@test "It pushes generated commit and tag to remote and actually updates the commit shas" {
INPUT_BRANCH=""
INPUT_TAGGING_MESSAGE="v2.0.0"
Expand Down