Skip to content

Commit 03577a2

Browse files
committed
feat: add pre-commit to format po files
1 parent eda10c1 commit 03577a2

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.pre-commit-config.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Install the pre-commit hooks below with
2+
# 'pre-commit install'
3+
4+
# Auto-update the version of the hooks with
5+
# 'pre-commit autoupdate'
6+
7+
repos:
8+
- repo: local
9+
hooks:
10+
- id: format-with-powrap
11+
name: format-with-powrap
12+
entry: ./pre-commit.sh
13+
language: system

pre-commit.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
STAGEDFILES=($(git diff --cached --name-only -- '*.po' --diff-filter=ACM))
4+
echo "po files: ${STAGEDFILES[@]}"
5+
6+
NEED_FORMAT_FILES=0
7+
8+
# set the error msg color
9+
RED='\033[0;31m'
10+
NC='\033[0m' # No Color
11+
12+
if [ ${#STAGEDFILES[@]} -gt 0 ]; then
13+
for FILE in "${STAGEDFILES[@]}"; do
14+
powrap --check --quiet "$FILE"
15+
RETURN_CODE=$?
16+
if [ $RETURN_CODE -eq 1 ]; then
17+
powrap "$FILE"
18+
NEED_FORMAT_FILES=1
19+
fi
20+
done
21+
22+
if [ $NEED_FORMAT_FILES -eq 1 ]; then
23+
echo -e "${RED}Failed to commit, please add the formatted po file(s) and commit again.${NC}"
24+
exit 1
25+
fi
26+
else
27+
echo "There's no staged po files to format."
28+
fi
29+
30+
exit 0

0 commit comments

Comments
 (0)