Last active
February 7, 2018 14:12
-
-
Save Pzixel/b10969a02c6c96cf5fc3d30573312b1e to your computer and use it in GitHub Desktop.
Setups git hooks for rustfmt and clang-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
#!/bin/sh | |
rustup component add rustfmt-preview | |
rustfmt_path=`which rustfmt` | |
echo "#!/bin/sh | |
declare -a rust_files=() | |
declare -a cpp_files=() | |
files=\$(git diff-index --name-only HEAD) | |
echo 'Formatting source files' | |
for file in \$files; do | |
if [ ! -f \"\${file}\" ]; then | |
continue | |
fi | |
if [[ \"\${file}\" == *.rs ]]; then | |
rust_files+=(\"\${file}\") | |
fi | |
if [[ \"\${file}\" =~ (\.h|\.cpp|\.cc) ]]; then | |
cpp_files+=(\"\${file}\") | |
fi | |
done | |
if [ \${#rust_files[@]} -ne 0 ]; then | |
$rustfmt_path \${rust_files[@]} & | |
fi | |
if [ \${#cpp_files[@]} -ne 0 ]; then | |
clang-format -i \${cpp_files[@]} & | |
fi | |
wait | |
changed_files=(\"\${rust_files[@]}\" \"\${cpp_files[@]}\") | |
if [ \${#changed_files[@]} -ne 0 ]; then | |
git add \${changed_files[@]} | |
echo \"Formatting done, changed files: \${changed_files[@]}\" | |
else | |
echo \"No changes, formatting skipped\" | |
fi" > .git/hooks/pre-commit | |
chmod +x .git/hooks/pre-commit | |
echo "Hooks updated" |
Может лучше переписать на скриптовом языке?
@bmusin на каком? Намекаю, что это еще и на винде должно работать. Того же питона на ней из коробки нет.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
В слове hookers в последней строке опечатка