Skip to content

Commit 3cc016c

Browse files
Merge pull request #375 from stefanzweifel/v6-next
2 parents ddb7ae4 + 7618051 commit 3cc016c

File tree

6 files changed

+128
-117
lines changed

6 files changed

+128
-117
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717

1818
steps:
1919
- uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.head_ref }}
2022

2123
- name: Use git-auto-commit-action
2224
id: "auto-commit-action"

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ The following is an extended example with all available options.
6262
# Defaults to "Apply automatic changes"
6363
commit_message: Automated Change
6464
65-
# Optional. Local and remote branch name where commit is going to be pushed
66-
# to. Defaults to the current branch.
67-
# You might need to set `create_branch: true` if the branch does not exist.
65+
# Optional. Remote branch name where commit is going to be pushed to.
66+
# Defaults to the current branch.
6867
branch: feature-123
6968
7069
# Optional. Options used by `git-commit`.
@@ -105,20 +104,11 @@ The following is an extended example with all available options.
105104

106105
# Optional. Disable dirty check and always try to create a commit and push
107106
skip_dirty_check: true
108-
109-
# Optional. Skip internal call to `git fetch`
110-
skip_fetch: true
111-
112-
# Optional. Skip internal call to `git checkout`
113-
skip_checkout: true
114107

115108
# Optional. Prevents the shell from expanding filenames.
116109
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
117110
disable_globbing: true
118111

119-
# Optional. Create given branch name in local and remote repository.
120-
create_branch: true
121-
122112
# Optional. Creates a new tag and pushes it to remote without creating a commit.
123113
# Skips dirty check and changed files. Must be used with `tagging_message`.
124114
create_git_tag_only: false
@@ -422,7 +412,6 @@ The steps in your workflow might look like this:
422412
commit_message: ${{ steps.last-commit.outputs.message }}
423413
commit_options: '--amend --no-edit'
424414
push_options: '--force'
425-
skip_fetch: true
426415
```
427416
428417
See discussion in [#159](https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950) for details.

UPGRADING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Upgrading
2+
3+
## From v5 to v6
4+
5+
The following options have been removed from git-auto-commit and can be removed from your workflows.
6+
7+
- `create_branch` (git-auto-commit no longer switches branches locally during a workflow run)
8+
- `skip_fetch`
9+
- `skip_checkout`
10+

action.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,28 @@ 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
6759
disable_globbing:
6860
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
6961
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
7362
create_git_tag_only:
7463
description: Perform a clean git tag and push, without commiting anything
7564
required: false
7665
default: false
7766
internal_git_binary:
7867
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
7968
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
80+
8081

8182
outputs:
8283
changes_detected:

entrypoint.sh

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,26 @@ _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+
3042
_check_if_git_is_available
3143

3244
_switch_to_repository
45+
46+
_check_if_is_git_repository
47+
48+
_check_if_repository_is_in_detached_state
49+
3350
if "$INPUT_CREATE_GIT_TAG_ONLY"; then
3451
_log "debug" "Create git tag only";
3552
_set_github_output "create_git_tag_only" "true"
@@ -39,8 +56,6 @@ _main() {
3956

4057
_set_github_output "changes_detected" "true"
4158

42-
_switch_to_branch
43-
4459
_add_files
4560

4661
# Check dirty state of repo again using git-diff.
@@ -90,36 +105,25 @@ _git_is_dirty() {
90105
gitStatusMessage="$((git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}} >/dev/null ) 2>&1)";
91106
# shellcheck disable=SC2086
92107
gitStatus="$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})";
93-
if [ $? -ne 0 ]; then
94-
_log "error" "git-status failed with:<$gitStatusMessage>";
95-
exit 1;
96-
fi
97108
[ -n "$gitStatus" ]
98109
}
99110
100-
_switch_to_branch() {
101-
echo "INPUT_BRANCH value: $INPUT_BRANCH";
102-
103-
# Fetch remote to make sure that repo can be switched to the right branch.
104-
if "$INPUT_SKIP_FETCH"; then
105-
_log "debug" "git-fetch will not be executed.";
111+
_check_if_is_git_repository() {
112+
if [ -d ".git" ]; then
113+
_log "debug" "Repository found.";
106114
else
107-
git fetch --depth=1;
115+
_log "error" "Not a git repository. Please make sure to run this action in a git repository. Adjust the `repository` input if necessary.";
116+
exit 1;
108117
fi
118+
}
109119
110-
# If `skip_checkout`-input is true, skip the entire checkout step.
111-
if "$INPUT_SKIP_CHECKOUT"; then
112-
_log "debug" "git-checkout will not be executed.";
120+
_check_if_repository_is_in_detached_state() {
121+
if [ -z "$(git symbolic-ref HEAD)" ]
122+
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;
113125
else
114-
# Create new local branch if `create_branch`-input is true
115-
if "$INPUT_CREATE_BRANCH"; then
116-
# shellcheck disable=SC2086
117-
git checkout -B $INPUT_BRANCH --;
118-
else
119-
# Switch to branch from current Workflow run
120-
# shellcheck disable=SC2086
121-
git checkout $INPUT_BRANCH --;
122-
fi
126+
_log "debug" "Repository is on a branch.";
123127
fi
124128
}
125129
@@ -168,6 +172,8 @@ _tag_commit() {
168172
169173
_push_to_github() {
170174
175+
echo "INPUT_BRANCH value: $INPUT_BRANCH";
176+
171177
echo "INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS}";
172178
_log "debug" "Apply push options ${INPUT_PUSH_OPTIONS}";
173179

0 commit comments

Comments
 (0)