From fafea853e8a6a0a728c7244a91dc5facc66d0a0a Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 13 Dec 2020 09:22:38 +0100 Subject: [PATCH 1/4] Set depth on git-fetch --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 73c36d4..42eadba 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,7 +41,7 @@ _switch_to_branch() { echo "INPUT_BRANCH value: $INPUT_BRANCH"; # Fetch remote to make sure that repo can be switched to the right branch. - git fetch; + git fetch --depth=3; # Switch to branch from current Workflow run # shellcheck disable=SC2086 From a9021d53592e88e13cf7dba2fb9fd3bab07156fc Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sun, 13 Dec 2020 09:31:16 +0100 Subject: [PATCH 2/4] Add skip_fetch input option This new option will allow users to skip the execution of `git fetch` if it has a negative impact in their workflows. In a future PR I will probably remove the call to git-fetch interely. It was added in #108 in relation to a problem with slashes in branch names. That problem wasn't properly fixed though. --- action.yml | 4 ++++ entrypoint.sh | 7 ++++++- tests/git-auto-commit.bats | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a4a8630..adb0fdf 100644 --- a/action.yml +++ b/action.yml @@ -48,6 +48,10 @@ 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 outputs: changes_detected: diff --git a/entrypoint.sh b/entrypoint.sh index 42eadba..d1e0a72 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,7 +41,12 @@ _switch_to_branch() { echo "INPUT_BRANCH value: $INPUT_BRANCH"; # Fetch remote to make sure that repo can be switched to the right branch. - git fetch --depth=3; + + if "$INPUT_SKIP_FETCH"; then + echo "::debug::git-fetch has not been executed"; + else + git fetch --depth=3; + fi # Switch to branch from current Workflow run # shellcheck disable=SC2086 diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index ee381a9..963ad42 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -21,6 +21,7 @@ setup() { export INPUT_TAGGING_MESSAGE="" export INPUT_PUSH_OPTIONS="" export INPUT_SKIP_DIRTY_CHECK=false + export INPUT_SKIP_FETCH=false # Configure Git if [[ -z $(git config user.name) ]]; then @@ -297,3 +298,16 @@ git_auto_commit() { run git ls-remote --tags --refs assert_output --partial refs/tags/v2.0.0 } + +@test "If SKIP_FETCH is true git-fetch will not be called" { + + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt + + INPUT_SKIP_FETCH=true + + run git_auto_commit + + assert_success + + assert_line "::debug::git-fetch has not been executed" +} From b53a2f8baf51055d691e380828085b7e8825ce1c Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 15 Dec 2020 20:30:42 +0100 Subject: [PATCH 3/4] Set --depth to 1 --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d1e0a72..0d11b03 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,7 +45,7 @@ _switch_to_branch() { if "$INPUT_SKIP_FETCH"; then echo "::debug::git-fetch has not been executed"; else - git fetch --depth=3; + git fetch --depth=1; fi # Switch to branch from current Workflow run From 292ae30da667eb2a35987eb45f74429fa1f816da Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 15 Dec 2020 20:45:42 +0100 Subject: [PATCH 4/4] Add skip_fetch to README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97fec33..abc44dc 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,10 @@ This is a more extended example with all possible options. push_options: '--force' # Optional: Disable dirty check and always try to create a commit and push - skip_dirty_check: true + skip_dirty_check: true + + # Optional: Skip internal call to `git fetch` + skip_fetch: true ``` ## Example