Skip to content

fix(node-management): detach to canonical remote ref so remote-only branches install - #2936

Closed
wangzhengzhuo05 wants to merge 1 commit into
artokun:mainfrom
wangzhengzhuo05:fix/detach-remote-branch
Closed

wangzhengzhuo05 wants to merge 1 commit into
artokun:mainfrom
wangzhengzhuo05:fix/detach-remote-branch

Conversation

@wangzhengzhuo05

Copy link
Copy Markdown
Contributor

Summary

Fixes #2919. install_custom_node (action:install, source:git) with a ref that names a branch existing only as a remote-tracking branch (i.e. it is not the clone's default HEAD, so no local branch of that name exists) fails because:

git checkout --detach main
fatal: '--detach' cannot be used with '-b/-B/--orphan'

git's DWIM "create a local branch from origin/" kicks in for the bare name and conflicts with --detach. The install then errors and rolls back the clone.

What

In runGitCheckout (src/services/node-management.ts), after git fetch --all --tags and before the detach, a bare branch/tag name on the non-version path is canonicalized when it does not exist locally:

  • If refs/heads/<name> or refs/tags/<name> exists locally (via gitShowRefExists) → keep the bare name (no DWIM risk).
  • Else if refs/remotes/origin/<name> exists (via gitRemoteRefFor) → use that canonical fully-qualified ref path. git checkout --detach refs/remotes/origin/main never triggers DWIM.
  • Else → keep the bare name; a genuinely missing ref fails with the normal git error (behavior unchanged).

The #1470 version-derived-channel branch (refFromVersion === true && isGitHeadChannel) is untouched. A probe failure (GitRefProbeError) is now rethrown instead of being misreported as a checkout error.

Why

The repository's clone default HEAD can differ from the requested branch (e.g. the repro repo in #2919 defaults to h3-community-r01, so main is remote-only after clone). The user then gets nothing installed and has to git clone -b main by hand.

Tests

  • New #2919 test: ref: "main" with a remote-only main asserts the checkout uses ["-C", <dir>, "checkout", "--detach", "refs/remotes/origin/main"].
  • The existing explicit-tag test (checkout --detach "v1.2.3") still passes unchanged, proving locally-present refs keep the bare name.
  • Two cm-cli tests updated only to account for the new show-ref probe call (checkout assertions preserved in intent).

Verification

  • npx vitest run src/__tests__/services/node-management.test.ts → 244 passed (243 baseline + 1 new).
  • npm run build (tsc) → clean.
  • Mutation check: with the canonicalization neutralized, the new #2919 test fails (checkout uses the bare main); restoring the fix makes it pass — the regression test genuinely guards the remote-only-branch path.

Copilot AI balanced review requested due to automatic review settings September 10, 2026 16:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wangzhengzhuo05

Copy link
Copy Markdown
Contributor Author

Closing this to keep the tracker clean \u2014 it has been sitting without review for several days. This is no reflection on the change itself: the fix and its local verification still stand. If the issue is still present and you would like the patch revisited, say the word and I will rebase it onto current main and re-open. Thanks for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants