diff --git a/spotless/pre-commit b/spotless/pre-commit index a1ded4e..81bf946 100644 --- a/spotless/pre-commit +++ b/spotless/pre-commit @@ -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}" \ No newline at end of file