Commit 897989aa authored by Anastasios Poimenidis's avatar Anastasios Poimenidis
Browse files

fix: alter pre-commit file to run spotless:apply before commiting anything

parent caa03b0f
Loading
Loading
Loading
Loading
Loading
+19 −12
Changes for .githooks/pre-commit: 19 added lines, 12 removed lines.
Original line number Diff line number Diff line
#!/bin/sh

# 1. Skip if Git is in the middle of a rebase, cherry-pick, or merge
GIT_DIR="$(git rev-parse --git-dir)"
if [ -d "$GIT_DIR/rebase-merge" ] || [ -d "$GIT_DIR/rebase-apply" ] || [ -f "$GIT_DIR/MERGE_HEAD" ]; then
    exit 0
fi

REPO_ROOT="$(git rev-parse --show-toplevel)"

STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.java$' | sed "s|^|$REPO_ROOT/|" | paste -sd, -)
# 2. Get staged Java files (relative list for git add, absolute list for Spotless)
STAGED_RELATIVE=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.java$')

if [ -z "$STAGED_FILES" ]; then
if [ -z "$STAGED_RELATIVE" ]; then
    exit 0
fi

echo "Running Spotless format check..." >&2
# Convert to absolute paths separated by commas
STAGED_ABSOLUTE=$(echo "$STAGED_RELATIVE" | sed "s|^|$REPO_ROOT/|" | paste -sd, -)

# Run spotless and route stdout/stderr so IntelliJ's UI modal captures it
OUTPUT=$(./mvnw spotless:check -DspotlessFiles="$STAGED_FILES" 2>&1)
echo "✨ Auto-formatting staged Java files with Spotless..."

# 3. Apply Spotless only to staged files
./mvnw spotless:apply -DspotlessFiles="$STAGED_ABSOLUTE"
STATUS=$?

if [ $STATUS -ne 0 ]; then
    echo "" >&2
    echo "==========================================================" >&2
    echo "❌ Spotless check failed! Unformatted code detected:" >&2
    echo "$OUTPUT" | grep -E "(\[ERROR\]|violations)" >&2
    echo "💡 Fix by running: ./mvnw spotless:apply" >&2
    echo "==========================================================" >&2
    echo "" >&2
    echo "❌ Spotless apply failed. Aborting commit." >&2
    exit 1
fi

# 4. Crucial: Re-stage the formatted files into the current commit
echo "$STAGED_RELATIVE" | xargs -r git add

exit 0
 No newline at end of file
+1 −1
Changes for src/test/resources/domain/connection/requests/domainConnectionRequest.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
{
  "serviceId": "ece47dec-16bc-4d45-a624-0729db80d1f4",
  "bindDomainIdentityId": "Acme Corporation",
  "bindDomainIdentityId": "bind domain identity id",
  "dialDomainIdentityId": "dial domain identity id",
  "address": "10.20.30.40",
  "portRanges": [{"low":80, "high":80}],