diff --git a/plugin/plugin/src/main/kotlin/net/twisterrob/gradle/vcs/GITPlugin.kt b/plugin/plugin/src/main/kotlin/net/twisterrob/gradle/vcs/GITPlugin.kt index db7cf20ab..83ae8d989 100644 --- a/plugin/plugin/src/main/kotlin/net/twisterrob/gradle/vcs/GITPlugin.kt +++ b/plugin/plugin/src/main/kotlin/net/twisterrob/gradle/vcs/GITPlugin.kt @@ -39,23 +39,24 @@ open class GITPluginExtension : VCSExtension { } override val isAvailableQuick: Boolean - get() { - // Check more than just the presence of .git to lessen the possibility of detecting "git", - // but not actually having a git repository. - val gitDir = RepositoryCache.FileKey.resolve(project.rootDir, FS.DETECTED) - return gitDir != null - } + get() = project.rootDir.resolve(".git").exists() // 'git describe --always'.execute([], project.rootDir).waitFor() == 0 override val isAvailable: Boolean - get() = try { - open().close() - true - } catch (_: FileNotFoundException) { - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=572617 - false - } catch (_: RepositoryNotFoundException) { - false + get() { + // Check more than just the presence of .git to lessen the possibility of detecting "git", + // but not actually having a git repository. + RepositoryCache.FileKey.resolve(project.rootDir, FS.DETECTED) ?: return false + return try { + // Actually try to open the repository now. + open().close() + true + } catch (_: FileNotFoundException) { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=572617 + false + } catch (_: RepositoryNotFoundException) { + false + } } // 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim() diff --git a/plugin/plugin/src/test/kotlin/net/twisterrob/gradle/vcs/GITPluginIntgTest.kt b/plugin/plugin/src/test/kotlin/net/twisterrob/gradle/vcs/GITPluginIntgTest.kt index 558aa0bf1..08f91e40a 100644 --- a/plugin/plugin/src/test/kotlin/net/twisterrob/gradle/vcs/GITPluginIntgTest.kt +++ b/plugin/plugin/src/test/kotlin/net/twisterrob/gradle/vcs/GITPluginIntgTest.kt @@ -59,17 +59,19 @@ class GITPluginIntgTest : BaseIntgTest() { result.assertHasOutputLine("""GIT revision: 2""") } - @Test fun `git works malformed git directory`() { + @Test fun `fails with malformed git directory`() { gradle.root.resolve(".git").mkdir() @Language("gradle") val script = """ apply plugin: 'net.twisterrob.vcs' println("VCS.current: " + project.VCS.current) + println("GIT revision: " + project.VCS.current.revision) """.trimIndent() - val result = gradle.run(script).withDebug(true).build() + val result = gradle.run(script).buildAndFail() - result.assertHasOutputLine("""VCS.current: ${DummyVcsExtension::class.qualifiedName}@[a-z0-9]{1,8}""".toRegex()) + result.assertHasOutputLine("""VCS.current: extension '${GITPluginExtension.NAME}'""".toRegex()) + result.assertHasOutputLine("""> repository not found: \Q${gradle.root.absolutePath}\E""".toRegex()) } /**