-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #SB-2730: Add hook for auto format of Java code on commit
- Loading branch information
Vinaya Kumar B
committed
Apr 17, 2018
1 parent
79ef660
commit 472a77a
Showing
73 changed files
with
4,740 additions
and
4,656 deletions.
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,12 @@ | ||
#!/bin/bash | ||
|
||
REPO_ROOT_DIR="$(git rev-parse --show-toplevel)" | ||
|
||
FORMAT_JAR_LOCATION="${REPO_ROOT_DIR}/tools/java-format/google-java-format-1.5-all-deps.jar" | ||
|
||
for staged_file in $(git diff --cached --name-only); do | ||
[ -f "${staged_file}" ] || continue | ||
|
||
"${REPO_ROOT_DIR}/scripts/check-java-file-format" "${FORMAT_JAR_LOCATION}" "${staged_file}" | ||
git add "${staged_file}" | ||
done |
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,17 @@ | ||
#!/bin/sh | ||
|
||
FILES_TO_SKIP="^(src-gen|third-party|(test/.*\/testdata\/)).*\.java$" | ||
|
||
JAR_PATH=$1 | ||
FILE_PATH=$2 | ||
|
||
# Test if the file is Java file | ||
echo "${FILE_PATH}" | grep -Eqi "\.java$" || exit 1 | ||
|
||
# Test if the file should be skipped | ||
echo "${FILE_PATH}" | grep -Eqi "${FILES_TO_SKIP}" && exit 0 | ||
|
||
# Try to format the file | ||
java -jar "${JAR_PATH}" -i "${FILE_PATH}" | ||
|
||
exit 0 |
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,5 @@ | ||
#!/bin/bash | ||
|
||
REPO_ROOT_DIR="$(git rev-parse --show-toplevel)" | ||
|
||
cp "${REPO_ROOT_DIR}/git-hooks/pre-commit" "${REPO_ROOT_DIR}/.git/hooks/" |
Oops, something went wrong.