diff --git a/setup-repo.sh b/setup-repo.sh index bd6d350246d6087c7542f87360961cf8f692ce49..c607b6a2ec1a986a20427f54019fbf225e71e17b 100755 --- a/setup-repo.sh +++ b/setup-repo.sh @@ -88,27 +88,31 @@ function ensure_hook_is_installed() { # check if this repo is referenced in the precommit hook already repo_path=$(git rev-parse --show-toplevel) if ! grep -q "$repo_path" "$pre_commit_file"; then -echo "#!/usr/bin/env bash" >> $pre_commit_file -echo "current_repo_path=\$(git rev-parse --show-toplevel)" >> $pre_commit_file -echo "repo_to_format=\"$repo_path\"" >> $pre_commit_file -echo 'if [ "$current_repo_path" == "$repo_to_format" ]'" && [ -e $DIR/format-objc-files.sh ]; then $DIR/format-objc-files.sh -s || exit 1; fi" >> $pre_commit_file - -echo "\n\n" -echo 'echo "⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ 开始Swift矫正 ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️"' >> $pre_commit_file -echo 'FILES=$( git diff --cached --diff-filter=d --name-only | grep ".swift$" )' >> $pre_commit_file -echo 'if [ $? -eq 1 ]; then ' >> $pre_commit_file -echo 'echo "No Staged Files For Linting"' >> $pre_commit_file -echo 'exit 0' >> $pre_commit_file -echo "fi" >> $pre_commit_file -echo "Pods/SwiftLint/swiftlint autocorrect -- \$FILES" >> $pre_commit_file -echo "Pods/SwiftLint/swiftlint lint --strict \$FILES" >> $pre_commit_file -echo "RESULT=\$?" >> $pre_commit_file -echo "git add ." >> $pre_commit_file -echo 'if [ $RESULT -gt 0 ]; then' >> $pre_commit_file -echo 'echo "⬆️ ⬆️ ⬆️ ⬆️ ⬆️ ⬆️ 错误信息 ⬆️ ⬆️ ⬆️ ⬆️ ⬆️ ⬆️"' >> $pre_commit_file -echo "fi" >> $pre_commit_file -echo 'exit $RESULT' >> $pre_commit_file +echo ' +#!/usr/bin/env bash +current_repo_path=$(git rev-parse --show-toplevel) +repo_to_format="/Users/zenzz/Workspace/kfang/agent-ios" +if [ "$current_repo_path" == "$repo_to_format" ] && [ -e /Users/zenzz/Workspace/kfang/agent-ios/Pods/oc_clang_format/format-objc-files.sh ]; then /Users/zenzz/Workspace/kfang/agent-ios/Pods/oc_clang_format/format-objc-files.sh -s || exit 1; fi + + +### +echo "⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ 开始Swift矫正 ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️" +FILES=$( git diff --cached --diff-filter=d --name-only | grep ".swift$" ) +if [ $? -eq 1 ]; then + echo "No Staged Files For Linting" + exit 0 +fi + +Pods/SwiftLint/swiftlint autocorrect -- $FILES +Pods/SwiftLint/swiftlint lint --strict $FILES +RESULT=$? +git add . +if [ $RESULT -gt 0 ]; then + echo "⬆️ ⬆️ ⬆️ ⬆️ ⬆️ ⬆️ 错误信息 ⬆️ ⬆️ ⬆️ ⬆️ ⬆️ ⬆️" +fi +exit $RESULT +' > $pre_commit_file fi }