]> git.ardis.lu - git.ardis.lu/commitdiff
Remove `$GIT_DIR` from post-update hook
authorArdis Lu <ardisglu@gmail.com>
Wed, 24 Sep 2025 05:04:38 +0000 (22:04 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 24 Sep 2025 05:04:38 +0000 (22:04 -0700)
`$GIT_DIR` is not set on the first push to a new repo. Instead, use the proper git command to avoid future issues.

srv/git/git-shell-commands/init

index ca962ce64a6266d896433afb0ae049c873c78b99..a52cc561d690e57316ad4cfe48296bf114096d4f 100644 (file)
@@ -46,13 +46,14 @@ git init --bare --quiet
 
 # Create post-update hook for dumb HTTP transport, generating README for summary view,
 # and general maintenance.
-# See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_dumb_http)
+# See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_dumb_http
 # See https://git-scm.com/docs/git-maintenance
 # See https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery
+# Do not use $GIT_DIR, see https://stackoverflow.com/q/53121208/21084807
 cat > "$path/hooks/post-update" << EOL
 #!/bin/sh
 git update-server-info
-git cat-file blob HEAD:README.md | comrak --gfm > $GIT_DIR/README.html
+git cat-file blob HEAD:README.md | comrak --gfm > "$(git rev-parse --git-common-dir)/README.html"
 git maintenance run
 EOL
 chmod a+x "$path/hooks/post-update"
This page took 0.041097 seconds and 4 git commands to generate.