DOC-14109 worktree support - #880
Conversation
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
There was a problem hiding this comment.
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_REPOvia GitHub CLI instead of inferring from the local toplevel directory name. - Refactor
lib/preview.jsto use a namedrebuildPlaybookhandler and add local path mapping logic intended to support worktrees. - Adjust the Antora
--extensionpath 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.
| 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}` | ||
| } |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
the intention is that the readdir checks every file, and returns the first one that does have a main git dir.
|
I checked out this PR in my local ~/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) |
f010327 to
a818b27
Compare
|
Has been tested by @harini16r who also uses Worktrees, and solves her specific issue. |
* description-block refactor with Claude. * search ui 15 * search ui 17 * Remove mobile 2.8 from prod (#903) * Remove Mobile 2.8 * also docs-mobile * Update rewrites.conf for mobile 2.8 * .NET 3.9.5 DOC-14524 * search ui 18 * search ui 19 * Template helper to slice an object Call with e.g. `[template,attachment$kv_metrics_metadata.json,with-metadata,from=0,to=250]` Assumes an object, and returns a new object with that range of keys. Used for paginating metrics metadata. * search ui 20 * search ui 21 * Adding mcp-server release 1.0 (#902) * prod-233 * 1.4 branch for docs-sdk-cxx repo DOC-14532 * Doc 14578 high priority geo fixes (#905) * DOC-14578 fold in www robots.txt recommendations * DOC-14578 split llms.txt into multiple files * create ersatz llms-full.txt * Remove duplicate Google-Extended reference * docs ui 22 * tweak llms-full.txt * Update antora/yauzl To fix broken ui-bundle unzipping in Node 26, spotted by @ggray-cb * fix --allow-git for preview install * Shallow/sparse clone couchbase-cloud in CI * comment out condition as CI not set * use gh repo clone * search ui 23 (ask AI button) * Spark 4.0 * search ui 24 adopted chatbot code into ui * search ui 25 * prod 234 * DOC-14604 remove couchbase-cloud * Staging build for removing couchbase-cloud * search ui 26 chatbot whitespace * update derived playbooks * search ui 28 highlight sharing * search ui 29 * Update Python SDK API version to 4.6.3 * Mark antora-playbook.yml with 'private' comments * add sample playbook with no private repos * Update SDK version numbers in rewrites.conf * Updating playbook to reflect changes in rosetta repo name (#911) * Updating playbook to reflect changes in rosetta repo name * Update antora-playbook.preview.diff.yml to match --------- Co-authored-by: Hakim <hakim.cassimally@couchbase.com> * JVM SDK updates DOC-14650 * search ui 30 * search UI 31 * search ui 32 (chatbot thinking ...) * preview3 playbook * preview4 playbook * preview5 playbook * fix preview4 playbook * Update script path in Antora preview playbook comments * DOC-14109 worktree support (#880) 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 Also: * Search for worktree up to 2 levels deep. * preview: quiet the local build TUI, surface the URL, drop Outlook debug flow The local `preview` build buried the one thing writers need - the preview URL(s) - under Antora's warn-level logs and several always-on extension console.log dumps, and `preview --debug` piping stdout through `tee` even suppressed Antora's own URL banner (it's gated on TTY detection). New scripts/preview-runner.js spawns Antora with JSON logs and a forced IS_TTY, classifies the stream via the regex table extracted from collate-logs.js into scripts/lib/antora-log-parser.js (collate-logs.js's own CLI behavior is unchanged, since docs-infra's workflows depend on it), and prints a clean success/failure summary with the URL(s) up front and the full log written to preview/. --debug also drops the Outlook/ AppleScript report email (we're on Gmail now) for simply opening preview/doctor/ in Finder. Also bumps the version to 1.2.0 and makes the --remote flow's warning prompts bold red, since they were easy to miss. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * preview: auto-update itself when stale, like brew/npm Nobody remembers to run `preview --update` by hand. Now, before doing anything else, the script checks its own mtime and re-runs --update (then re-execs itself with the original args) if it's >= 7 days old - configurable via PREVIEW_UPDATE_CHECK_DAYS. Also touches scripts/preview at the end of --init, since `git pull` won't bump its mtime if the pull didn't actually change that file's content. - Newer Homebrew defaults to an "ask mode" that prompts to confirm installing anything beyond exactly the named formulae, which blocked the now-unattended auto-update at `brew install gh jq yq`. Silenced with HOMEBREW_NO_ASK=1. - The "we're about to auto-update" message is now bold red (via warn) instead of cyan, so it's obvious why brew/npm activity is happening. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * prod 235 * update preview UI * Fixes for insights branch * Fixes for insights branch --------- Co-authored-by: Hakim Cassimally <Hakim.Cassimally@gmail.com> Co-authored-by: Hakim <hakim.cassimally@couchbase.com> Co-authored-by: Zeba Shireen <zeba.shireen@couchbase.com> Co-authored-by: Tim Fletcher <tim.fletcher@couchbase.com> Co-authored-by: Ray Offiah <ray.offiah@couchbase.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This seems to work for me for simple cases now, but I feel like I'm missing:
worktrees: truekey