Skip to content

Store branch name in vt state#278

Open
nbbaier wants to merge 3 commits into
val-town:mainfrom
nbbaier:feat/persist-branch-name-state
Open

Store branch name in vt state#278
nbbaier wants to merge 3 commits into
val-town:mainfrom
nbbaier:feat/persist-branch-name-state

Conversation

@nbbaier

@nbbaier nbbaier commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Persist the checked-out branch name in .vt/state.json.
  • Update it after create/remix, clone, checkout, and checkout -b.
  • Keep the field optional so existing local state stays compatible.
  • Add regression coverage for every state-writing path.

Why

Local tooling, including shell prompts, can determine the active Val Town branch without an API call.

Validation

  • deno task check
  • Targeted command tests covering create, remix, clone, checkout, and checkout -b
  • Manual smoke test of .vt/state.json after clone and checkout

@devin-ai-integration

Copy link
Copy Markdown
Contributor

LGTM with a few changes requested. The approach is minimal and backward-compatible.

What I checked:

  • deno task check
  • deno task fmt:check
  • deno test --allow-all src/cmd/tests/authless_help_test.ts
  • I did not run the full live integration tests because the VAL_TOWN_API_KEY available in this session is for the local dev stack and api.val.town returns 401; deno task check covers the new test code.

Requested changes:

  1. src/cmd/lib/clone.ts ignores the branchName argument. The README and .arguments line both promise vt clone [valUri] [targetDir] [branchName], but the value is never passed to VTClient.clone. This PR makes that bug more visible because any non-default branch passed to clone will still be persisted as main. Since VTClient.clone already accepts branchName, the fix is one line:

    const vt = await VTClient.clone({
      rootPath: clonePath,
      valName,
      username: ownerName,
      branchName,
    });
  2. src/cmd/lib/checkout.ts has a stale comment at lines 147-151 that says "we store the branch ID, not the branch name." That is no longer true after this PR. Please remove or update that comment. The current logic using currentBranchData.name is still correct; the comment is just misleading.

  3. Add a branch-name assertion to src/cmd/tests/clone_test.ts. checkout_test.ts covers it indirectly, but the PR description says clone is a state-writing path. A good place is the clone a newly created val or clone command output test:

    import { DEFAULT_BRANCH_NAME } from "~/consts.ts";
    import { readPersistedBranchName } from "~/cmd/tests/utils.ts";
    
    assertEquals(
      await readPersistedBranchName(targetDir),
      DEFAULT_BRANCH_NAME,
      "clone should persist the checked-out branch name",
    );

    If you fix (1), please also add a test cloning a non-default branch.

Branch rename edge case (the question you asked):

state.json stores the branch name as a cache. If a branch is renamed on Val Town, the file stays stale until the next clone, create, remix, or checkout. push, pull, status, branch, and checkout all use branch.id and live API names, so they keep working. status prints the live name. Only shell prompts that read state.json directly would show the old name. Since we don't need to sync, that's the expected behavior.

Optional nit:
readPersistedBranchName in tests reads raw JSON. That's fine, but using VTMeta.loadVtState would keep the test aligned with the schema. Not a blocker.

@nbbaier

nbbaier commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Comments addressed in 927f7fb

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