-
-
Save ktoso/708972 to your computer and use it in GitHub Desktop.
| #!/bin/sh | |
| # | |
| # This hook will run the eclipse code formatter before any commit | |
| # to make the source look as it's supposed to look like in the repo. | |
| ECLIPSE_HOME=$HOME/eclipse | |
| STYLE_FILE=$HOME/org.eclipse.jdt.core.prefs | |
| echo "Running pre-commit hook: run-eclipse-formatter---------------------" | |
| echo "Will run eclipse formatter, using: $STYLE_FILE" | |
| echo "Listing folders to run formatter on… " | |
| code_dirs=`find . -maxdepth 3 | grep 'src/'` | |
| for dir in $code_dirs; do | |
| echo $dir; | |
| done; | |
| echo "Launching eclipse code formatter… " | |
| exec $ECLIPSE_HOME/eclipse \ | |
| -nosplash \ | |
| -application org.eclipse.jdt.core.JavaCodeFormatter \ | |
| -verbose \ | |
| -config $STYLE_FILE \ | |
| $code_dirs | |
| echo "done---------------------------------------------------------------" |
Then you can create a hooks directory in your .git folder and just name the file "pre-commit"
i have to execute .xml (code for-matter) file as part of pre-commit hook, i am using above code after changing eclipse path and file location, but this is not working with me.
showing file has been changed but i can't see the changes even after reload(refresh) the file.
and second i want to run this pre-commit hook only on modified file instead of scan complete repository. please suggest.
thanks
I can only give you a suggestion about the last point you made "i want to run this pre-commit hook only on modified file instead of scan complete repository. please suggest"
You can change:
echo "Listing folders to run formatter on… "
code_dirs=`find . -maxdepth 3 | grep 'src/'`
for dir in $code_dirs; do
echo $dir;
done;
echo "Launching eclipse code formatter… "
exec $ECLIPSE_HOME/eclipse \
-nosplash \
-application org.eclipse.jdt.core.JavaCodeFormatter \
-verbose \
-config $STYLE_FILE \
$code_dirs
with this:
echo "Listing files to run formatter on:"
files=`git status --porcelain | cut -c 4-`
for f in $files; do
echo $f;
done;
echo "Launching eclipse code formatter… "
exec $ECLIPSE_HOME/eclipse \
-nosplash \
-application org.eclipse.jdt.core.JavaCodeFormatter \
-verbose \
-config $STYLE_FILE \
$files
Note: This will also run the code formatter on newly added files.
where to find git hooks folder in ubuntu, i am unable to see .git folder .