git / brickware / marrow.git - f79468c

(6 hours ago)commit f79468c: added hook install

Summary | History | Files

commit f79468c

authorTanner Stenson <tanner@brickware.sh>
dateThu Jan 8 15:10:24 2026 -0500

message

added hook install

diff

commit f79468cdfaf920bcc093e75cedbca1224e5b85e7
Author: Tanner Stenson <tanner@brickware.sh>
Date:   Thu Jan 8 15:10:24 2026 -0500

    added hook install

diff --git a/marrow-shell.c b/marrow-shell.c
index f55f045..e238c5e 100644
--- a/marrow-shell.c
+++ b/marrow-shell.c
@@ -196,6 +196,33 @@ create_bare_repository(const char *path) {
 
     /* Create bare git repository - redirect output to avoid interfering with git protocol */
     snprintf(command, sizeof(command), "git init --bare '%s' >/dev/null 2>&1", path);
+    if (0 != system(command)) {
+        return 0;
+    }
+
+    /* Install post-receive hook */
+    char hook_path[PATH_MAX];
+    snprintf(hook_path, sizeof(hook_path), "%s/hooks/post-receive", path);
+
+    FILE *hook_file = fopen(hook_path, "w");
+    if (!hook_file) {
+        return 0;
+    }
+
+    fprintf(hook_file,
+            "#!/bin/sh\n"
+            "REPO_PATH=\"$(pwd)\"\n"
+            "GIT_BASE_PATH=\"/srv/git\"\n"
+            "OUTPUT_DIR=\"/var/www/git\"\n"
+            "\n"
+            "REPO_NAME=\"${REPO_PATH#$GIT_BASE_PATH/}\"\n"
+            "\n"
+            "/usr/local/bin/marrow-static -D \"$GIT_BASE_PATH\" \"$OUTPUT_DIR\" \"$REPO_NAME\"\n");
+
+    fclose(hook_file);
+
+    /* Make hook executable */
+    snprintf(command, sizeof(command), "chmod +x '%s' >/dev/null 2>&1", hook_path);
     return (0 == system(command));
 }