Skip to content

Commit 8f776b4

Browse files
authored
Merge pull request #51413 from samzong/refactor/improve-lsync-script
refactor(scripts): improve robustness and readability of lsync.sh Manual merge due to impact of issue with Netlify secret scanning
2 parents 5dc80ac + 50e256e commit 8f776b4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

scripts/lsync.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ fi
1919

2020
if [ -d "$1" ] ; then
2121
SYNCED=1
22-
for f in `find $1 -name "*.md"` ; do
23-
EN_VERSION=`echo $f | sed "s/content\/.\{2,5\}\//content\/en\//g"`
24-
if [ ! -e $EN_VERSION ]; then
22+
while IFS= read -r -d '' f; do
23+
EN_VERSION=$(echo "$f" | sed "s/content\/.\{2,5\}\//content\/en\//g")
24+
if [ ! -e "$EN_VERSION" ]; then
2525
echo -e "**removed**\t$EN_VERSION"
2626
SYNCED=0
2727
continue
2828
fi
2929

30-
LASTCOMMIT=`git log -n 1 --pretty=format:%h -- $f`
31-
git diff --exit-code --numstat $LASTCOMMIT...HEAD $EN_VERSION
32-
if [ $? -ne 0 ] ; then
30+
LASTCOMMIT=$(git log -n 1 --pretty=format:%h -- "$f")
31+
if ! git diff --exit-code --numstat "$LASTCOMMIT...HEAD" -- "$EN_VERSION"; then
3332
SYNCED=0
3433
fi
35-
done
34+
done < <(find "$1" -name "*.md" -print0)
35+
3636
if [ $SYNCED -eq 1 ]; then
3737
echo "$1 is still in sync"
3838
exit 0
@@ -43,18 +43,18 @@ fi
4343
LOCALIZED="$1"
4444

4545
# Try get the English version
46-
EN_VERSION=`echo $LOCALIZED | sed "s/content\/.\{2,5\}\//content\/en\//g"`
47-
if [ ! -e $EN_VERSION ]; then
46+
EN_VERSION=$(echo "$LOCALIZED" | sed "s/content\/.\{2,5\}\//content\/en\//g")
47+
if [ ! -e "$EN_VERSION" ]; then
4848
echo "$EN_VERSION has been removed."
4949
exit 3
5050
fi
5151

5252
# Last commit for the localized path
53-
LASTCOMMIT=`git log -n 1 --pretty=format:%h -- $LOCALIZED`
53+
LASTCOMMIT=$(git log -n 1 --pretty=format:%h -- "$LOCALIZED")
5454

55-
git diff --exit-code $LASTCOMMIT...HEAD $EN_VERSION
55+
diff_output=$(git diff --quiet "$LASTCOMMIT...HEAD" -- "$EN_VERSION" || echo "changed")
5656

57-
if [ "$?" -eq 0 ]; then
57+
if [ -z "$diff_output" ]; then
5858
echo "$LOCALIZED is still in sync"
5959
exit 0
6060
fi

0 commit comments

Comments
 (0)