X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=hooks%2Fpre-commit;fp=hooks%2Fpre-commit;h=f9649b36cc649bf71f80fc1f944ecd4d395a6ad8;hb=7a56cc1804edcc2bb3ca3e4a8589faf55eb03547;hp=0000000000000000000000000000000000000000;hpb=0930b5d395ef0a48d1f97f88ee533c13d0962759;p=valse.git diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..f9649b3 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,46 @@ +#!/bin/sh +# +# Hook used to indent all source files before commiting +# + +# indent / format file by type +indent() { + # getting against as the current commit + if git rev-parse --verify HEAD >/dev/null 2>&1 + then + local against=HEAD + else + # Initial commit: diff against an empty tree object + local against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 + fi + + # loop on modified files + git diff --cached --name-only $against |while read file; + do + local ext=$(expr "$file" : ".*\(\..*\)") + case $ext in + .R|.r) + __indent_R; + ;; + esac + done +} + +# Indent the file with `indent' if this is a R file +__indent_R() { + if test ! -x "$INDENT" + then + return; + fi + if test ! -f $file + then + return; + fi + + echo "Indenting " $file + echo "library(formatR);formatR::tidy_source('$file',comment=TRUE,blank=TRUE, + arrow=TRUE,brace.newline=TRUE,indent=2,width.cutoff=80,file='$file')" | R --slave + git add "$file" +} + +indent