Skip to content

Example of how to only check/format staged files? #335

Answered by tethridge
tethridge asked this question in Q&A
Discussion options

You must be logged in to vote

This is the pre-commit script that I have pulled together. It doesn't work because "--include-only" doesn't work like I have it. I have the list of files delimited by ':', but I get an error that the "--include-only" option doesn't exist.

If I remove "--include-only=$CHANGED_FILES" from the two lines that invoke ktfmt, then it works. However, it will check the whole project which can be slow.

#!/usr/bin/env bash
echo "Running Kotlin formatting check..."
OUTPUT="/tmp/ktfmt-$(date +%s)"
CHANGED_FILES=`git diff --name-only --cached --diff-filter=AMd | paste -sd ":" -`
./gradlew ktfmtCheck --include-only=$CHANGED_FILES  > $OUTPUT 2>&1
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
  ./gradlew ktf…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@cortinico
Comment options

@tethridge
Comment options

@cortinico
Comment options

@tethridge
Comment options

@cortinico
Comment options

Answer selected by cortinico
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants