summaryrefslogtreecommitdiffstats
path: root/git-shell-commands.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-09-03 21:17:55 -0700
committerRose Hogenson <rosehogenson@posteo.net>2026-09-03 21:21:59 -0700
commit2607b7a1f6123c06ad65497d7b232137ebd6bed7 (patch)
tree311f8c338638ed8d6385b673ad85f58b4f059f26 /git-shell-commands.go
parentCreate description file with correct permissions (diff)
downloadgit-shell-commands-2607b7a1f6123c06ad65497d7b232137ebd6bed7.tar.zst
Add a post-receive hook to set repo age
Diffstat (limited to 'git-shell-commands.go')
-rw-r--r--git-shell-commands.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/git-shell-commands.go b/git-shell-commands.go
index 8348080..3f0950e 100644
--- a/git-shell-commands.go
+++ b/git-shell-commands.go
@@ -61,6 +61,25 @@ Create a new git repo named REPO.
if err := git.Run(); err != nil {
return err
}
+ infoWeb := filepath.Join(dir, "info", "web")
+ fmt.Fprintf(os.Stderr, "mkdir %s\n", shellQuote(infoWeb))
+ if err := os.Mkdir(infoWeb, 0755); err != nil {
+ return err
+ }
+ postReceiveHook := filepath.Join(dir, "hooks", "post-receive")
+ const postReceiveScript = "TZ=UTC0 git log -1 --reflog --date='format-local:%Y-%m-%d %H:%M:%S' --pretty=%cd > $GIT_DIR/info/web/last-modified"
+ fmt.Fprintf(os.Stderr, "echo %s > %s && chmod +x %[2]s\n", shellQuote(postReceiveScript), shellQuote(postReceiveHook))
+ postReceive, err := os.OpenFile(postReceiveHook, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
+ if err != nil {
+ return err
+ }
+ defer postReceive.Close()
+ if _, err := io.WriteString(postReceive, postReceiveScript+"\n"); err != nil {
+ return err
+ }
+ if err := postReceive.Close(); err != nil {
+ return err
+ }
if *d != "" {
if err := setRepoDescription(name, *d); err != nil {
return err