Skip to content

Gradlew and .git is not in the same root folder- addKtlintCheckGitPreCommitHook always successfully even i broke the rule [pre-commit] #374

@ksyamkrishnan

Description

@ksyamkrishnan

Under the same ref: #351
Hi @Tapchicoma , As per our discussions I created a new sample project and was able to reproduce the same issues. The details are provided in the readme file.

Please find the sample project here. I think the issue is with the changed file path. Can you please provide more insights on this. Also if multiple files are there in the changed files from different modules, this script will handle it.

#!/bin/sh set -e ######## KTLINT-GRADLE HOOK START ########

CHANGED_FILES="$(git --no-pager diff --name-status --no-color --cached -- public/trunk/ | awk '$1 != "D" && $2 ~ /.kts|.kt/ { print $2}')"

if [ -z "$CHANGED_FILES" ]; then echo "No Kotlin staged files." exit 0 fi;

echo "Running ktlint over these files:" echo "$CHANGED_FILES"

./public/trunk/gradlew -p ./public/trunk --quiet ktlintCheck -PinternalKtlintGitFilter="$CHANGED_FILES"

echo "Completed ktlint run."

echo "Completed ktlint hook." ######## KTLINT-GRADLE HOOK END ########

Thanks in Advance,
Syam

@Tapchicoma the changed file path coming is public/trunk/app/src/main/java/com/example/myapplication/MainActivity.kt
which is not working but if I change this to app/src/main/java/com/example/myapplication/MainActivity.kt it is working. Can you please suggest what changes we need to make to work it across?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions