Skip to content

Commit 223fd69

Browse files
conflicted files cherry-picked manually
1 parent ae6c260 commit 223fd69

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ The following is an extended example with all available options.
5959
# Defaults to "Apply automatic changes"
6060
commit_message: Automated Change
6161
62-
# Optional. Local and remote branch name where commit is going to be pushed
63-
# to. Defaults to the current branch.
64-
# You might need to set `create_branch: true` if the branch does not exist.
62+
# Optional. Remote branch name where commit is going to be pushed to.
63+
# Defaults to the current branch.
6564
branch: feature-123
6665
6766
# Optional. Options used by `git-commit`.
@@ -102,20 +101,11 @@ The following is an extended example with all available options.
102101

103102
# Optional. Disable dirty check and always try to create a commit and push
104103
skip_dirty_check: true
105-
106-
# Optional. Skip internal call to `git fetch`
107-
skip_fetch: true
108-
109-
# Optional. Skip internal call to `git checkout`
110-
skip_checkout: true
111104

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

116-
# Optional. Create given branch name in local and remote repository.
117-
create_branch: true
118-
119109
# Optional. Creates a new tag and pushes it to remote without creating a commit.
120110
# Skips dirty check and changed files. Must be used with `tagging_message`.
121111
create_git_tag_only: false
@@ -416,7 +406,6 @@ The steps in your workflow might look like this:
416406
commit_message: ${{ steps.last-commit.outputs.message }}
417407
commit_options: '--amend --no-edit'
418408
push_options: '--force'
419-
skip_fetch: true
420409
```
421410
422411

action.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Git Auto Commit
22
description: 'Automatically commits files which have been changed during the workflow run and push changes back to remote repository.'
33

4+
author: step-security
5+
46
inputs:
57
commit_message:
68
description: Commit message
@@ -54,20 +56,9 @@ inputs:
5456
description: Skip the check if the git repository is dirty and always try to create a commit.
5557
required: false
5658
default: false
57-
skip_fetch:
58-
description: Skip the call to git-fetch.
59-
required: false
60-
default: false
61-
skip_checkout:
62-
description: Skip the call to git-checkout.
63-
required: false
64-
default: false
6559
disable_globbing:
6660
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
6761
default: false
68-
create_branch:
69-
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
70-
default: false
7162
create_git_tag_only:
7263
description: Perform a clean git tag and push, without commiting anything
7364
required: false

entrypoint.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ _main() {
4242
_check_if_git_is_available
4343

4444
_switch_to_repository
45+
46+
_check_if_is_git_repository
47+
48+
_check_if_repository_is_in_detached_state
49+
4550
if "$INPUT_CREATE_GIT_TAG_ONLY"; then
4651
_log "debug" "Create git tag only";
4752
_set_github_output "create_git_tag_only" "true"
@@ -100,11 +105,26 @@ _git_is_dirty() {
100105
gitStatusMessage="$((git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}} >/dev/null ) 2>&1)";
101106
# shellcheck disable=SC2086
102107
gitStatus="$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})";
103-
if [ $? -ne 0 ]; then
104-
_log "error" "git-status failed with:<$gitStatusMessage>";
108+
[ -n "$gitStatus" ]
109+
}
110+
111+
_check_if_is_git_repository() {
112+
if [ -d ".git" ]; then
113+
_log "debug" "Repository found.";
114+
else
115+
_log "error" "Not a git repository. Please make sure to run this action in a git repository. Adjust the `repository` input if necessary.";
105116
exit 1;
106117
fi
107-
[ -n "$gitStatus" ]
118+
}
119+
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;
125+
else
126+
_log "debug" "Repository is on a branch.";
127+
fi
108128
}
109129
110130
_add_files() {

0 commit comments

Comments
 (0)