new file mode 100755
@@ -0,0 +1,31 @@
+#!/bin/sh
+rustup component add rustfmt-preview
+
+rustfmt_path=`which rustfmt`
+echo "#!/bin/bash
+declare -a rust_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
+done
+if [ \${#rust_files[@]} -ne 0 ]; then
+ $rustfmt_path \${rust_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"
Signed-off-by: Russell Currey <ruscur@russell.cc> --- setup_rustfmt_hook.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 setup_rustfmt_hook.sh