diff --git a/README.md b/README.md index bd10bf9..78cc22b 100644 --- a/README.md +++ b/README.md @@ -105,10 +105,19 @@ The following is an extended example with all available options. # Optional. Disable dirty check and always try to create a commit and push skip_dirty_check: true + # 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 + # Optional. Create given branch name in local and remote repository. + create_branch: true + # Optional. Creates a new tag and pushes it to remote without creating a commit. # Skips dirty check and changed files. Must be used with `tagging_message`. create_git_tag_only: false @@ -412,6 +421,7 @@ The steps in your workflow might look like this: commit_message: ${{ steps.last-commit.outputs.message }} commit_options: '--amend --no-edit' push_options: '--force' + skip_fetch: true ``` See discussion in [#159](https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950) for details. diff --git a/action.yml b/action.yml index 9df496a..60268dd 100644 --- a/action.yml +++ b/action.yml @@ -56,9 +56,20 @@ inputs: description: Skip the check if the git repository is dirty and always try to create a commit. required: false default: false + skip_fetch: + 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 + create_branch: + description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet. + default: false create_git_tag_only: description: Perform a clean git tag and push, without commiting anything required: false @@ -66,17 +77,6 @@ inputs: internal_git_binary: description: Internal use only! Path to git binary used to check if git is available. (Don't change this!) default: git - skip_fetch: - description: "Deprecated: skip_fetch has been removed in v6. It does not have any effect anymore." - required: false - default: false - skip_checkout: - description: "Deprecated: skip_checkout has been removed in v6. It does not have any effect anymore." - required: false - default: false - create_branch: - description: "Deprecated: create_branch has been removed in v6. It does not have any effect anymore." - default: false outputs: diff --git a/entrypoint.sh b/entrypoint.sh index b55b351..a3885d9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -56,6 +56,8 @@ _main() { _set_github_output "changes_detected" "true" + _switch_to_branch + _add_files # Check dirty state of repo again using git-diff. @@ -127,6 +129,32 @@ _check_if_repository_is_in_detached_state() { fi } +_switch_to_branch() { + echo "INPUT_BRANCH value: $INPUT_BRANCH"; + + # Fetch remote to make sure that repo can be switched to the right branch. + if "$INPUT_SKIP_FETCH"; then + _log "debug" "git-fetch will not be executed."; + else + git fetch --depth=1; + fi + + # If `skip_checkout`-input is true, skip the entire checkout step. + if "$INPUT_SKIP_CHECKOUT"; then + _log "debug" "git-checkout will not be executed."; + else + # Create new local branch if `create_branch`-input is true + if "$INPUT_CREATE_BRANCH"; then + # shellcheck disable=SC2086 + git checkout -B $INPUT_BRANCH --; + else + # Switch to branch from current Workflow run + # shellcheck disable=SC2086 + git checkout $INPUT_BRANCH --; + fi + fi +} + _add_files() { echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}"; _log "debug" "Apply add options ${INPUT_ADD_OPTIONS}";