Skip to content

fix: FS.write_path starts from the empty tree over an unborn ref#9

Open
ivarvong wants to merge 1 commit into
mainfrom
fix/write-path-unborn-ref
Open

fix: FS.write_path starts from the empty tree over an unborn ref#9
ivarvong wants to merge 1 commit into
mainfrom
fix/write-path-unborn-ref

Conversation

@ivarvong

@ivarvong ivarvong commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Bootstrapping a repo through a workspace — Exgit.clone an empty remote (or Exgit.init), Workspace.open, write, commit, push — failed at the first write with {:error, :not_found}: FS.write_path/5 required the base ref to resolve, while Workspace.commit/2 already treats an unborn ref as parentless.

write_path now starts from the empty tree when the base is an unborn ref, so the full lifecycle works against a just-created remote:

{:ok, repo} = Exgit.clone(transport)          # empty Artifacts repo
ws = Exgit.Workspace.open(repo, "refs/heads/main")
{:ok, ws} = Exgit.Workspace.write(ws, "/hello.txt", "hi\n")
{:ok, _sha, ws} = Exgit.Workspace.commit(ws, message: "first", author: %{name: "a", email: "a@b"}, update_ref: "refs/heads/main")
{:ok, _} = Exgit.push(ws.repo, transport, refspecs: ["refs/heads/main"])

Unborn detection is deliberately narrow — a ref name with no ref-store entry, per the same name/SHA heuristic resolve_tree/2 uses. A raw SHA that fails to resolve stays {:error, :not_found}: in a lazy clone that is a missing object, and treating it as empty would silently produce a tree that drops every existing entry.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FpxHS5iGm9ktgpnL9QZu9x

Workspace.commit/2 already treats an unborn ref as parentless, but
Workspace.write/3 failed {:error, :not_found} on the same base — so a
workspace over a freshly initialized or cloned-empty repository could
never stage its first file. Unborn detection is deliberately narrow: a
ref NAME absent from the ref store. A raw SHA that fails to resolve
stays an error, since in a lazy clone that is a fetch miss and an empty
base there would silently drop every existing tree entry.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FpxHS5iGm9ktgpnL9QZu9x
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