Kotlin / dataframe

Structured data processing in Kotlin
https://kotlin.github.io/dataframe/overview.html
Apache License 2.0
768 stars 48 forks source link

Incorrect permission setting for the pre-commit file #612

Closed devcrocod closed 3 months ago

devcrocod commented 4 months ago

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)

Jolanrensen commented 4 months ago

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.

devcrocod commented 4 months ago

To commit, I manually call chmod 755 .git/hooks/pre-commit

devcrocod commented 4 months ago

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

Jolanrensen commented 4 months ago

so... looks like fileMode doesn't work as expected on MacOS

Jolanrensen commented 4 months ago

@devcrocod can you try fileMode = 0b1011110011

devcrocod commented 4 months ago

It didn't help(

Jolanrensen commented 4 months ago

@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.")
    }
}
devcrocod commented 4 months ago

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

Jolanrensen commented 4 months ago

yeah, it needs execute permission, so something like -rwx-r-xr-x, which, if my math is correct is 755

Jolanrensen commented 3 months ago

Can be reproduced on Linux sometimes too.

phanlezz commented 2 months ago

It didn't help( @Jolanrensen

@devcrocod can you try fileMode = 0b1011110011

For us 0b111101101 worked :) so a literal translation of 7-5-5

In our case the rights were not correctly assigned for the start scripts to our projects.