Skip to content

Serve git worktrees at <worktree>.<project>.OPS_DOMAIN - #46

Merged
khamer merged 9 commits into
masterfrom
worktree-support
Oct 22, 2026
Merged

khamer merged 9 commits into
masterfrom
worktree-support

Conversation

@khamer

@khamer khamer commented Oct 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Serve git worktrees from inside OPS_SITES_DIR at <worktree>.<project>.OPS_DOMAIN
  • nginx reads the worktree's host path from .git/worktrees/<wt>/gitdir and passes it to Apache via the new X-Ops-Project-Path header
  • Dashboard lists served worktrees under each project
  • Added integration test and comprehensive documentation

Changes

nginx (home/nginx/nginx.conf)

  • Added $ops_project_path variable to track the actual project/worktree path
  • Added worktree resolution logic that:
    • Extracts the worktree name from the host pattern <worktree>.<project>
    • Reads .git/worktrees/<worktree>/gitdir to find the worktree's real path
    • Validates the path is inside OPS_SITES_DIR and has no .. traversal attempts
    • Handles both absolute and relative gitdir paths (worktree.useRelativePaths)
    • Falls back to OPS_PROJECT_ALLOW_SUBDOMAINS behavior if no valid worktree is found
  • Sends X-Ops-Project-Path header to Apache

Apache (home/apache/set_docroot.lua)

  • Updated to read project path from X-Ops-Project-Path header, falling back to the project name for non-worktree requests

Dashboard (home/www/dashboard/)

  • Added getWorktrees() helper that mirrors the nginx gitdir lookup logic
  • Updated index template to list discovered worktrees as links under each project

Testing & Docs

  • Added tests/worktrees.sh: isolated integration test with its own nginx and Apache containers
  • Added design spec and implementation plan
  • Updated README with worktree setup instructions and configuration examples
  • Updated CHANGELOG

Notes

  • Worktrees do not require OPS_PROJECT_ALLOW_SUBDOMAINS to be served
  • HTTPS works automatically for any project that existed at the last ops system refresh-certs
  • No new ops configuration or mounts needed

🤖 Generated with Claude Code

khamer and others added 9 commits September 30, 2026 12:11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Git's worktree.useRelativePaths writes gitdir relative to the gitdir
file's folder; resolve it in container space and require it to stay
under /var/www/html/. Strip trailing slashes from OPS_SITES_DIR before
the prefix check. Document that a symlinked OPS_SITES_DIR must be set
to its real path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under each project, link every worktree nginx would serve at
<worktree>.<project>.OPS_DOMAIN. The gitdir lookup mirrors nginx.conf
and skips worktrees whose folder no longer exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@khamer
khamer merged commit 35a49c9 into master Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant