Skip to content

Commit

Permalink
fix: create hooks folder when a shallow clone is made (closes #170)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasfara committed Apr 27, 2023
1 parent 32315ca commit 6d67ac6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal fun writeScript(
project.logger.debug("Finding the '.git' folder")
generateSequence(baseDir) { it.parentFile }.find { it.isGitFolder() }?.let {
val scriptContent = createCommitMessage(types, scopes, successMessage, failureMessage, ignoreMessageCommit)
val hooksFolder = it.resolve(".git/hooks/")
if (!hooksFolder.exists()) hooksFolder.mkdir()
it.resolve(".git/hooks/commit-msg").writeScript(scriptContent)
project.logger.debug("[ConventionalCommits] script file written in '.git/hooks/commit-msg'")
} ?: run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,33 @@ class ConventionalCommitsTest : WordSpec({
println(scriptContent)
scriptContent shouldContain "^Merge .+\$"
}
"create the hook file even if the hooks folder do not exist (issue #170)" {
val projectDirectory = tempdir()
projectDirectory.resolve(".git/").mkdirs()
projectDirectory.configureSettingsGradle { "" }
projectDirectory.configureBuildGradle {
"""
plugins {
id("it.nicolasfarabegoli.conventional-commits")
}
""".trimIndent()
}

val tasks = GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
.withProjectDir(projectDirectory)
.withArguments("tasks")
.build()
tasks.task(":tasks")?.outcome shouldBe TaskOutcome.SUCCESS

projectDirectory.resolve(".git/hooks/commit-msg").exists() shouldBe true
projectDirectory.resolve(".git/hooks/commit-msg")
.readText() shouldContain "\\e[32mCommit message meets Conventional Commit standards...\\e[0m"
// Test if `'` character is correctly escaped into `\x27`
projectDirectory.resolve(".git/hooks/commit-msg")
.readText() shouldContain "feat(login): add the \\\\x27remember me\\\\x27 button"
}
}
}
})

0 comments on commit 6d67ac6

Please sign in to comment.