summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt4
-rw-r--r--build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt22
-rw-r--r--scripts/pre-push-hook.sh2
3 files changed, 18 insertions, 10 deletions
diff --git a/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt b/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt
index 0b2b299c..f1b7c39d 100644
--- a/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt
+++ b/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/GitHooksPlugin.kt
@@ -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"))
}
}
}
diff --git a/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt b/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt
index f563ada0..37fad7ef 100644
--- a/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt
+++ b/build-logic/automation-plugins/src/main/kotlin/app/passwordstore/gradle/tasks/GitHooks.kt
@@ -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,
diff --git a/scripts/pre-push-hook.sh b/scripts/pre-push-hook.sh
index c19d5aa6..9cfbc9e1 100644
--- a/scripts/pre-push-hook.sh
+++ b/scripts/pre-push-hook.sh
@@ -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