commit 5f54fb88f8c0164bd5caa12161ebbc233742b684 Author: Dasemu Date: Mon Nov 16 11:33:22 2026 +0100 chore: add phase 0 spike scripts and results Co-Authored-By: Claude Sonnet 5.5 diff --git a/LESSONS.md b/LESSONS.md new file mode 100644 index 0000000..2525e9d --- /dev/null +++ b/LESSONS.md @@ -0,0 +1,3 @@ +# Lessons + +- Forgejo push mirrors to localhost are blocked by default; set `ALLOW_LOCALNETWORKS` in throwaway test instances. diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md new file mode 100644 index 0000000..9c9a16d --- /dev/null +++ b/docs/DECISIONS.md @@ -0,0 +1,4 @@ +# Decisions + +1. Custom refs on Gitea/Forgejo: supported on Forgejo 11, no fallback needed (see `phase0-spike.md`). Real instance pending. +2-5. Open. diff --git a/docs/phase0-spike.md b/docs/phase0-spike.md new file mode 100644 index 0000000..944c45a --- /dev/null +++ b/docs/phase0-spike.md @@ -0,0 +1,23 @@ +# Phase 0 spike: custom refs on Gitea/Forgejo + +Scripts: `spikes/forgejo-up.sh` (throwaway Forgejo 11 via Podman), `spikes/snapshot.sh` +(plumbing-only snapshot), `spikes/phase0.sh` (end-to-end checks). + +## Results (Forgejo 11, local, 2026-11-16) + +| Question | Result | +|---|---| +| Push `refs/sync//` (force) | Accepted | +| Appears as a branch (API `/branches`) | No, only `main` | +| Visible via API `/git/refs` | Yes (so not fully hidden; UI not checked visually) | +| Fetchable from another clone (`+refs/sync/*:refs/sync/*`) | Yes; tree contains tracked, staged and untracked files, excludes ignored | +| Snapshot leaves branch, index and history untouched | Yes (temp `GIT_INDEX_FILE`) | +| Included by push mirror | No, mirror received only `refs/heads/main` (+HEAD) | + +Conclusion: **no fallback needed** for Forgejo. Section 7.1 design holds. + +## Caveats / pending +- Verified on Forgejo 11 only. The real instance at git.zenvairo.es (Gitea or Forgejo, version unknown) still has to be checked; needs a throwaway repo there (external effect, awaiting approval). +- UI visibility not verified visually. +- Push mirrors to a local target need `migrations.ALLOW_LOCALNETWORKS`; irrelevant for real targets. +- GitHub as a direct target of `refs/sync/*` is not tested (design never pushes them there). diff --git a/spikes/forgejo-up.sh b/spikes/forgejo-up.sh new file mode 100755 index 0000000..6c1e2af --- /dev/null +++ b/spikes/forgejo-up.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Start a throwaway Forgejo (dev only) on localhost:3300 with an admin user. +set -euo pipefail +podman rm -f gitsync-forgejo >/dev/null 2>&1 || true +podman run -d --name gitsync-forgejo -p 3300:3000 \ + -e FORGEJO__security__INSTALL_LOCK=true \ + -e FORGEJO__server__ROOT_URL=http://localhost:3300/ \ + -e FORGEJO__server__DISABLE_SSH=true \ + -e FORGEJO__database__DB_TYPE=sqlite3 \ + -e FORGEJO__mirror__ENABLED=true -e FORGEJO__migrations__ALLOW_LOCALNETWORKS=true -e FORGEJO__migrations__ALLOWED_DOMAINS=localhost \ + codeberg.org/forgejo/forgejo:11 >/dev/null +for i in $(seq 60); do curl -fs localhost:3300/api/healthz >/dev/null && break; sleep 1; done +podman exec --user git gitsync-forgejo forgejo admin user create --admin \ + --username spike --password spike-pass-123 --email spike@example.invalid --must-change-password=false diff --git a/spikes/phase0.sh b/spikes/phase0.sh new file mode 100755 index 0000000..5aa6f1e --- /dev/null +++ b/spikes/phase0.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Phase 0 spike against a local throwaway Forgejo (run spikes/forgejo-up.sh first). +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd) +API=http://localhost:3300/api/v1; AUTH=spike:spike-pass-123 +w=$(mktemp -d); cd "$w" +curl -fs -u $AUTH -H 'Content-Type: application/json' -X POST $API/user/repos \ + -d '{"name":"demo","private":true}' >/dev/null +curl -fs -u $AUTH -H 'Content-Type: application/json' -X POST $API/user/repos \ + -d '{"name":"demo-mirror","private":true}' >/dev/null +URL=http://spike:spike-pass-123@localhost:3300/spike/demo.git +git init -q -b main m1 && cd m1 +git config user.email a@b.c; git config user.name t +echo hi > a.txt; git add a.txt; git commit -qm init +git remote add origin $URL; git push -q origin main +echo "wip" > untracked.txt; echo "edit" >> a.txt; echo secret > ignored.env; echo "*.env" > .gitignore +c=$("$here/snapshot.sh" . desktop); echo "snapshot: $c" +echo "--- push refs/sync (force)" +git push -f origin "refs/sync/desktop/main:refs/sync/desktop/main" 2>&1 | tail -3 +echo "--- ls-remote"; git ls-remote origin +echo "--- API branches"; curl -fs -u $AUTH $API/repos/spike/demo/branches | python3 -c 'import sys,json;print([b["name"] for b in json.load(sys.stdin)])' +echo "--- API git refs"; curl -fs -u $AUTH "$API/repos/spike/demo/git/refs" | python3 -c 'import sys,json;print([r["ref"] for r in json.load(sys.stdin)])' +echo "--- 2nd machine fetch + restore" +cd "$w"; git clone -q $URL m2 && cd m2 +git fetch -q origin "+refs/sync/*:refs/sync/*"; git for-each-ref refs/sync +git show --stat refs/sync/desktop/main | head -12 +git ls-tree -r --name-only refs/sync/desktop/main +echo "--- push mirror to demo-mirror" +curl -s -u $AUTH -H 'Content-Type: application/json' -X POST $API/repos/spike/demo/push_mirrors \ + -d '{"remote_address":"http://localhost:3000/spike/demo-mirror.git","remote_username":"spike","remote_password":"spike-pass-123","interval":"8h","sync_on_commit":true}' | head -c 300; echo +sleep 1; curl -s -u $AUTH -X POST $API/repos/spike/demo/mirror-sync -o /dev/null -w "mirror-sync http=%{http_code}\n" +cd "$w/m1"; echo more >> a.txt; git commit -qam second; git push -q origin main; sleep 8 +echo "--- mirror refs"; git ls-remote http://spike:spike-pass-123@localhost:3300/spike/demo-mirror.git +echo "workdir: $w" diff --git a/spikes/snapshot.sh b/spikes/snapshot.sh new file mode 100755 index 0000000..1fe9e4a --- /dev/null +++ b/spikes/snapshot.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Prototype: snapshot a worktree (tracked+staged+untracked, minus ignored) +# into refs/sync// without touching branch, index or history. +# Usage: snapshot.sh +set -euo pipefail +wt=$1; machine=$2 +cd "$wt" +gitdir=$(git rev-parse --absolute-git-dir) +branch=$(git symbolic-ref --short HEAD) +ref="refs/sync/$machine/$branch" +tmp=$(mktemp); trap 'rm -f "$tmp"' EXIT +cp "$gitdir/index" "$tmp" 2>/dev/null || true +export GIT_INDEX_FILE=$tmp +git add -A +tree=$(git write-tree) +prev=$(git rev-parse -q --verify "$ref" || true) +if [ -n "$prev" ] && [ "$(git rev-parse "$prev^{tree}")" = "$tree" ]; then echo "unchanged $prev"; exit 0; fi +parents=(-p HEAD); [ -n "$prev" ] && parents+=(-p "$prev") +commit=$(git commit-tree "$tree" "${parents[@]}" -m "gitsync snapshot $machine $(date -u +%FT%TZ)") +git update-ref "$ref" "$commit" +echo "$commit"