@@ -27,9 +27,26 @@ _log() {
27
27
}
28
28
29
29
_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
+
30
42
_check_if_git_is_available
31
43
32
44
_switch_to_repository
45
+
46
+ _check_if_is_git_repository
47
+
48
+ _check_if_repository_is_in_detached_state
49
+
33
50
if " $INPUT_CREATE_GIT_TAG_ONLY " ; then
34
51
_log " debug" " Create git tag only" ;
35
52
_set_github_output " create_git_tag_only" " true"
@@ -39,8 +56,6 @@ _main() {
39
56
40
57
_set_github_output " changes_detected" " true"
41
58
42
- _switch_to_branch
43
-
44
59
_add_files
45
60
46
61
# Check dirty state of repo again using git-diff.
@@ -90,36 +105,25 @@ _git_is_dirty() {
90
105
gitStatusMessage=" $(( git status - s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED: +${INPUT_FILE_PATTERN_EXPANDED[@]} } >/ dev/ null ) 2 >& 1 )";
91
106
# shellcheck disable=SC2086
92
107
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
97
108
[ -n "$gitStatus " ]
98
109
}
99
110
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.";
106
114
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 ;
108
117
fi
118
+ }
109
119
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 ;
113
125
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.";
123
127
fi
124
128
}
125
129
@@ -168,6 +172,8 @@ _tag_commit() {
168
172
169
173
_push_to_github() {
170
174
175
+ echo "INPUT_BRANCH value: $INPUT_BRANCH ";
176
+
171
177
echo "INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS} ";
172
178
_log "debug" "Apply push options ${INPUT_PUSH_OPTIONS} ";
173
179
0 commit comments