Skip to content

Commit fa990fa

Browse files
committed
fixup! Introduce script testing
1 parent 1007e7b commit fa990fa

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

scripts/detectChangedFiles.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ while [[ $# -gt 0 ]]; do
6565
shift || true # ignore error when there are no more arguments
6666
done
6767

68+
exit_failed() {
69+
case "$0" in
70+
*/sh) return 1 ;; # Script is sourced
71+
*) exit 1 ;; # Script is executed directly
72+
esac
73+
}
74+
75+
exit_successful() {
76+
case "$0" in
77+
*/sh) return 0 ;; # Script is sourced
78+
*) exit 0 ;; # Script is executed directly
79+
esac
80+
}
81+
6882
if ${readonlyMode}; then
6983
echo -e "${COLOR_INFO}detectChangedFiles: Readonly mode activated. Change detection file won't be created.${COLOR_DEFAULT}" >&2
7084
else
@@ -74,8 +88,8 @@ fi
7488
# Check if the paths parameter exist
7589
if [ -z "${paths}" ] ; then
7690
echo 0 # 0=No change detected. The path list is empty. There is nothing to compare. Therefore assume that there are no changes.
77-
exit 0
78-
fi
91+
exit_successful
92+
fi
7993

8094
# Check all paths if they are valid files or valid directories
8195
for path in ${paths//,/ }; do
@@ -87,7 +101,7 @@ for path in ${paths//,/ }; do
87101
fi
88102
# Neither a valid directory and file
89103
echo -e "${COLOR_ERROR}detectChangedFiles: Error: Invalid path: ${path}${COLOR_DEFAULT}" >&2
90-
exit 1
104+
exit_failed
91105
done
92106

93107
# Function to get file size
@@ -157,7 +171,7 @@ if [ ! -f "${hashFilePath}" ] ; then
157171
echo -e "${COLOR_INFO}detectChangedFiles: Skipping file creation with content (=hash) ${CURRENT_FILES_HASH}${COLOR_DEFAULT}" >&2
158172
fi
159173
echo 1 # 1=Change detected and change detection file created
160-
exit 0
174+
exit_successful
161175
fi
162176

163177
# Assume that there is no change if the saved hash is equal to the current one.

0 commit comments

Comments
 (0)