== A folder opens on its working tree: no pin and no ref, and the subject is the folder.

# metab checkout --api /api/source/status
exit: 0
--- stdout ---
api: /api/source/status
status: 200
{
  "subject": "attached_filesystem",
  "generation": 1,
  "pin": null,
  "ref": null,
  "ref_name": null,
  "name": null,
  "origin": null,
  "location": null,
  "borrows": null,
  "shallow": false,
  "refreshable": false,
  "follows": false,
  "latest": null,
  "ref_on_origin": null,
  "last_fetch_at": null,
  "last_outcome": null,
  "refreshing": false,
  "refresh_quiet": false,
  "stale": false,
  "probe_every_s": null,
  "pull_request": null,
  "selection_state": null,
  "selection_href": null
}
--- stderr ---

== The selector lists the working tree and the checkout's own branches. working_tree says the working tree is served and where HEAD is, its branch and its commit, read from the checkout as the listing is made; kinds names the four lists in the order of the selector's tabs. The origin's default branch lists with the primary branches. The checked_out field names the branch the working tree is on. The current field marks a served ref.

# metab checkout --api /api/source/refs
exit: 0
--- stdout ---
api: /api/source/refs
status: 200
{
  "kind": "branch",
  "query": "",
  "pin": null,
  "ref": null,
  "kinds": [
    "working_tree",
    "branch",
    "remote",
    "tag"
  ],
  "working_tree": {
    "current": true,
    "head": "refs/heads/topic",
    "head_name": "topic",
    "head_commit": "42382ea2303b733e1e21b4bd6ddb974ca4e775eb",
    "name": "checkout",
    "location": "<ROOT>"
  },
  "origin": null,
  "pull_requests": null,
  "refs": [
    {
      "name": "topic",
      "ref": "refs/heads/topic",
      "commit": "42382ea2303b733e1e21b4bd6ddb974ca4e775eb",
      "committed_at": 1767229200.0,
      "default": false,
      "checked_out": true,
      "current": false
    },
    {
      "name": "local-work",
      "ref": "refs/heads/local-work",
      "commit": "25e0a2a76ab47a407f3dee083221e6efdcca6283",
      "committed_at": 1769904000.0,
      "default": false,
      "checked_out": false,
      "current": false
    },
    {
      "name": "feature",
      "ref": "refs/heads/feature",
      "commit": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
      "committed_at": 1767232800.0,
      "default": false,
      "checked_out": false,
      "current": false
    }
  ]
}
--- stderr ---

== The working tree's own list has no refs and answers working_tree alone, with no Git process: what the selector's Working tree tab shows, and what a page asks each time its watch says the checkout's HEAD moved. That watch is on the path .git/HEAD of the page's event stream, whose generation is what HEAD names, so it is the same for a linked worktree, whose HEAD is not under that path.

# metab checkout --api '/api/source/refs?kind=working_tree'
exit: 0
--- stdout ---
api: /api/source/refs?kind=working_tree
status: 200
{
  "kind": "working_tree",
  "query": "",
  "pin": null,
  "ref": null,
  "kinds": [
    "working_tree",
    "branch",
    "remote",
    "tag"
  ],
  "working_tree": {
    "current": true,
    "head": "refs/heads/topic",
    "head_name": "topic",
    "head_commit": "42382ea2303b733e1e21b4bd6ddb974ca4e775eb",
    "name": "checkout",
    "location": "<ROOT>"
  },
  "origin": null,
  "pull_requests": null,
  "refs": []
}
--- stderr ---

# metab checkout --api /api/events/watch --data watch-head.json
exit: 0
--- stdout ---
api: /api/events/watch
status: 200
{
  "type": "file_watch",
  "connection": null,
  "path": ".git/HEAD",
  "watching": false,
  "generation": "e116d38afab58b32"
}
--- stderr ---

== Remote-tracking branches are a third list, each with its remote's name. The symbolic origin/HEAD a clone writes puts its target among the primary branches. Tags list newest first, peeled to the commit they name.

# metab checkout --api '/api/source/refs?kind=remote'
exit: 0
--- stdout ---
api: /api/source/refs?kind=remote
status: 200
{
  "kind": "remote",
  "query": "",
  "pin": null,
  "ref": null,
  "kinds": [
    "working_tree",
    "branch",
    "remote",
    "tag"
  ],
  "working_tree": {
    "current": true,
    "head": "refs/heads/topic",
    "head_name": "topic",
    "head_commit": "42382ea2303b733e1e21b4bd6ddb974ca4e775eb",
    "name": "checkout",
    "location": "<ROOT>"
  },
  "origin": null,
  "pull_requests": null,
  "refs": [
    {
      "name": "origin/topic",
      "ref": "refs/remotes/origin/topic",
      "commit": "42382ea2303b733e1e21b4bd6ddb974ca4e775eb",
      "committed_at": 1767229200.0,
      "default": false,
      "checked_out": false,
      "current": false
    },
    {
      "name": "origin/feature",
      "ref": "refs/remotes/origin/feature",
      "commit": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
      "committed_at": 1767232800.0,
      "default": false,
      "checked_out": false,
      "current": false
    }
  ]
}
--- stderr ---

# metab checkout --api '/api/source/refs?kind=tag'
exit: 0
--- stdout ---
api: /api/source/refs?kind=tag
status: 200
{
  "kind": "tag",
  "query": "",
  "pin": null,
  "ref": null,
  "kinds": [
    "working_tree",
    "branch",
    "remote",
    "tag"
  ],
  "working_tree": {
    "current": true,
    "head": "refs/heads/topic",
    "head_name": "topic",
    "head_commit": "42382ea2303b733e1e21b4bd6ddb974ca4e775eb",
    "name": "checkout",
    "location": "<ROOT>"
  },
  "origin": null,
  "pull_requests": null,
  "refs": [
    {
      "name": "local-tag",
      "ref": "refs/tags/local-tag",
      "commit": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
      "committed_at": 1767232800.0,
      "default": false,
      "checked_out": false,
      "current": false
    },
    {
      "name": "v1",
      "ref": "refs/tags/v1",
      "commit": "fcb9d63c3c8533d1b929861f451a066e6d4f2d9e",
      "committed_at": 1767225600.0,
      "default": false,
      "checked_out": false,
      "current": false
    }
  ]
}
--- stderr ---

== A branch is served as a revision of the checkout: a pin named as the folder is, with no origin and nothing to refresh, since nothing is fetched into a checkout. location is the checkout, whose Git objects the pages are read from. The page was on the folder's README.md; view_href is that file at the revision's address.

# metab checkout --api /api/source/pin --data pin-feature-view.json
exit: 0
--- stdout ---
api: /api/source/pin
status: 200
{
  "changed": true,
  "status": {
    "subject": "git_revision",
    "generation": 2,
    "pin": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
    "ref": "refs/heads/feature",
    "ref_name": "feature",
    "name": "checkout",
    "origin": null,
    "location": "<ROOT>",
    "borrows": null,
    "shallow": false,
    "refreshable": false,
    "follows": true,
    "latest": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
    "ref_on_origin": null,
    "last_fetch_at": null,
    "last_outcome": null,
    "refreshing": false,
    "refresh_quiet": false,
    "stale": false,
    "probe_every_s": 2.0,
    "pull_request": null,
    "selection_state": null,
    "selection_href": null
  },
  "read_from": "checkout",
  "view_href": "/view/g1-UkVBRE1FLm1k"
}
--- stderr ---

== The checked-out branch is its last commit, not the working tree. STAGED.md is in the index and in no commit, so a page on it goes to the root.

# metab checkout --api /api/source/pin --data pin-checked-out.json
exit: 0
--- stdout ---
api: /api/source/pin
status: 200
{
  "changed": true,
  "status": {
    "subject": "git_revision",
    "generation": 2,
    "pin": "42382ea2303b733e1e21b4bd6ddb974ca4e775eb",
    "ref": "refs/heads/topic",
    "ref_name": "topic",
    "name": "checkout",
    "origin": null,
    "location": "<ROOT>",
    "borrows": null,
    "shallow": false,
    "refreshable": false,
    "follows": true,
    "latest": "42382ea2303b733e1e21b4bd6ddb974ca4e775eb",
    "ref_on_origin": null,
    "last_fetch_at": null,
    "last_outcome": null,
    "refreshing": false,
    "refresh_quiet": false,
    "stale": false,
    "probe_every_s": 2.0,
    "pull_request": null,
    "selection_state": null,
    "selection_href": null
  },
  "read_from": "checkout",
  "view_href": "/view/"
}
--- stderr ---

== A remote-tracking branch and a tag are served by name.

# metab checkout --api /api/source/pin --data pin-remote.json
exit: 0
--- stdout ---
api: /api/source/pin
status: 200
{
  "changed": true,
  "status": {
    "subject": "git_revision",
    "generation": 2,
    "pin": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
    "ref": "refs/remotes/origin/feature",
    "ref_name": "origin/feature",
    "name": "checkout",
    "origin": null,
    "location": "<ROOT>",
    "borrows": null,
    "shallow": false,
    "refreshable": false,
    "follows": true,
    "latest": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
    "ref_on_origin": null,
    "last_fetch_at": null,
    "last_outcome": null,
    "refreshing": false,
    "refresh_quiet": false,
    "stale": false,
    "probe_every_s": 2.0,
    "pull_request": null,
    "selection_state": null,
    "selection_href": null
  },
  "read_from": "checkout"
}
--- stderr ---

# metab checkout --api /api/source/pin --data pin-tag.json
exit: 0
--- stdout ---
api: /api/source/pin
status: 200
{
  "changed": true,
  "status": {
    "subject": "git_revision",
    "generation": 2,
    "pin": "fcb9d63c3c8533d1b929861f451a066e6d4f2d9e",
    "ref": "refs/tags/v1",
    "ref_name": "v1",
    "name": "checkout",
    "origin": null,
    "location": "<ROOT>",
    "borrows": null,
    "shallow": false,
    "refreshable": false,
    "follows": true,
    "latest": "fcb9d63c3c8533d1b929861f451a066e6d4f2d9e",
    "ref_on_origin": null,
    "last_fetch_at": null,
    "last_outcome": null,
    "refreshing": false,
    "refresh_quiet": false,
    "stale": false,
    "probe_every_s": 2.0,
    "pull_request": null,
    "selection_state": null,
    "selection_href": null
  },
  "read_from": "checkout"
}
--- stderr ---

== The working tree is asked for by name. It is already served in a new start, so nothing changes.

# metab checkout --api /api/source/pin --data pin-working-tree.json
exit: 0
--- stdout ---
api: /api/source/pin
status: 200
{
  "changed": false,
  "status": {
    "subject": "attached_filesystem",
    "generation": 1,
    "pin": null,
    "ref": null,
    "ref_name": null,
    "name": null,
    "origin": null,
    "location": null,
    "borrows": null,
    "shallow": false,
    "refreshable": false,
    "follows": false,
    "latest": null,
    "ref_on_origin": null,
    "last_fetch_at": null,
    "last_outcome": null,
    "refreshing": false,
    "refresh_quiet": false,
    "stale": false,
    "probe_every_s": null,
    "pull_request": null,
    "selection_state": null,
    "selection_href": null
  },
  "read_from": null
}
--- stderr ---

== A ref the checkout lacks is not found, and nothing is fetched. Revision syntax and a mixed selection are refused before any lookup.

# metab checkout --api /api/source/pin --data pin-gone.json
exit: 1
--- stdout ---
api: /api/source/pin
status: 404
{
  "error": "no branch or tag with that name is in the checkout",
  "code": "selection_not_found"
}
--- stderr ---
Error: /api/source/pin returned HTTP 404

# metab checkout --api /api/source/pin --data pin-syntax.json
exit: 1
--- stdout ---
api: /api/source/pin
status: 400
{
  "error": "the ref is not a valid Git ref name",
  "code": "invalid_selection"
}
--- stderr ---
Error: /api/source/pin returned HTTP 400

# metab checkout --api /api/source/pin --data pin-working-tree-and-ref.json
exit: 1
--- stdout ---
api: /api/source/pin
status: 400
{
  "error": "\"working_tree\" is true, alone or with \"view\"",
  "code": "invalid_selection"
}
--- stderr ---
Error: /api/source/pin returned HTTP 400

== --ref opens the folder on a branch: metab PATH --ref NAME starts on a revision where metab PATH starts on the working tree, by the switch the selector makes.

# metab checkout --ref feature --api /api/source/status
exit: 0
--- stdout ---
api: /api/source/status
status: 200
{
  "subject": "git_revision",
  "generation": 2,
  "pin": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
  "ref": "refs/heads/feature",
  "ref_name": "feature",
  "name": "checkout",
  "origin": null,
  "location": "<ROOT>",
  "borrows": null,
  "shallow": false,
  "refreshable": false,
  "follows": true,
  "latest": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
  "ref_on_origin": null,
  "last_fetch_at": null,
  "last_outcome": null,
  "refreshing": false,
  "refresh_quiet": false,
  "stale": false,
  "probe_every_s": 2.0,
  "pull_request": null,
  "selection_state": null,
  "selection_href": null
}
--- stderr ---

== A revision of one of the checkout's own branches follows that branch: follows is true, latest is the branch's commit as last read in the checkout, and probe_every_s is how often a visible page asks where the branch is. That ask is the page's own; for it the server reads the checkout's refs, fetches nothing, and answers probed. A commit opened by its ID and the working tree never move, so the ask is refused there as a folder's refresh is.

# metab checkout --ref feature --api /api/source/refresh --data page-ask.json
exit: 0
--- stdout ---
api: /api/source/refresh
status: 200
{
  "refresh": "probed",
  "status": {
    "subject": "git_revision",
    "generation": 2,
    "pin": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
    "ref": "refs/heads/feature",
    "ref_name": "feature",
    "name": "checkout",
    "origin": null,
    "location": "<ROOT>",
    "borrows": null,
    "shallow": false,
    "refreshable": false,
    "follows": true,
    "latest": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
    "ref_on_origin": null,
    "last_fetch_at": null,
    "last_outcome": null,
    "refreshing": false,
    "refresh_quiet": false,
    "stale": false,
    "probe_every_s": 2.0,
    "pull_request": null,
    "selection_state": null,
    "selection_href": null
  }
}
--- stderr ---

# metab checkout --ref fcb9d63c3c85 --api /api/source/refresh --data page-ask.json
exit: 1
--- stdout ---
api: /api/source/refresh
status: 409
{
  "error": "This is not available here.",
  "detail": "source does not support refresh",
  "code": "unsupported_for_subject",
  "capability": "refresh"
}
--- stderr ---
Error: /api/source/refresh returned HTTP 409

# metab checkout --api /api/source/refresh --data page-ask.json
exit: 1
--- stdout ---
api: /api/source/refresh
status: 409
{
  "error": "This is not available here.",
  "detail": "source does not support refresh",
  "code": "unsupported_for_subject",
  "capability": "refresh"
}
--- stderr ---
Error: /api/source/refresh returned HTTP 409

== A revision's files are read by the routes a page reads them by. feature has FEATURE.md and the committed README.md, and none of the working tree's edited, staged, or untracked files. The catalog is every file of the revision, each named by its GitPath wire (p), as on a mirror.

# metab checkout --ref feature --api /api/catalog
exit: 0
--- stdout ---
api: /api/catalog
status: 200
{
  "complete": true,
  "truncated": false,
  "revision": 1,
  "files": [
    {
      "p": "g1-RkVBVFVSRS5tZA",
      "e": ".md",
      "n": "FEATURE.md"
    },
    {
      "p": "g1-UkVBRE1FLm1k",
      "e": ".md",
      "n": "README.md"
    }
  ]
}
--- stderr ---

# metab checkout --ref feature --show FEATURE.md
exit: 0
--- stdout ---
show: FEATURE.md
route: /view/g1-RkVBVFVSRS5tZA
kind: markdown
views: rendered (default, key V), source (key S)
model: text envelope; size=17 content_bytes=17 content_truncated=False
--- stderr ---

== The Commits tab shows the revision the Files tab shows: on feature, HEAD is feature's commit, detached, and the history is that commit's, from feature back to first, where the working tree's starts at the checked-out topic.

# metab checkout --ref feature --api /api/git/repo
exit: 0
--- stdout ---
api: /api/git/repo
status: 200
{
  "is_repo": true,
  "root": "",
  "head": {
    "ref": null,
    "revision": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
    "detached": true,
    "unborn": false
  }
}
--- stderr ---

# metab checkout --ref feature --api '/api/git/log?limit=2'
exit: 0
--- stdout ---
api: /api/git/log?limit=2
status: 200
{
  "is_repo": true,
  "commits": [
    {
      "id": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
      "short_id": "c7ae2a3",
      "parent_ids": [
        "fcb9d63c3c8533d1b929861f451a066e6d4f2d9e"
      ],
      "author": {
        "name": "Mirror",
        "email": "mirror@example.invalid"
      },
      "authored_at": 1767232800.0,
      "committed_at": 1767232800.0,
      "subject": "feature",
      "refs": [
        {
          "id": "refs/heads/feature",
          "name": "feature",
          "kind": "branch",
          "revision": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b"
        },
        {
          "id": "refs/remotes/origin/feature",
          "name": "origin/feature",
          "kind": "remote",
          "revision": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
          "remote": "origin"
        },
        {
          "id": "refs/tags/local-tag",
          "name": "local-tag",
          "kind": "tag",
          "revision": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b"
        }
      ]
    },
    {
      "id": "fcb9d63c3c8533d1b929861f451a066e6d4f2d9e",
      "short_id": "fcb9d63",
      "parent_ids": [],
      "author": {
        "name": "Mirror",
        "email": "mirror@example.invalid"
      },
      "authored_at": 1767225600.0,
      "committed_at": 1767225600.0,
      "subject": "first",
      "refs": [
        {
          "id": "refs/tags/v1",
          "name": "v1",
          "kind": "tag",
          "revision": "fcb9d63c3c8533d1b929861f451a066e6d4f2d9e"
        }
      ]
    }
  ],
  "cursor": null,
  "has_more": false,
  "page": 0,
  "page_cursor": "<CURSOR>",
  "previous_cursor": null,
  "scope": "default",
  "scope_refs": [],
  "scope_fingerprint": "8babf87cfe78ef7afbd5e55558a35a29ae97d9cb4478b282154a97b5e7ef58a2",
  "graph_checkpoint": {
    "version": 1,
    "prior_swimlanes": [],
    "color_index": -1,
    "head_revision": "c7ae2a331f546e6a2431ed7093e9e430a9d1269b",
    "scope_fingerprint": "8babf87cfe78ef7afbd5e55558a35a29ae97d9cb4478b282154a97b5e7ef58a2"
  }
}
--- stderr ---

== --ref takes a tag, a remote-tracking branch, and a commit ID. A window of a revision is still called by its folder, and its full name adds what is shown. The two identities run with HOME at the sandbox, so the folder is named from ~.

# metab checkout --ref v1 --api /api/identity
exit: 0
--- stdout ---
api: /api/identity
status: 200
{
  "short_name": "checkout",
  "full_name": "~/checkout@v1",
  "kind": "git",
  "kind_label": "Local Git checkout",
  "title": "checkout • Metabrowser",
  "kind_tip": "Local Git checkout",
  "repository": null
}
--- stderr ---

# metab checkout --ref origin/feature --api /api/identity
exit: 0
--- stdout ---
api: /api/identity
status: 200
{
  "short_name": "checkout",
  "full_name": "~/checkout@origin/feature",
  "kind": "git",
  "kind_label": "Local Git checkout",
  "title": "checkout • Metabrowser",
  "kind_tip": "Local Git checkout",
  "repository": null
}
--- stderr ---

# metab checkout --ref fcb9d63c3c85 --show README.md
exit: 0
--- stdout ---
show: README.md
route: /view/g1-UkVBRE1FLm1k
kind: markdown
views: rendered (default, key V), source (key S)
model: text envelope; size=9 content_bytes=9 content_truncated=False
--- stderr ---

== The navigation check runs on a revision. A revision has no recency, so the live filter answers its typed refusal, which is what a page hides that filter by.

# metab checkout --ref feature --check-api
exit: 0
--- stdout ---
api check: checkout
scenario: nav-live-clear-filter
initial tree: 200; response=tree
live filter: 409; unsupported_for_subject
cleared filter: 200; response=tree
index: done
final nav: 200; rows=2; files=2; size=26; index=done
filtered nav: 200; rows=2; files=2; size=26; empty_dirs=0
result: pass
--- stderr ---

== A ref the checkout lacks, revision syntax, and a root with no checkout are refused, and nothing starts. A Git source names its branch or tag in its URL.

# metab checkout --ref gone --api /api/source/status
exit: 1
--- stdout ---
--- stderr ---
Error: --ref gone: no branch or tag with that name is in the checkout

# metab checkout --ref topic~1 --show README.md
exit: 1
--- stdout ---
--- stderr ---
Error: --ref topic~1: the ref is not a valid Git ref name

# metab plain --ref feature --api /api/source/status
exit: 1
--- stdout ---
--- stderr ---
Error: --ref names a branch or tag of a checkout, and ROOT is not a Git repository's root

# metab file://<ROOT>/origin.git --ref feature --api /api/source/status
exit: 1
--- stdout ---
--- stderr ---
Error: --ref names a branch or tag of a local checkout, and ROOT is a Git source; name the branch or tag in the URL

== A window of a checkout is called by its folder, and a plain folder has no refs to choose among.

# metab checkout --api /api/identity
exit: 0
--- stdout ---
api: /api/identity
status: 200
{
  "short_name": "checkout",
  "full_name": "<ROOT>",
  "kind": "git",
  "kind_label": "Local Git checkout",
  "title": "checkout • Metabrowser",
  "kind_tip": "Local Git checkout",
  "repository": null
}
--- stderr ---

# metab plain --api /api/source/refs
exit: 1
--- stdout ---
api: /api/source/refs
status: 409
{
  "error": "This is not available here.",
  "detail": "source does not support refs",
  "code": "unsupported_for_subject",
  "capability": "refs"
}
--- stderr ---
Error: /api/source/refs returned HTTP 409

== None of it wrote the checkout: after every command above, HEAD, the index, and the working tree are what the fixture left, on topic, with README.md modified and not staged, STAGED.md added, and UNTRACKED.md untracked.

# git -C checkout status --porcelain=v1 --branch
exit: 0
--- stdout ---
## topic...origin/topic
 M README.md
A  STAGED.md
?? UNTRACKED.md
--- stderr ---

# git -C checkout rev-parse HEAD
exit: 0
--- stdout ---
42382ea2303b733e1e21b4bd6ddb974ca4e775eb
--- stderr ---
