1
1
#! /bin/bash
2
2
3
- #! /bin/bash
4
-
5
3
# -----------------------------------------------------------------------------
6
4
# Script to format files in repos with improved git error handling
7
5
# -----------------------------------------------------------------------------
@@ -93,6 +91,13 @@ done < "$REPO_LIST"
93
91
> " $LOG_FILE "
94
92
# > "$LONG_LINES_LOG_FILE"
95
93
94
+ # Check for idempotent mode flag
95
+ IDEMPOTENT_MODE= false
96
+ if [ " $1 " == " --idempotent" ]; then
97
+ IDEMPOTENT_MODE=true
98
+ echo " Idempotent testing mode activated."
99
+ fi
100
+
96
101
# Function to format files and log errors with clear info
97
102
format_files () {
98
103
local FILE_PATH=" $1 "
@@ -129,7 +134,30 @@ format_files() {
129
134
# echo "$OUTPUT" | grep -E "$PATTERN" >> "$LONG_LINES_LOG_FILE"
130
135
}
131
136
137
+ idempotent_test () {
138
+ local FILE_PATH=" $1 "
139
+ TMP1=$( mktemp)
140
+ TMP2=$( mktemp)
141
+
142
+ # Format once and save output to TMP1
143
+ $FORMATTER_BINARY " $FILE_PATH " > " $TMP1 " 2> /dev/null
144
+
145
+ # Format the result of the first formatting and save to TMP2
146
+ $FORMATTER_BINARY " $TMP1 " > " $TMP2 " 2> /dev/null
147
+
148
+ # Compare the two outputs
149
+ if ! diff -q " $TMP1 " " $TMP2 " & > /dev/null; then
150
+ echo " Idempotency test failed for $FILE_PATH " >> " $LOG_FILE "
151
+ echo " Difference found in idempotency test for: $FILE_PATH "
152
+ else
153
+ echo " Idempotency test passed for $FILE_PATH "
154
+ fi
155
+
156
+ rm -f " $TMP1 " " $TMP2 "
157
+ }
158
+
132
159
export -f format_files
160
+ export -f idempotent_test
133
161
export FORMATTER_BINARY
134
162
export LOG_FILE
135
163
# export LONG_LINES_LOG_FILE
@@ -142,6 +170,13 @@ START_TIME=$(date +%s)
142
170
find " $TARGET_DIR " \( -t ype d \( -n ame " .sfdx" -o -n ame " scripts" \) \) -p rune -o -t ype f \( -n ame " *.cls" -o -n ame " *.trigger" \) -p rint0 | \
143
171
parallel -0 -j+0 format_files
144
172
173
+ # Run idempotent testing if mode is activated
174
+ if [ " $IDEMPOTENT_MODE " = true ]; then
175
+ echo " Running idempotency tests..."
176
+ find " $TARGET_DIR " \( -type d \( -name " .sfdx" -o -name " scripts" \) \) -prune -o -type f \( -name " *.cls" -o -name " *.trigger" \) -print0 | \
177
+ parallel -0 -j+0 idempotent_test
178
+ fi
179
+
145
180
# find "$TARGET_DIR" -path "$TARGET_DIR/.sfdx" -prune -o -type f \( -name "*.cls" -o -name "*.trigger" \) -print0 | \
146
181
# parallel -0 -j+0 format_files
147
182
0 commit comments