File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -82,8 +82,15 @@ _git_is_dirty() {
82
82
echo " INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN} " ;
83
83
read -r -a INPUT_FILE_PATTERN_EXPANDED <<< " $INPUT_FILE_PATTERN" ;
84
84
85
+ # capture stderr
86
+ gitStatusMessage=" $(( git status - s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED: +${INPUT_FILE_PATTERN_EXPANDED[@]} } >/ dev/ null ) 2 >& 1 )";
85
87
# shellcheck disable=SC2086
86
- [ -n " $( git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED: +${INPUT_FILE_PATTERN_EXPANDED[@]} } ) " ]
88
+ gitStatus="$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED: +${INPUT_FILE_PATTERN_EXPANDED[@]} } )";
89
+ if [ $? -ne 0 ]; then
90
+ _log "error" "git-status failed with:<$gitStatusMessage >";
91
+ exit 1 ;
92
+ fi
93
+ [ -n "$gitStatus " ]
87
94
}
88
95
89
96
_switch_to_branch() {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ setup() {
8
8
export FAKE_LOCAL_REPOSITORY=" ${BATS_TEST_DIRNAME} /tests_local_repository"
9
9
export FAKE_REMOTE=" ${BATS_TEST_DIRNAME} /tests_remote_repository"
10
10
export FAKE_TEMP_LOCAL_REPOSITORY=" ${BATS_TEST_DIRNAME} /tests_clone_of_remote_repository"
11
+ export FAKE_FOLDER_WITHOUT_GIT_REPO=" /tmp/tests_folder_without_git_repo"
11
12
12
13
# While it is likely the GitHub hosted runners will use master as the default branch,
13
14
# locally anyone may change that. So for tests lets grab whatever is currently set
@@ -58,6 +59,7 @@ teardown() {
58
59
rm -rf " ${FAKE_LOCAL_REPOSITORY} "
59
60
rm -rf " ${FAKE_REMOTE} "
60
61
rm -rf " ${FAKE_TEMP_LOCAL_REPOSITORY} "
62
+ rm -rf " ${INPUT_REPOSITORY} "
61
63
62
64
if [ -z ${GITHUB_OUTPUT+x} ]; then
63
65
echo " GITHUB_OUTPUT is not set"
@@ -1112,3 +1114,14 @@ END
1112
1114
run git log -n 1
1113
1115
assert_output --partial $COMMIT_MESSAGE
1114
1116
}
1117
+
1118
+ @test " It exits with error message if entrypoint.sh is being run not in a git repository" {
1119
+ INPUT_REPOSITORY=" ${FAKE_FOLDER_WITHOUT_GIT_REPO} "
1120
+
1121
+ mkdir " ${INPUT_REPOSITORY} "
1122
+
1123
+ run git_auto_commit
1124
+
1125
+ assert_failure;
1126
+ assert_line " ::error::git-status failed with:<fatal: not a git repository (or any of the parent directories): .git>"
1127
+ }
You can’t perform that action at this time.
0 commit comments