From d19b3de0aa0b24edc28a498ee53a9642d57536ca Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 10 Mar 2021 16:38:43 +0800 Subject: [PATCH] update setup-repo.sh. --- setup-repo.sh | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/setup-repo.sh b/setup-repo.sh index bd6d350..c607b6a 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 } -- Gitee