Skip to content

DOC-14109 WIP worktree support#880

Draft
osfameron wants to merge 3 commits intomasterfrom
DOC-14109-worktree-support
Draft

DOC-14109 WIP worktree support#880
osfameron wants to merge 3 commits intomasterfrom
DOC-14109-worktree-support

Conversation

@osfameron
Copy link
Collaborator

This seems to work for me for simple cases now, but I feel like I'm missing:

  • checking if current working tree is a linked worktree.
  • the worktrees: true key

This seems to work for me for simple cases now, but I feel like I'm missing:

* checking if current working tree is a linked worktree.
* the `worktrees: true` key
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the docs preview tooling to better identify the current repo (including in worktree-like setups) and to refactor the Antora extension hook that rewrites the playbook during preview builds.

Changes:

  • Derive PREVIEW_REPO via GitHub CLI instead of inferring from the local toplevel directory name.
  • Refactor lib/preview.js to use a named rebuildPlaybook handler and add local path mapping logic intended to support worktrees.
  • Adjust the Antora --extension path to be explicitly relative (./lib/preview.js).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
scripts/preview Switches repo-name detection to gh repo view and tweaks Antora extension path.
lib/preview.js Refactors playbook rebuild hook and adds local URL/path mapping logic aimed at worktree support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

lib/preview.js Outdated
Comment on lines +83 to +100
const isMainGitDir = p => {
const pwg = `${p}/.git`
if (! fs.existsSync(pwg)) { return false }
return fs.statSync(pwg).isDirectory()
}

function mapLocalUrl (repo, url) {
for (const repoPath of args.repoPath) {
const p = path.resolve(repoPath, repo)
if (fs.existsSync(p)) {
if (isMainGitDir(p)) { return p }
// otherwise check if this directory contains worktrees
const subdir =
fs.readdirSync(p).find(
n => isMainGitDir(`${p}/${n}`))
if (subdir) {
return `${p}/${subdir}`
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isMainGitDir only treats a repo as valid when .git is a directory. Linked worktrees typically have a .git file pointing at the shared gitdir, so this logic will fail to recognize the current worktree checkout and fall back to the remote URL (triggering an unnecessary clone and breaking the intended worktree support). Adjust the detection to treat a .git file as a valid worktree (or parse git rev-parse --git-dir / git worktree list --porcelain to locate the right working tree).

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intention is that the readdir checks every file, and returns the first one that does have a main git dir.

@simon-dew
Copy link
Contributor

I checked out this PR in my local docs-site repo and ran ./scripts/preview --init.
Unfortunately, in my worktree, preview still fails with this message:

~/GitHub/docs-devex/release/7.6 (DOC-12088-udf-guides ✗) preview
🐇 Hello! I'm the Docs Build Rabbit
version 1.1.1

HTTP 401: Bad credentials (https://api.github.com/graphql)
Try authenticating with:  gh auth login
   Let's build this preview!
PREVIEW_BRANCH=DOC-12088-udf-guides
PREVIEW_REPO=
PREVIEW_START_PATH=.
PREVIEW_OVERRIDE=antora-playbook.preview.local.yml
PREVIEW_CONFIG=DOC-12088-udf-guides
PREVIEW_COMPONENT=server

[14:00:01.593] FATAL (antora): Oh no!  source not found in playbook.
        You need to add to 'antora-playbook.preview.yml' something like:

        content:
          sources:
          # add in the appropriate place
          - url: https://github.com/couchbaselabs/docs-devex.git
            branches: DOC-12088-udf-guides
            
    Cause: Error
        at notfound (/Users/simondew/GitHub/docs-site/lib/preview.js:184:12)
        at GeneratorContext.rebuildPlaybook (/Users/simondew/GitHub/docs-site/lib/preview.js:44:15)
        at Object.onceWrapper (node:events:634:26)
        at GeneratorContext.notify (/Users/simondew/GitHub/docs-site/node_modules/@antora/site-generator/lib/generator-context.js:59:49)
        at generateSite (/Users/simondew/GitHub/docs-site/node_modules/@antora/site-generator/lib/generate-site.js:11:19)
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
        at async Command.parseAsync (/Users/simondew/GitHub/docs-site/node_modules/commander/lib/command.js:936:5)

@osfameron osfameron force-pushed the DOC-14109-worktree-support branch 2 times, most recently from f010327 to a818b27 Compare March 18, 2026 16:17
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.

3 participants