-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make spotless pre-commit script work? Possibly? Can't verify until di…
…ffplug/spotless#2365 is fixed.
- Loading branch information
Ihor Pakharenko
committed
Dec 27, 2024
1 parent
9d2d0f9
commit 8d0bbf9
Showing
1 changed file
with
14 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |