Skip to content

Commit 437e65b

Browse files
committed
🧪 test and related fix for pre-commit hook
Signed-off-by: Adrien Kara <[email protected]>
1 parent fdc1ac1 commit 437e65b

File tree

2 files changed

+587
-25
lines changed

2 files changed

+587
-25
lines changed

pre-commit

+22-19
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ check_dnct() {
3030
return $SUCCESS
3131
fi
3232

33-
# check if the commit message has the DNCT tag
33+
# run the git diff
3434
local _spoted
35-
_spoted="$(git diff --cached --name-only --diff-filter=AM -p -G "$DNCT_REGEX")"
35+
if ! _spoted="$(git diff --cached --name-only --diff-filter=AM -p -G "$DNCT_REGEX")"; then
36+
error "Unexpected error from git diff check your repository"
37+
return $FAILURE
38+
fi
39+
40+
# check if the commit message has the DNCT tag
3641
if [[ -n $_spoted ]]; then
3742
error "DNCT tag are spoted in commit, see files below to fix it:"
3843

@@ -49,7 +54,7 @@ check_dnct() {
4954
## check_dsstore is a function to check if a DSStore file is spoted in commit
5055
check_dsstore() {
5156
# check if this flag is enabled
52-
if [[ $FILE_IGNORE_DSSTORE -eq $TRUE ]]; then
57+
if [[ $FILE_UNCACHE_DSSTORE -eq $FALSE ]]; then
5358
return $SUCCESS
5459
fi
5560

@@ -61,9 +66,8 @@ check_dsstore() {
6166
local _file="$1"
6267

6368
# check if the file is a DSStore file
64-
if [[ $_file == *"/.ds_store" ]]; then
65-
git_uncache "$_file"
66-
return $FAILURE
69+
if grep -i "\.ds_store$" <<<"$_file" >/dev/null 2>>"$LOG_FILE"; then
70+
git_uncache "$_file" || return $FAILURE
6771
fi
6872

6973
return $SUCCESS
@@ -72,7 +76,7 @@ check_dsstore() {
7276
## check_binary is a function to check if a binary file is spoted in commit
7377
check_binary() {
7478
# check if this flag is enabled
75-
if [[ $FILE_IGNORE_BINARY -eq $TRUE ]]; then
79+
if [[ $FILE_UNCACHE_BINARY -eq $FALSE ]]; then
7680
return $SUCCESS
7781
fi
7882

@@ -89,12 +93,12 @@ check_binary() {
8993
return $SUCCESS
9094
fi
9195

92-
case $FILE_IGNORE_BINARY in
96+
case $FILE_UNCACHE_BINARY in
9397
"$TRUE")
9498
git_uncache "$_file"
9599
;;
96100
"$SUPERPOSITION")
97-
interactive_remove "Executable binary" "$_file"
101+
interactive_uncache "Executable binary" "$_file"
98102
;;
99103
*)
100104
return $SUCCESS
@@ -106,7 +110,7 @@ check_binary() {
106110

107111
## check_size is a function to check if file size is greater than the limit
108112
check_size() {
109-
# check if this flag is enabled
113+
# check if this flag is disabled
110114
if [[ $FILE_MAX_SIZE -lt 1 ]]; then
111115
return $SUCCESS
112116
fi
@@ -123,22 +127,21 @@ check_size() {
123127
if ! _size=$(stat -c%s "$_file" 2>/dev/null); then
124128
return $FAILURE
125129
fi
126-
# convert it to KB
127130
_size=$((_size / 1024))
128131

129-
# check if the file size is greater than the limit
130-
# if limit is 0 or less, then no check is done
132+
# check the file size
131133
if [[ $_size -lt $FILE_MAX_SIZE ]]; then
132134
return $SUCCESS
133135
fi
134136

135-
case $FILE_SIZE_AUTOFIX in
137+
case $FILE_UNCACHE_OVERSIZE in
136138
"$TRUE")
137-
git_uncache "$_file"
139+
git_uncache "$_file" && return $SUCCESS
138140
;;
139141
"$SUPERPOSITION")
140-
interactive_remove \
141-
"${_size}KB exceeds limit of ${FILE_MAX_SIZE}KB for a" "$_file"
142+
interactive_uncache \
143+
"${_size}KB exceeds limit of ${FILE_MAX_SIZE}KB for a" "$_file" \
144+
&& return $SUCCESS
142145
;;
143146
*)
144147
return $SUCCESS
@@ -180,6 +183,6 @@ if [[ ${BASH_SOURCE[0]} -ef "$0" ]]; then
180183
continue
181184
fi
182185
done
183-
fi
184186

185-
exit $SUCCESS
187+
exit $SUCCESS
188+
fi

0 commit comments

Comments
 (0)