From d61a0f9ffdb2519e327c780958efd9d905552c0f Mon Sep 17 00:00:00 2001 From: Wei Date: Wed, 17 Dec 2025 22:24:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=BE=A9=20wsl=20install.sh=20?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=95=8F=E9=A1=8C=20(#78)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 22 ++++++++++++++++++++++ hooks/pre-commit.sh | 40 +++++++++++++++++++++++++++++++--------- install.sh | 15 +++++++++------ 3 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..31205d7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Ensure shell scripts always use LF line endings on all platforms +*.sh text eol=lf + +# Ensure Python files use LF line endings +*.py text eol=lf + +# Auto-detect text files and normalize line endings to LF +* text=auto eol=lf + +# Explicitly declare files that should always be treated as binary +*.exe binary +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.ico binary +*.mov binary +*.mp4 binary +*.mp3 binary +*.zip binary +*.gz binary +*.tar binary diff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh index 282fa2f..0336ac9 100755 --- a/hooks/pre-commit.sh +++ b/hooks/pre-commit.sh @@ -5,7 +5,7 @@ set -e # Get staged files -STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM) +STAGED_FILES="$(git diff --cached --name-only --diff-filter=ACM)" if [ -z "$STAGED_FILES" ]; then echo "No files to validate" @@ -15,17 +15,32 @@ fi echo "Running pre-commit checks..." # Check Go files -GO_FILES=$(echo "$STAGED_FILES" | grep '\.go$' || true) +GO_FILES="$(printf '%s\n' "$STAGED_FILES" | grep '\.go$' || true)" if [ -n "$GO_FILES" ]; then echo "Checking Go files..." + if ! command -v gofmt &> /dev/null; then + echo "❌ gofmt not found. Please install Go (gofmt is included with the Go toolchain)." + exit 1 + fi + # Format check - gofmt -l $GO_FILES | while read -r file; do + GO_FILE_ARGS=() + while IFS= read -r file; do if [ -n "$file" ]; then - echo "❌ $file needs formatting (run: gofmt -w $file)" + GO_FILE_ARGS+=("$file") + fi + done <<< "$GO_FILES" + + if [ "${#GO_FILE_ARGS[@]}" -gt 0 ]; then + UNFORMATTED="$(gofmt -l "${GO_FILE_ARGS[@]}")" + if [ -n "$UNFORMATTED" ]; then + echo "❌ The following files need formatting:" + echo "$UNFORMATTED" + echo "Run: gofmt -w " exit 1 fi - done + fi # Run tests if command -v go &> /dev/null; then @@ -38,19 +53,26 @@ if [ -n "$GO_FILES" ]; then fi # Check JSON files -JSON_FILES=$(echo "$STAGED_FILES" | grep '\.json$' || true) +JSON_FILES="$(printf '%s\n' "$STAGED_FILES" | grep '\.json$' || true)" if [ -n "$JSON_FILES" ]; then echo "Validating JSON files..." - for file in $JSON_FILES; do + if ! command -v jq &> /dev/null; then + echo "❌ jq not found. Please install jq to validate JSON files." + exit 1 + fi + while IFS= read -r file; do + if [ -z "$file" ]; then + continue + fi if ! jq empty "$file" 2>/dev/null; then echo "❌ Invalid JSON: $file" exit 1 fi - done + done <<< "$JSON_FILES" fi # Check Markdown files -MD_FILES=$(echo "$STAGED_FILES" | grep '\.md$' || true) +MD_FILES="$(printf '%s\n' "$STAGED_FILES" | grep '\.md$' || true)" if [ -n "$MD_FILES" ]; then echo "Checking markdown files..." # Add markdown linting if needed diff --git a/install.sh b/install.sh index a90f87a..6469962 100644 --- a/install.sh +++ b/install.sh @@ -1,12 +1,15 @@ #!/bin/bash set -e -echo "⚠️ WARNING: install.sh is LEGACY and will be removed in future versions." -echo "Please use the new installation method:" -echo " python3 install.py --install-dir ~/.claude" -echo "" -echo "Continuing with legacy installation in 5 seconds..." -sleep 5 +if [ -z "${SKIP_WARNING:-}" ]; then + echo "⚠️ WARNING: install.sh is LEGACY and will be removed in future versions." + echo "Please use the new installation method:" + echo " python3 install.py --install-dir ~/.claude" + echo "" + echo "Set SKIP_WARNING=1 to bypass this message" + echo "Continuing with legacy installation in 5 seconds..." + sleep 5 +fi # Detect platform OS=$(uname -s | tr '[:upper:]' '[:lower:]')