gradle-git-properties icon indicating copy to clipboard operation
gradle-git-properties copied to clipboard

Do not fail build if in a linked working tree and failOnNoGitDirectory = false

Open mjustin opened this issue 3 years ago • 0 comments

Per the unfixed (but closed) #14, the build breaks when run from a Git linked working tree. This issue has been waiting on JGit issue 477475 to add support for linked working trees, and has been closed in the interim. While there has been a recent (March 2022) renewal of interest in the JGit issue, it's not clear whether this issue will finally be resolved or not, and in either event it's certainly outside the control of the maintainers of the Gradle git.properties plugin.

Until the JGit issue and #14 are fixed, the current behavior of build breakage is probably reasonable when failOnNoGitDirectory is true (the default), since that implies that having the git.properties file is something the user wants to be present strongly enough to break the build on, so being unable to generate it should lead to a failure. However, when failOnNoGitDirectory is false, it would be nice if the build didn't break when run from a Git linked working tree, even if the Gradle git.properties plugin doesn't yet support generating properties in this scenario.

Workaround

Right now, I'm able to work around this issue by putting the following in my build.gradle, per https://github.com/n0mer/gradle-git-properties/issues/14#issuecomment-1035608025. It's not ideal since it either requires me to have a different build.gradle locally, or to commit something that is only necessary because of my own local git checkout, and not something other developers on the project need.

gitProperties {
    Path dotGitPath = rootProject.layout.projectDirectory.asFile.toPath().resolve(".git")
    if (Files.isRegularFile(dotGitPath)) {
        Files.lines(dotGitPath).withCloseable { ditGitFileLines ->
            dotGitDirectory = ditGitFileLines
                    .filter { it.startsWith("gitdir: ") }
                    .map { it.substring('gitdir: '.length(), it.lastIndexOf('/.git/')) }
                    .map { project.objects.directoryProperty().convention(project.layout.projectDirectory.dir(it)) }
                    .findFirst()
                    .orElse(project.objects.directoryProperty().convention(project.layout.projectDirectory.dir(".git")))
        }
    }
}

mjustin avatar Mar 29 '22 18:03 mjustin