refactor(build-logic): make GitHooksTask
more lazy
This commit is contained in:
parent
fe666e9ecb
commit
48ae52f9cf
3 changed files with 18 additions and 10 deletions
|
@ -11,8 +11,8 @@ class GitHooksPlugin : Plugin<Project> {
|
|||
override fun apply(project: Project) {
|
||||
project.tasks.register<GitHooks>("installGitHooks") {
|
||||
val projectDirectory = project.layout.projectDirectory
|
||||
hookScript.set(projectDirectory.file("scripts/pre-push-hook.sh").asFile.readText())
|
||||
hookOutput.set(projectDirectory.file(".git/hooks/pre-push").asFile)
|
||||
hookSource.set(projectDirectory.file("scripts/pre-push-hook.sh"))
|
||||
hookOutput.set(projectDirectory.file(".git/hooks/pre-push"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
package app.passwordstore.gradle.tasks
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE
|
||||
import java.nio.file.attribute.PosixFilePermission.GROUP_READ
|
||||
import java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE
|
||||
|
@ -15,23 +15,31 @@ import java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE
|
|||
import java.nio.file.attribute.PosixFilePermission.OWNER_READ
|
||||
import java.nio.file.attribute.PosixFilePermission.OWNER_WRITE
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.PathSensitive
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
@CacheableTask
|
||||
abstract class GitHooks : DefaultTask() {
|
||||
@get:Input abstract val hookScript: Property<String>
|
||||
@get:InputFile
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
abstract val hookSource: RegularFileProperty
|
||||
|
||||
@get:OutputFile abstract val hookOutput: Property<File>
|
||||
@get:OutputFile abstract val hookOutput: RegularFileProperty
|
||||
|
||||
@TaskAction
|
||||
fun install() {
|
||||
hookOutput.get().writeText(hookScript.get())
|
||||
Files.copy(
|
||||
hookSource.asFile.get().toPath(),
|
||||
hookOutput.asFile.get().toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
)
|
||||
Files.setPosixFilePermissions(
|
||||
hookOutput.get().toPath(),
|
||||
hookOutput.asFile.get().toPath(),
|
||||
setOf(
|
||||
OWNER_READ,
|
||||
OWNER_WRITE,
|
||||
|
|
|
@ -4,7 +4,7 @@ set -e
|
|||
set -u
|
||||
set -o pipefail
|
||||
|
||||
ZERO=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
||||
ZERO="0000000000000000000000000000000000000000"
|
||||
GRADLE_EXEC="${GRADLE_EXEC:-./gradlew}"
|
||||
|
||||
while read local_ref local_oid remote_ref remote_oid; do
|
||||
|
|
Loading…
Reference in a new issue