pre-commit with auto fixing
[anna.git] / pre-commit.sh
index 2771db8..e9ded58 100755 (executable)
@@ -93,13 +93,18 @@ test_style () {
   $ASTYLE -a -f -p -o -O -c -s2 -U -x --mode=c < $file > $newfile 2>>/dev/null
   diff "${file}" "${newfile}"
   r=$?
-  rm "${newfile}"
   if [ $r != 0 ] ; then
     echo "Code style error in '$file', please fix before commiting."
-    echo "To autofix, create a hidden file named './.fix_style' on suite root."
-pwd
-echo xxxx
-    exit 1
+    if [ -f "./.fix_style" ]; then
+      echo "Auto-fixing code style..."
+      mv $newfile $file
+    else
+      echo "To autofix, create a hidden file named './.fix_style' on suite root."
+      rm $newfile
+      exit 1
+    fi
+  else
+    rm $newfile
   fi
 }