Skip to content

Docset name falls back to unknown-<dir> when --path points below the git root #3797

Description

@clintandrewhall

Describe the bug

When --path points at a docset that is not at the repository root, git checkout information is reported as unavailable even though the build is running inside an ordinary git checkout. DocumentationSet.Name then falls back to unknown-<sourceDirName>, and the site renders that string as the docset label.

The cause is that the --path value doubles as the ceiling for the git-root search, so the upward walk can never leave the docset directory:

https://github.com/elastic/docs-builder/blob/main/src/Elastic.Documentation.Configuration/Builder/BuildContext.cs#L114-L116

(DocumentationSourceDirectory, ConfigurationPath) = Paths.FindDocsFolderFromRoot(ReadFileSystem, rootFolder);

DocumentationCheckoutDirectory = Paths.FindGitRoot(DocumentationSourceDirectory, ceiling: rootFolder);

FindGitRoot starts at DocumentationSourceDirectory and is bounded by rootFolder, which is the --path value. When the docset lives below the git root, .git sits above that ceiling, so DocumentationCheckoutDirectory is null, Git becomes GitCheckoutInformation.Unavailable, and Name takes the fallback branch:

Name = Context.Git != GitCheckoutInformation.Unavailable
    ? Context.Git.RepositoryName
    : Context.DocumentationCheckoutDirectory?.Name ?? $"unknown-{Context.DocumentationSourceDirectory.Name}";

Observed on a Codex preview for elastic/kibana, built with docs-builder 1.33.0 through elastic/docs-actions codex-preview.yml with path: docs-dev. The build log shows it plainly, and the rendered page carries unknown-docs-dev as the site label in the top left:

info ::DocumentationGenerator:: Created documentation set for: unknown-docs-dev

Two effects beyond the label, both from the same null DocumentationCheckoutDirectory:

  • HtmlWriter gates the per-page GitHub edit URL and the GitHub source URL on it being non-null, so those links are dropped from every page.
  • links.json records Origin as the Unavailable sentinel (branch, remote and ref all "unavailable") rather than the real branch and commit.

This is specific to builds that pass --path. codex build is unaffected, because it constructs GitCheckoutInformation explicitly from the clone (RepositoryName = checkout.Reference.Name) and roots the BuildContext at the repository directory, so the live site shows the correct name. That makes it a preview-only discrepancy, which is also why it is easy to miss.

It should affect any repository whose docset is not at the root. Among repos currently wired up to codex-preview that is security-team (docs-codex/), synthetics-service (docs-v3/), platform-engineering-productivity (new-docs/), infra (docs/resilience-team/) and kibana (docs-dev/).

This is not the same as #3136, which was about scope-root access to .git from a worktree.

Expected behavior

With the docset below the git root, the name resolves to the repository name (kibana in this case) and the GitHub edit/source links are emitted, matching what the same content produces when built by codex build.

The two concerns look conflated: --path is meaningful as the content scope root, but using it to bound git discovery means the enclosing repository becomes invisible precisely when the docset is nested. Letting git discovery walk to the enclosing repository, while leaving the content scope root where it is, would fix it — though the scope-root validation that produced #3136 suggests that walk needs to stay read-only and tolerate .git being a file or a link.

Steps to reproduce

  1. In a git checkout, place a docset in a subdirectory, for example docs-dev/docset.yml.
  2. Run docs-builder --path docs-dev --output ./.artifacts/docs/html.
  3. Observe Created documentation set for: unknown-docs-dev in the log, and the same string as the site label in the rendered output.

Reproduced with docs-builder 1.33.0.

Tooling

  • docs-builder
  • migration tooling

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions