Skip to content

Commit 1949701

Browse files
committed
Merge branch 'master' into pr/391
2 parents e9f84b9 + a88dc49 commit 1949701

File tree

8 files changed

+365
-96
lines changed

8 files changed

+365
-96
lines changed

.github/workflows/git-auto-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
contents: write
1717

1818
steps:
19-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@v5
2020
with:
2121
ref: ${{ github.head_ref }}
2222

.github/workflows/linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
steps:
1111
- name: Checkout Code
12-
uses: actions/checkout@v4
12+
uses: actions/checkout@v5
1313

1414
- name: Lint Code Base
1515
uses: github/super-linter@v7

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v5
1515

1616
- name: Install testing dependencies
1717
run: yarn install

.github/workflows/update-changelog.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
steps:
1818
- name: Checkout code
19-
uses: actions/checkout@v4
19+
uses: actions/checkout@v5
2020
with:
2121
ref: master
2222

README.md

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

114+
# Optional. Skip internal call to `git fetch`
115+
skip_fetch: true
116+
117+
# Optional. Skip internal call to `git checkout`
118+
skip_checkout: true
119+
114120
# Optional. Prevents the shell from expanding filenames.
115121
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
116122
disable_globbing: true
117123

124+
# Optional. Create given branch name in local and remote repository.
125+
create_branch: true
126+
118127
# Optional. Creates a new tag and pushes it to remote without creating a commit.
119128
# Skips dirty check and changed files. Must be used with `tagging_message`.
120129
create_git_tag_only: false
@@ -418,6 +427,7 @@ The steps in your workflow might look like this:
418427
commit_message: ${{ steps.last-commit.outputs.message }}
419428
commit_options: '--amend --no-edit'
420429
push_options: '--force'
430+
skip_fetch: true
421431
```
422432
423433
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
@@ -60,27 +60,27 @@ inputs:
6060
description: Skip the check if the git repository is dirty and always try to create a commit.
6161
required: false
6262
default: false
63+
skip_fetch:
64+
description: Skip the call to git-fetch.
65+
required: false
66+
default: false
67+
skip_checkout:
68+
description: Skip the call to git-checkout.
69+
required: false
70+
default: false
6371
disable_globbing:
6472
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
6573
default: false
74+
create_branch:
75+
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
76+
default: false
6677
create_git_tag_only:
6778
description: Perform a clean git tag and push, without commiting anything
6879
required: false
6980
default: false
7081
internal_git_binary:
7182
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
7283
default: git
73-
skip_fetch:
74-
description: "Deprecated: skip_fetch has been removed in v6. It does not have any effect anymore."
75-
required: false
76-
default: false
77-
skip_checkout:
78-
description: "Deprecated: skip_checkout has been removed in v6. It does not have any effect anymore."
79-
required: false
80-
default: false
81-
create_branch:
82-
description: "Deprecated: create_branch has been removed in v6. It does not have any effect anymore."
83-
default: false
8484

8585

8686
outputs:
@@ -92,7 +92,7 @@ outputs:
9292
description: Value is "true", if a git tag was created using the `create_git_tag_only`-input.
9393

9494
runs:
95-
using: 'node20'
95+
using: 'node24'
9696
main: 'index.js'
9797

9898
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)