summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.idea/codeStyles/Project.xml15
-rwxr-xr-x[-rw-r--r--]hooks/pre-commit50
-rwxr-xr-xhooks/setup-hooks4
3 files changed, 52 insertions, 17 deletions
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 49f1221..b66e2e7 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -20,7 +20,7 @@
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
- <package name="kotlinx.android.synthetic" withSubpackages="true" static="false" />
+ <package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
@@ -36,6 +36,9 @@
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
+ <MarkdownNavigatorCodeStyleSettings>
+ <option name="RIGHT_MARGIN" value="72" />
+ </MarkdownNavigatorCodeStyleSettings>
<codeStyleSettings language="Groovy">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
@@ -155,21 +158,17 @@
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
+ <option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
+ <option name="LINE_COMMENT_ADD_SPACE" value="true" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
- <option name="METHOD_PARAMETERS_WRAP" value="5" />
- <option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
- <option name="LINE_COMMENT_ADD_SPACE" value="true" />
- <option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
- <option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="FIELD_ANNOTATION_WRAP" value="1" />
<option name="VARIABLE_ANNOTATION_WRAP" value="1" />
<indentOptions>
- <option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
-</component>
+</component> \ No newline at end of file
diff --git a/hooks/pre-commit b/hooks/pre-commit
index 00d361b..6e0b167 100644..100755
--- a/hooks/pre-commit
+++ b/hooks/pre-commit
@@ -1,14 +1,46 @@
-#!/bin/sh
+#!/bin/bash
-./gradlew spotlessCheck -q
-EXIT_CODE=$?
-if [ $EXIT_CODE -ne 0 ]; then
- echo "❌ spotlessCheck failed, running spotlessApply for you..."
+filesToAddAfterFormatting=()
+containsSpotlessEnabledFormats=0
- ./gradlew spotlessApply -q
+# Collect all files currently in staging area, and check if there are any spotless enabled format file
+# We currently support only *.kt, *.gradle', '*.md', '.gitignore' files.
+for entry in $(git status --porcelain | sed -r 's/[ \t]+/-/g'); do
+ # entry can be for example:
+ # MM-src/main/java/net/project/MyController.java
+ # -M-src/main/java/net/project/AnotherController.java
- echo "Formatting done, please try your commit again! If the problem persists, apply fixes manually."
- exit $EXIT_CODE
+ if [[ $entry == M* ]]; then
+ filesToAddAfterFormatting+=(${entry:2}) # strips the prefix
+ fi
+
+ if [[ $entry == *.kt ]] || [[ $entry == *.gradle ]] || [[ $entry == *.md ]] || [[ $entry == .gitignore ]]; then
+ containsSpotlessEnabledFormats=1
+ fi
+done
+
+# If any java or kotlin files are found, run spotlessApply
+if [ "$containsSpotlessEnabledFormats" == "1" ]; then
+ echo '[git hook] executing gradle spotlessCheck before commit'
+ ./gradlew spotlessCheck
+ EXIT_CODE=$?
+ if [ $EXIT_CODE -ne 0 ]; then
+ echo "❌ [git hook] spotlessCheck failed, running spotlessApply for you..."
+
+ ./gradlew spotlessApply
+
+ echo "[git hook] Formatting done, please try your commit again! If the problem persists, apply fixes manually."
+ exit $EXIT_CODE
+ fi
+ echo "✔️ [git hook] Spotless: Everything looks clean!"
+else
+ echo "[git hook] Not running spotless"
fi
-exit 0 \ No newline at end of file
+# Add the files that were in the staging area
+for file in "${filesToAddAfterFormatting[@]}"; do
+ echo "re-adding $file after formatting"
+ git add "$file"
+done
+
+exit 0
diff --git a/hooks/setup-hooks b/hooks/setup-hooks
new file mode 100755
index 0000000..4f48be0
--- /dev/null
+++ b/hooks/setup-hooks
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# This script setups symlink from .git/hooks directory to this directory.
+ln -s -f ../../hooks/pre-commit .git/hooks/pre-commit \ No newline at end of file