fix: 修復 wsl install.sh 格式問題 (#78)

This commit is contained in:
Wei
2025-12-17 22:24:02 +08:00
committed by GitHub
parent fe5508228f
commit d61a0f9ffd
3 changed files with 62 additions and 15 deletions

22
.gitattributes vendored Normal file
View File

@@ -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

View File

@@ -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 <file>"
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

View File

@@ -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:]')