Skip to content

Commit 2da8d96

Browse files
committed
Restore skip_fetch, skip_checkout, create_branch
1 parent 01d77ca commit 2da8d96

3 files changed

Lines changed: 49 additions & 11 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,19 @@ The following is an extended example with all available options.
105105
# Optional. Disable dirty check and always try to create a commit and push
106106
skip_dirty_check: true
107107

108+
# Optional. Skip internal call to `git fetch`
109+
skip_fetch: true
110+
111+
# Optional. Skip internal call to `git checkout`
112+
skip_checkout: true
113+
108114
# Optional. Prevents the shell from expanding filenames.
109115
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
110116
disable_globbing: true
111117

118+
# Optional. Create given branch name in local and remote repository.
119+
create_branch: true
120+
112121
# Optional. Creates a new tag and pushes it to remote without creating a commit.
113122
# Skips dirty check and changed files. Must be used with `tagging_message`.
114123
create_git_tag_only: false
@@ -412,6 +421,7 @@ The steps in your workflow might look like this:
412421
commit_message: ${{ steps.last-commit.outputs.message }}
413422
commit_options: '--amend --no-edit'
414423
push_options: '--force'
424+
skip_fetch: true
415425
```
416426
417427
See discussion in [#159](https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950) for details.

action.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ inputs:
5656
description: Skip the check if the git repository is dirty and always try to create a commit.
5757
required: false
5858
default: false
59+
skip_fetch:
60+
description: Skip the call to git-fetch.
61+
required: false
62+
default: false
63+
skip_checkout:
64+
description: Skip the call to git-checkout.
65+
required: false
66+
default: false
5967
disable_globbing:
6068
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
6169
default: false
70+
create_branch:
71+
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
72+
default: false
6273
create_git_tag_only:
6374
description: Perform a clean git tag and push, without commiting anything
6475
required: false
6576
default: false
6677
internal_git_binary:
6778
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
6879
default: git
69-
skip_fetch:
70-
description: "Deprecated: skip_fetch has been removed in v6. It does not have any effect anymore."
71-
required: false
72-
default: false
73-
skip_checkout:
74-
description: "Deprecated: skip_checkout has been removed in v6. It does not have any effect anymore."
75-
required: false
76-
default: false
77-
create_branch:
78-
description: "Deprecated: create_branch has been removed in v6. It does not have any effect anymore."
79-
default: false
8080

8181

8282
outputs:

entrypoint.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ _main() {
5656

5757
_set_github_output "changes_detected" "true"
5858

59+
_switch_to_branch
60+
5961
_add_files
6062

6163
# Check dirty state of repo again using git-diff.
@@ -127,6 +129,32 @@ _check_if_repository_is_in_detached_state() {
127129
fi
128130
}
129131
132+
_switch_to_branch() {
133+
echo "INPUT_BRANCH value: $INPUT_BRANCH";
134+
135+
# Fetch remote to make sure that repo can be switched to the right branch.
136+
if "$INPUT_SKIP_FETCH"; then
137+
_log "debug" "git-fetch will not be executed.";
138+
else
139+
git fetch --depth=1;
140+
fi
141+
142+
# If `skip_checkout`-input is true, skip the entire checkout step.
143+
if "$INPUT_SKIP_CHECKOUT"; then
144+
_log "debug" "git-checkout will not be executed.";
145+
else
146+
# Create new local branch if `create_branch`-input is true
147+
if "$INPUT_CREATE_BRANCH"; then
148+
# shellcheck disable=SC2086
149+
git checkout -B $INPUT_BRANCH --;
150+
else
151+
# Switch to branch from current Workflow run
152+
# shellcheck disable=SC2086
153+
git checkout $INPUT_BRANCH --;
154+
fi
155+
fi
156+
}
157+
130158
_add_files() {
131159
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
132160
_log "debug" "Apply add options ${INPUT_ADD_OPTIONS}";

0 commit comments

Comments
 (0)