Skip to content

Commit a88dc49

Browse files
Merge pull request #388 from stefanzweifel/v7-next
2 parents a531dec + acbe8b1 commit a88dc49

File tree

4 files changed

+361
-91
lines changed

4 files changed

+361
-91
lines changed

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: 12 additions & 12 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:
@@ -88,7 +88,7 @@ outputs:
8888
description: Value is "true", if a git tag was created using the `create_git_tag_only`-input.
8989

9090
runs:
91-
using: 'node20'
91+
using: 'node24'
9292
main: 'index.js'
9393

9494
branding:

entrypoint.sh

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,13 @@ _log() {
2727
}
2828

2929
_main() {
30-
if "$INPUT_SKIP_FETCH"; then
31-
_log "warning" "git-auto-commit: skip_fetch has been removed in v6. It does not have any effect anymore.";
32-
fi
33-
34-
if "$INPUT_SKIP_CHECKOUT"; then
35-
_log "warning" "git-auto-commit: skip_checkout has been removed in v6. It does not have any effect anymore.";
36-
fi
37-
38-
if "$INPUT_CREATE_BRANCH"; then
39-
_log "warning" "git-auto-commit: create_branch has been removed in v6. It does not have any effect anymore.";
40-
fi
41-
4230
_check_if_git_is_available
4331

4432
_switch_to_repository
4533

4634
_check_if_is_git_repository
4735

48-
# _check_if_repository_is_in_detached_state
36+
_check_if_repository_is_in_detached_state
4937

5038
if "$INPUT_CREATE_GIT_TAG_ONLY"; then
5139
_log "debug" "Create git tag only";
@@ -56,6 +44,8 @@ _main() {
5644

5745
_set_github_output "changes_detected" "true"
5846

47+
_switch_to_branch
48+
5949
_add_files
6050

6151
# Check dirty state of repo again using git-diff.
@@ -120,13 +110,40 @@ _check_if_is_git_repository() {
120110
_check_if_repository_is_in_detached_state() {
121111
if [ -z "$(git symbolic-ref HEAD)" ]
122112
then
123-
_log "error" "Repository is in detached HEAD state. Please make sure you check out a branch. Adjust the `ref` input accordingly.";
124-
exit 1;
113+
_log "warning" "Repository is in a detached HEAD state. git-auto-commit will likely handle this automatically. To avoid it, check out a branch using the ref option in actions/checkout.";
125114
else
126115
_log "debug" "Repository is on a branch.";
127116
fi
128117
}
129118
119+
_switch_to_branch() {
120+
echo "INPUT_BRANCH value: $INPUT_BRANCH";
121+
122+
# Fetch remote to make sure that repo can be switched to the right branch.
123+
if "$INPUT_SKIP_FETCH"; then
124+
_log "debug" "git-fetch will not be executed.";
125+
else
126+
_log "debug" "git-fetch will be executed.";
127+
git fetch --depth=1;
128+
fi
129+
130+
# If `skip_checkout`-input is true, skip the entire checkout step.
131+
if "$INPUT_SKIP_CHECKOUT"; then
132+
_log "debug" "git-checkout will not be executed.";
133+
else
134+
_log "debug" "git-checkout will be executed.";
135+
# Create new local branch if `create_branch`-input is true
136+
if "$INPUT_CREATE_BRANCH"; then
137+
# shellcheck disable=SC2086
138+
git checkout -B $INPUT_BRANCH --;
139+
else
140+
# Switch to branch from current Workflow run
141+
# shellcheck disable=SC2086
142+
git checkout $INPUT_BRANCH --;
143+
fi
144+
fi
145+
}
146+
130147
_add_files() {
131148
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
132149
_log "debug" "Apply add options ${INPUT_ADD_OPTIONS}";

0 commit comments

Comments
 (0)