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

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

Open
mjustin opened this issue Mar 29, 2022 · 0 comments

Comments

@mjustin
Copy link

mjustin commented Mar 29, 2022

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 #14 (comment). 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")))
        }
    }
}
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

1 participant