Skip to content

Commit

Permalink
Make spotless pre-commit script work? Possibly? Can't verify until di…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihor Pakharenko committed Dec 27, 2024
1 parent 9d2d0f9 commit 8d0bbf9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions spotless/pre-commit
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#!/bin/sh

# Runs spotlessApply on staged changes. This script is intended to be used as a pre-commit hook.
# To use it, copy this script to .git/hooks/pre-commit and make it executable.
# For more samples / inspiration check:
# https://github.com/diffplug/spotless/issues/178
# https://github.com/diffplug/spotless/issues/623
#
# Can't reliably verify if it works until
# https://github.com/diffplug/spotless/issues/2365
# Is fixed

#!/usr/bin/env bash
set -euo pipefail

RATCHET_REF="${HEAD^}"
if git rev-parse --verify HEAD >/dev/null 2>&1
then
RATCHET_REF=HEAD
else
# Initial commit: diff against an empty tree object
RATCHET_REF=$(git hash-object -t tree /dev/null)
fi

echo "Running spotlessApply on files changed since ${RATCHET_REF}"

./gradlew --no-daemon --console=plain :spotlessApply -PratchetFrom="${RATCHET_REF}"

0 comments on commit 8d0bbf9

Please sign in to comment.