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 set -e
# Get staged files # 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 if [ -z "$STAGED_FILES" ]; then
echo "No files to validate" echo "No files to validate"
@@ -15,17 +15,32 @@ fi
echo "Running pre-commit checks..." echo "Running pre-commit checks..."
# Check Go files # 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 if [ -n "$GO_FILES" ]; then
echo "Checking Go files..." 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 # Format check
gofmt -l $GO_FILES | while read -r file; do GO_FILE_ARGS=()
while IFS= read -r file; do
if [ -n "$file" ]; then 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 exit 1
fi fi
done fi
# Run tests # Run tests
if command -v go &> /dev/null; then if command -v go &> /dev/null; then
@@ -38,19 +53,26 @@ if [ -n "$GO_FILES" ]; then
fi fi
# Check JSON files # 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 if [ -n "$JSON_FILES" ]; then
echo "Validating JSON files..." 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 if ! jq empty "$file" 2>/dev/null; then
echo "❌ Invalid JSON: $file" echo "❌ Invalid JSON: $file"
exit 1 exit 1
fi fi
done done <<< "$JSON_FILES"
fi fi
# Check Markdown files # 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 if [ -n "$MD_FILES" ]; then
echo "Checking markdown files..." echo "Checking markdown files..."
# Add markdown linting if needed # Add markdown linting if needed

View File

@@ -1,12 +1,15 @@
#!/bin/bash #!/bin/bash
set -e set -e
echo "⚠️ WARNING: install.sh is LEGACY and will be removed in future versions." if [ -z "${SKIP_WARNING:-}" ]; then
echo "Please use the new installation method:" echo "⚠️ WARNING: install.sh is LEGACY and will be removed in future versions."
echo " python3 install.py --install-dir ~/.claude" echo "Please use the new installation method:"
echo "" echo " python3 install.py --install-dir ~/.claude"
echo "Continuing with legacy installation in 5 seconds..." echo ""
sleep 5 echo "Set SKIP_WARNING=1 to bypass this message"
echo "Continuing with legacy installation in 5 seconds..."
sleep 5
fi
# Detect platform # Detect platform
OS=$(uname -s | tr '[:upper:]' '[:lower:]') OS=$(uname -s | tr '[:upper:]' '[:lower:]')