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

Gradlew not found because of outdated path in pre-push hook #269

Open
xtyrrell opened this issue Jul 4, 2022 · 5 comments
Open

Gradlew not found because of outdated path in pre-push hook #269

xtyrrell opened this issue Jul 4, 2022 · 5 comments

Comments

@xtyrrell
Copy link

xtyrrell commented Jul 4, 2022

When git pushing, with the pre-push hook installed, I got this error:

.git/hooks/pre-push: line 6: /Users/max/workspace/project-2/gradlew: No such file or directory

lintKotlin found problems, running formatKotlin; commit the result and re-push
.git/hooks/pre-push: line 8: /Users/max/workspace/project-2/gradlew: No such file or directory
error: failed to push some refs to 'gitlab.com:exampleorg/examplegroup/project.git'

I looked in the pre-push hook code and it has:

GRADLEW=/Users/max/workspace/project-2/gradlew

The error seems to be because I moved my project to a different directory, so this path is outdated and wrong now.

Hopefully this Google-searchers.

@xtyrrell
Copy link
Author

xtyrrell commented Jul 4, 2022

Is there any appetite to make this path less brittle?

One idea would be to expect gradlew to be at ../../gradlew. This would make it look for gradlew next to the .git the hook is installed in, which may or may not be a good assumption.

@xtyrrell
Copy link
Author

xtyrrell commented Jul 5, 2022

After thinking about this a bit more, I don't think that's necessary; I think that just replaces one brittle path with another.

I think the best way to handle this would be to, in the git hook script, check that the gradlew file exists before trying executing it. If not, print a clear and actionable explanation of what is going wrong and a recommended step to fix it. I would say the first step should be for the user to re-install the git hook (which would fix the hook if you've moved your project to another location) and, if that doesn't work, to open an issue here.

That would at least unblock users who cannot push because the hook broke.

We could also think about re-running installKotlinterPrePushHook task every time some other tasks run, so that if you, for example, run the build before the git hook runs, it would fix itself before you have a chance to see the error message. But I think we should start with the first solution.

@jeremymailen
Copy link
Owner

Good suggestions. I agree a clear error message would be a good start.

@TheBestPessimist
Copy link

TheBestPessimist commented Feb 3, 2023

Another suggestion, why not leave gradlew variable as ./gradlew.

Here's the broken hook on windows, because i have a space in my folders name:

#!/bin/sh
set -e
##### KOTLINTER HOOK START #####
##### KOTLINTER 3.13.0 #####
GRADLEW=D:/all/work-nagarro/Client Projects/CapacityEstimationService/gradlew.bat
if ! $GRADLEW lintKotlin ; then
    echo 1>&2 "\nlintKotlin found problems, running formatKotlin; commit the result and re-push"
    $GRADLEW formatKotlin
    exit 1
fi
##### KOTLINTER HOOK END #####

Here's how it works for me:

#!/bin/sh
set -e
##### KOTLINTER HOOK START #####
##### KOTLINTER 3.13.0 #####
GRADLEW=./gradlew
if ! $GRADLEW lintKotlin ; then
    echo 1>&2 "\nlintKotlin found problems, running formatKotlin; commit the result and re-push"
    $GRADLEW formatKotlin
    exit 1
fi
##### KOTLINTER HOOK END #####

I believe the change should be made to this file: https://github.com/jeremymailen/kotlinter-gradle/blob/6ab22c96603f2e1752b2e9d971bf9758f64caa33/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/GitHookTasks.kt.

Would you accept a MR?

@mostrovoi
Copy link

the problem would be for those multimodule projects where gradlew and .git folder are not the same. A more robust solution is needed, I am afraid

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

4 participants