-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: added pre-commit hook. #3112
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
48dcea6
*: added git pre commit checker
zhexuany 9b3d99e
add credits
zhexuany 14dbbf8
addressed reviwerss' comments
zhexuany 92af871
addressed reviwerss' comments
zhexuany ff685a0
Merge branch 'master' into added_pre_commit_hook
zhexuany d73c4c3
addressed reviwerss' comments
zhexuany d305cb4
Merge branch 'added_pre_commit_hook' of github.com:zhexuany/tidb into…
zhexuany 705cc99
addressed reviwerss' comments
zhexuany File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/bash | ||
# This file modified from k8s | ||
# https://github.com/kubernetes/kubernetes/blob/master/hooks/pre-commit | ||
|
||
# How to use this hook? | ||
# ln -s hooks/pre-commit .git/hooks/ | ||
# In case hook is not executable | ||
# chmod +x .git/hooks/pre-commit | ||
|
||
readonly reset=$(tput sgr0) | ||
readonly red=$(tput bold; tput setaf 1) | ||
readonly green=$(tput bold; tput setaf 2) | ||
|
||
exit_code=0 | ||
|
||
echo -ne "Checking that it builds..." | ||
if ! OUT=$(make 2>&1); then | ||
echo | ||
echo "${red}${OUT}" | ||
exit_code=1 | ||
else | ||
echo "${green}OK" | ||
fi | ||
echo "${reset}" | ||
|
||
echo -ne "Checking for files that need gofmt... " | ||
files_need_gofmt=() | ||
files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "^_vendor")) | ||
for file in "${files[@]}"; do | ||
# Check for files that fail gofmt. | ||
diff="$(git show ":${file}" | gofmt -s -d 2>&1)" | ||
if [[ -n "$diff" ]]; then | ||
files_need_gofmt+=("${file}") | ||
fi | ||
done | ||
|
||
if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then | ||
echo "${red}ERROR!" | ||
echo "Some files have not been gofmt'd. To fix these errors, " | ||
echo "copy and paste the following:" | ||
echo " gofmt -s -w ${files_need_gofmt[@]}" | ||
exit_code=1 | ||
else | ||
echo "${green}OK" | ||
fi | ||
echo "${reset}" | ||
|
||
echo -ne "Checking for files that need goword... " | ||
files_need_goword=() | ||
files=($(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v -e "^_vendor")) | ||
for file in "${files[@]}"; do | ||
# Check for files that fail goword. | ||
diff=$(goword ${file}) | ||
if [[ -n "$diff" ]]; then | ||
files_need_goword+=("${file}") | ||
fi | ||
done | ||
|
||
if [[ "${#files_need_goword[@]}" -ne 0 ]]; then | ||
echo "${red}ERROR!" | ||
echo "Some files may have spelling errors." | ||
# echo ${files_need_goword[@]} | ||
echo "make goword for more details" | ||
exit_code=1 | ||
else | ||
echo "${green}OK" | ||
fi | ||
echo "${reset}" | ||
|
||
if [[ "${exit_code}" != 0 ]]; then | ||
echo "${red}Aborting commit${reset}" | ||
fi | ||
exit ${exit_code} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is --diff-filter ACM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hanfei1991 https://git-scm.com/docs/git-diff#git-diff---diff-filterACDMRTUXB82308203
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got