Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git hook ktlintFormat not working on Windows #544

Open
fjr619 opened this issue Oct 7, 2021 · 1 comment
Open

Git hook ktlintFormat not working on Windows #544

fjr619 opened this issue Oct 7, 2021 · 1 comment

Comments

@fjr619
Copy link

fjr619 commented Oct 7, 2021

When i run the git-hook pre-commit on windows it will not do the formatting for my code, i think the problem is from internalKtlintGitFilter. Because when i delete it, it will perform well.
Notes : I just have 1 change file with broken rules to test the git-hook. And i didnt get this issue on macOS

@IlyaNerd
Copy link
Contributor

IlyaNerd commented Jan 4, 2024

Having the same case. I have MINGW64 running the git commands and what I noticed is that pre-commit gives path with forward slashes '/', but then the code in the plugin GitHook checks for project root dir, which has backslashes('\') and filters out all the input values.

Possible workaround would be to replace '/' with '\' in hook:

  FILTER_VALUE=
  case "$(uname -sr)" in
     CYGWIN*|MINGW*|MSYS*)
       # replacing '/' with '\'
       FILTER_VALUE="${CHANGED_FILES//\//\\}"
       ;;

     *)
       FILTER_VALUE=$CHANGED_FILES
       ;;
  esac

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

  ./gradlew --quiet ktlintFormat -PinternalKtlintGitFilter="$FILTER_VALUE"

IlyaNerd pushed a commit to IlyaNerd/ktlint-gradle that referenced this issue Jan 4, 2024
IlyaNerd pushed a commit to IlyaNerd/ktlint-gradle that referenced this issue Jan 10, 2024
JLLeitschuh pushed a commit that referenced this issue Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants