Commit Graph
2 Commits
Author SHA1 Message Date
ggbdpq a5ccf3f23f plugins: an update of an unfixed git source re-resolves the branch, not the lock's old commit (#2954)
What changed
- Before Bun resolves a git plugin's spec, the branches and tags of its
  repository are fetched into the bare clone Bun keeps in its install
  cache (refreshGitCache in gitrev.go): best-effort before install's
  bun add (a remote that can't be reached leaves the install to what the
  cache has), an error before reinstall's bun update (an update that
  didn't happen is not reported as done).
- When bun update exits 0 but the plugin is still behind the commit the
  update checks saw the repository at, reinstall says so instead of
  claiming the update.
- A spec that names a commit (#<sha>) is left alone: nothing is resolved
  for one, and its pin stands.
- docs/subsystems/provider-plugins.md: this git update path.

Why
A plugin added from an unfixed git+https://... URL could not be updated
(#2954): plugins/package.json named no commit, but Bun resolves a git
spec through its own bare clone of the repository in the install cache,
whose refs stay at the first install - a fetch there moves FETCH_HEAD,
not the clone's refs/heads. Every resolve after the first, bun update as
much as a bun add after a remove, therefore named the old commit again,
bun.lock re-recorded it (name@git+...#bb961b2...), and the update said it
had installed while node_modules kept 0.1.3. The lock is the record of
that resolution, not its cause. Verified with Bun 1.4.2 (the version
magpie runs) against a local git+file:// repository: after the branch
moved, bun update my-plugin answered "no changes" and exited 0, and so
did bun install with the lock entry dropped, bun update --force and bun
install --force; with the clone's refs fetched, the same bun update
installed the branch's commit now.

Run
go test ./internal/plugin/ -count=1 (ok; new: TestGitUpdateInstallsTheBran
chsCommitNow and TestGitUpdateKeepsACommitPin on the bun on PATH against
a local git+file:// repository, TestGitUpdateSaysWhenItDidnt with the
fake bun keeping the lock's commit, TestRefFixed,
TestSameRepoAndCloneOrigin)
go test ./internal/cli/ ./internal/provider/ -count=1 (ok)
gofmt -l (clean); go vet ./internal/plugin/ on darwin, linux and windows
(ok); builds of darwin and of windows (CGO_ENABLED=0 -tags production,
as the Makefile cross-compiles it) and of the 79 Linux packages that
don't need Linux GTK cgo (the GUI and cli are built natively per machine,
as the Makefile says).

Review (magpie): patch sha256 checked against the issue; read whole.
Run at the batch head on the Mac mini: go test ./internal/plugin
-count=1 ok, the real-Bun git e2e among them (not skipped); on the
Windows box TestGitUpdate* pass. Broken by hand: store.go at the base -
TestGitUpdateInstallsTheBranchsCommitNow ("still at 1.0.0, want
2.0.0") and TestGitUpdateSaysWhenItDidnt red; only install()'s refresh
removed - "installed again: 2.0.0, want 3.0.0". Not tried: a real
plugin from a real GitHub branch.

Generated-by: GLM-5.3-Flash (ZCode)
2026-10-31 02:00:10 +08:00
yetone 7af45761f7 plugin, gui: a plugin from a git repository shows Update only when its repository has new commits (ARNO on Discord)
ARNO installed opencode-codearts-auth as github:yuweihao17/codearts. Its row
on Plugins always had an Update button, and still did right after updating
it to the newest commit. The page drew Update for every git plugin whatever
its commit, since npm has no version to compare for one, and nothing asked
the repository. ba0e2a8a fixed the same complaint for pinned npm plugins
only.

A git plugin is now compared by commit:
- internal/plugin/gitrev.go reads the commit Bun installed: the package's
  .bun-tag (owner-repo-<sha7> for GitHub's, the full sha for a clone),
  else bun.lock's "#<sha>". It asks where the spec's branch or tag (the
  default branch without #ref) is now: GitHub's API (commits?per_page=1
  [&sha=ref]) for github:o/r, o/r, https://github.com/o/r and
  git+https/git+ssh/git:// URLs on github.com; git ls-remote for gitlab:,
  bitbucket: and any other git URL (an annotated tag's commit, not the
  tag's). A spec pinned to a commit is that commit, asked of nobody.
  Answers are kept 10 minutes (GitHub allows 60 unauthenticated requests
  an hour).
- updates.go: the hourly CheckUpdates and the Check for updates button
  (CheckNow) report a git plugin as current or update, with its commit
  and the repository's head, in place of the old "git" status. A waiting
  git update is dropped once the installed commit is the head.
- GUI: /api/plugins/git gives the heads, asked after load and after an
  install or update. The row shows the commit installed. Update, the
  "New commits" chip, the Discover card's Update and Update all show only
  when the repository is at another commit. Five new strings are in zh,
  zh-TW, ja and de.
- Docs: the Updates list in site/public/docs (en, zh, ja) says how a git
  plugin's update is told.

Tarball specs are unaffected, since magpie plugin add refuses them as not
a package name.

Run:
- go test -tags nogui ./internal/plugin ./internal/gui (temp HOME): ok.
- New TestGitPluginUpdateOnlyWhenItsRepositoryMoved, for
  github:yuweihao17/codearts, its #main form, owner/repo, the
  https://github.com URL, git+file and git+file#main, against a fake
  GitHub API and bare repositories. After add, nothing waits. A new
  commit at the same version is an update. After Upgrade, nothing waits
  again.
- TestGitCommitAsBunWritesIt uses ARNO's literal bun.lock line and
  .bun-tag. TestGitSource covers spec parsing and the pinned-sha form.
- Broke GitBehind by hand (any installed commit is behind): the new test
  goes red in every form. Restored.
- GUI: plugin-git.test.cjs now checks no Update at the head, then New
  commits with Update and Update all once the head moves, then none after
  Update. It went red with the old condition put back. All 28 plugin-*
  files plus click-scroll, i18n-keys, gui-ja and gui-de pass in Chromium
  and WebKit.
- Real case, sandbox HOME, magpie web on a spare port: magpie plugin add
  github:yuweihao17/codearts installed c594984. /api/plugins/git and
  /api/plugins/check say current at c594984 against the real GitHub, and
  nothing is waiting. In both engines the row shows "v0.1.0 c594984" with
  no Update and no Update all.
- gofmt -l clean; go vet -tags nogui darwin, GOOS=linux and GOOS=windows
  on internal/plugin and internal/gui.
2026-10-11 01:14:19 +08:00