aboutsummaryrefslogtreecommitdiff
path: root/git_hooks_deploy.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-17 11:54:14 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-17 11:54:14 +0800
commit5dc1cbdb7f7aa9aad7592595147a36bf7db09187 (patch)
tree1fac0e4e1e9bcb4ed6520823edf9ac1f49136ed9 /git_hooks_deploy.go
parentgit_hooks_handle.go: Move from git_hooks.go (diff)
downloadforge-5dc1cbdb7f7aa9aad7592595147a36bf7db09187.tar.gz
forge-5dc1cbdb7f7aa9aad7592595147a36bf7db09187.tar.zst
forge-5dc1cbdb7f7aa9aad7592595147a36bf7db09187.zip
git_hooks_deploy.go: Deploy hooks to filesystem
Diffstat (limited to '')
-rw-r--r--git_hooks_deploy.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/git_hooks_deploy.go b/git_hooks_deploy.go
new file mode 100644
index 0000000..01be550
--- /dev/null
+++ b/git_hooks_deploy.go
@@ -0,0 +1,50 @@
+package main
+
+import (
+ "errors"
+ "io"
+ "os"
+ "path/filepath"
+)
+
+func deploy_hooks_to_filesystem() (err error) {
+ err = func() error {
+ src_fd, err := resources_fs.Open("git_hooks_client/git_hooks_client")
+ if err != nil {
+ return err
+ }
+ defer src_fd.Close()
+
+ dst_fd, err := os.OpenFile(filepath.Join(config.Hooks.Execs, "git_hooks_client"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755)
+ if err != nil {
+ return err
+ }
+ defer dst_fd.Close()
+
+ _, err = io.Copy(dst_fd, src_fd)
+ if err != nil {
+ return err
+ }
+
+ return nil
+ }()
+ if err != nil {
+ return err
+ }
+
+ err = os.Chmod(filepath.Join(config.Hooks.Execs, "git_hooks_client"), 0755)
+ if err != nil {
+ return err
+ }
+
+ for _, hook_name := range []string{
+ "pre-receive",
+ } {
+ err = os.Symlink(filepath.Join(config.Hooks.Execs, "git_hooks_client"), filepath.Join(config.Hooks.Execs, hook_name))
+ if err != nil && !errors.Is(err, os.ErrExist) {
+ return err
+ }
+ }
+
+ return nil
+}