Incorrect permission setting for the pre-commit file
devcrocod opened this issue · 11 comments
After cloning the repository and trying to make local changes, I encountered a problem executing a commit due to limited access rights to the pre-commit file. This results in a Permission denied
error and I can't commit:
13:02:59.977: [dataframe] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f -- plugins/dataframe-gradle-plugin/src/test/kotlin/org/jetbrains/dataframe/gradle/DataFrameReadTest.kt core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/RenderingTests.kt core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/JupyterHtmlRenderer.kt core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/json.kt build.gradle.kts
13:02:59.988: [dataframe] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false commit -F /private/var/folders/h_/ln1cbg0j01vdr_636gjcr1wc0000kt/T/git-commit-msg-.txt --
/bin/sh: .git/hooks/pre-commit: Permission denied
IDEA: IU-242.1737
macOS: 14.2.1 (23C71)
git version 2.39.3 (Apple Git-145)
Probably, setting the permissions is done differently on MacOS.
This is the function that creates the pre-commit file:
// This task installs the pre-commit hook to the local machine the first time the project is built
// The pre-commit hook contains the command to run processKDocsMain before each commit
val installGitPreCommitHook by tasks.creating(Copy::class) {
doNotTrackState(/* reasonNotToTrackState = */ "Fails on TeamCity otherwise.")
val gitHooksDir = File(rootProject.rootDir, ".git/hooks")
if (gitHooksDir.exists()) {
from(File(rootProject.rootDir, "gradle/scripts/pre-commit"))
into(gitHooksDir)
fileMode = 755
} else {
logger.lifecycle("'.git/hooks' directory not found. Skipping installation of pre-commit hook.")
}
}
Could you try setting the permissions manually? Then maybe we can create a special case for MacOS.
To commit, I manually call chmod 755 .git/hooks/pre-commit
Even if I run .gradlew
through the terminal with sudo
, I still get a file like this: --wxrw--wx 1 Pavel.Gorgulov staff 156B Mar 4 13:51 pre-commit
so... looks like fileMode
doesn't work as expected on MacOS
@devcrocod can you try fileMode = 0b1011110011
It didn't help(
@devcrocod Okay, then we'll have to go manual:
val installGitPreCommitHook by tasks.creating(Copy::class) {
doNotTrackState(/* reasonNotToTrackState = */ "Fails on TeamCity otherwise.")
val gitHooksDir = File(rootProject.rootDir, ".git/hooks")
if (gitHooksDir.exists()) {
from(File(rootProject.rootDir, "gradle/scripts/pre-commit"))
into(gitHooksDir)
fileMode = 755
if (OSType.identify() == OSType.Mac) exec {
workingDir(gitHooksDir)
commandLine("chmod", "755", "pre-commit")
}
} else {
logger.lifecycle("'.git/hooks' directory not found. Skipping installation of pre-commit hook.")
}
}
Oh, if I remove fileMode
then the following permissions are set: -rw-r--r-- 1 Pavel.Gorgulov staff 156B Mar 5 14:23 pre-commit
yeah, it needs execute permission, so something like -rwx-r-xr-x, which, if my math is correct is 755
Can be reproduced on Linux sometimes too.