💾 Archived View for log.pfad.fr › 2023 › git-clone-all-the-things captured on 2024-03-21 at 14:45:58. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-11-04)
-=-=-=-=-=-=-
TL;DR you can now run "git clone https://log.pfad.fr" to subscribe to the source of this log.
After playing with flake.nix, I noticed that I didn't want to hardcode my forge URL in the flake.nix file, just like I prefer to use a domain I control for go modules (where it is usually referred to as "vanity URL"):
Self-hosting Go documentation on vanity URL
So I dug to understand if and how I could use my domain for the flake inputs (while I am to lazy to self-host a code forge):
- vanitydoc.url = "git+https://codeberg.org/pfad.fr/vanitydoc.git"; + vanitydoc.url = "git+https://code.pfad.fr/vanitydoc";
Under the hood, nix is performing a git clone, so the problem moves to telling git how to look for the repository somewhere else. I remembered having seen some "warning: redirecting to ..." when performing a git clone, so I thought that I could put a simple HTTP redirection from "https://code.pfad.fr/vanitydoc.git" to the actual forge URL "https://codeberg.org/pfad.fr/vanitydoc.git". However, git failed with:
remote: 404 page not found
To get a more verbose output, set the GIT_CURL_VERBOSE environment variable to 1. It shows that git actually fetches an "augmented URL": https://code.pfad.fr/vanitydoc.git/info/refs?service=git-upload-pack. Redirecting the `.../info/refs` path instead of the root path led to the next error:
fatal: unable to update url base from redirection: asked for: ...
Maintaining the query parameters "?service=git-upload-pack" fixes the issue (and I can drop the ".git" suffix since the redirection does not conflict with the documentation anymore)!
git clone https://code.pfad.fr/vanitydoc Cloning into 'vanitydoc'... warning: redirecting to https://codeberg.org/pfad.fr/vanitydoc.git/ remote: Enumerating objects: ...
So if you want to redirect a git repository, make sure to redirect the info/refs path and keep the query string:
From: https://<clone-URL>/info/refs?service=git-upload-pack To: https://<forge-URL>/info/refs?service=git-upload-pack
The flake.nix now relies on a domain I control, so moving forges should not be a problem in the future.
After a night of sleep, I thought that I could also expose the source of this log under https://log.pfad.fr. During my previous adventures, I stumbled upon the git documentation about the "Dumb HTTP protocol".
Git on the Server - The Protocols > Dumb HTTP
Since I only want to expose the main branch, I added the following steps to the build pipeline of this log:
git clone --bare . -b main --single-branch dist/bare cd dist/bare git update-server-info rsync --archive info objects HEAD packed-refs ../http/
info/refs file that will be read by "git clone"
Julia Evans - In a git repository, where do your files live?
So you can now clone this log to subscribe to the source of it (articles are in the "content" folder):
git clone https://log.pfad.fr
Further reading on subscribing via git (accessible via the gemini protocol):
solderpunk: Low budget P2P content distribution with git
📅 2023-10-24