-
Notifications
You must be signed in to change notification settings - Fork 4
Integrate automatic code formatting with git hooks and documentation #415
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,40 @@ | ||
| # Git Hooks for xAPI Java | ||
|
|
||
| This directory contains git hooks for automating development workflows. | ||
|
|
||
| ## Available Hooks | ||
|
|
||
| ### pre-commit | ||
|
|
||
| Automatically formats Java code using the Spotify fmt-maven-plugin before committing changes. | ||
|
|
||
| **What it does:** | ||
| - Runs `./mvnw com.spotify.fmt:fmt-maven-plugin:format` to format all Java files | ||
| - Adds reformatted files to the commit automatically | ||
| - Ensures code follows the Google Java Style Guide | ||
|
|
||
| ## Installation | ||
|
|
||
| To enable these hooks, run from the repository root: | ||
|
|
||
| ```bash | ||
| ./install-git-hooks.sh | ||
| ``` | ||
|
|
||
| This configures git to use hooks from this directory instead of the default `.git/hooks/`. | ||
|
|
||
| ## Disabling Hooks | ||
|
|
||
| To disable the hooks: | ||
|
|
||
| ```bash | ||
| git config --unset core.hooksPath | ||
| ``` | ||
|
|
||
| ## Manual Formatting | ||
|
|
||
| If you prefer not to use the git hook, you can manually format code at any time: | ||
|
|
||
| ```bash | ||
| ./mvnw com.spotify.fmt:fmt-maven-plugin:format | ||
| ``` | ||
This file contains hidden or 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,26 @@ | ||
| #!/bin/bash | ||
| # Pre-commit hook for xapi-java | ||
| # Automatically formats Java code using the Spotify fmt-maven-plugin before committing | ||
|
|
||
| # Check if we're in the repository root | ||
| if [ ! -f "mvnw" ]; then | ||
| echo "Error: mvnw not found. This hook must be run from the repository root." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Running code formatter..." | ||
|
|
||
| # Run the formatter | ||
| ./mvnw com.spotify.fmt:fmt-maven-plugin:format -q | ||
|
|
||
| # Check if the formatter ran successfully | ||
| if [ $? -ne 0 ]; then | ||
| echo "Error: Code formatting failed. Please fix the issues and try again." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Add any files that were reformatted to the commit | ||
| git add -u | ||
|
|
||
| echo "Code formatting complete." | ||
| exit 0 |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,25 @@ | ||
| #!/bin/bash | ||
| # Install script for git hooks | ||
| # This script sets up git hooks for automatic code formatting | ||
|
|
||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| echo "Installing git hooks for xapi-java..." | ||
|
|
||
| # Check if we're in the repository root | ||
| if [ ! -f "$SCRIPT_DIR/mvnw" ]; then | ||
| echo "Error: This script must be run from the repository root." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Configure git to use the .githooks directory | ||
| git config core.hooksPath .githooks | ||
|
|
||
| echo "✓ Git hooks installed successfully!" | ||
| echo "" | ||
| echo "The following hooks are now active:" | ||
| echo " - pre-commit: Automatically formats Java code using fmt-maven-plugin" | ||
| echo "" | ||
| echo "To disable the hooks, run: git config --unset core.hooksPath" |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.