From 06dddf7f686ae0ec501ca39d20e43af66e9823b0 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 26 Sep 2026 20:50:26 +0800 Subject: [PATCH] update: magpie update in a Homebrew install (brew install magpie, from the new tap in magpie-releases) says to brew upgrade magpie instead of replacing the binary in brew's Cellar, which would leave brew thinking the old version is there --- internal/update/update.go | 7 +++++++ internal/update/update_test.go | 13 +++++++++++++ update_cli.go | 3 +++ 3 files changed, 23 insertions(+) diff --git a/internal/update/update.go b/internal/update/update.go index 9665eb1c..ae0c40fd 100644 --- a/internal/update/update.go +++ b/internal/update/update.go @@ -176,6 +176,13 @@ func Bundle() string { return app } +// Homebrew is whether exe was installed by Homebrew (brew install magpie), +// which keeps it in its Cellar and has to be the one to upgrade it: a +// binary replaced under it leaves brew thinking the old version is there. +func Homebrew(exe string) bool { + return strings.Contains(filepath.ToSlash(exe), "/Cellar/magpie/") +} + // Executable is the running binary, symlinks resolved. func Executable() (string, error) { exe, err := os.Executable() diff --git a/internal/update/update_test.go b/internal/update/update_test.go index a6834516..82ddd588 100644 --- a/internal/update/update_test.go +++ b/internal/update/update_test.go @@ -30,3 +30,16 @@ func TestReleased(t *testing.T) { } } } + +func TestHomebrew(t *testing.T) { + for exe, want := range map[string]bool{ + "/opt/homebrew/Cellar/magpie/0.1.126/bin/magpie": true, + "/home/linuxbrew/.linuxbrew/Cellar/magpie/0.1.126/bin/magpie": true, + "/usr/local/bin/magpie": false, + "/Applications/magpie.app/Contents/MacOS/magpie": false, + } { + if Homebrew(exe) != want { + t.Errorf("%s: %v", exe, !want) + } + } +} diff --git a/update_cli.go b/update_cli.go index 949e651c..09e3e1db 100644 --- a/update_cli.go +++ b/update_cli.go @@ -51,6 +51,9 @@ func updateCmd(args []string) error { fmt.Println(green.Render("✓"), "updated", tilde(app), "to", rel.Version, muted.Render("· quit and reopen magpie to use it")) return nil } + if exe, err := update.Executable(); err == nil && update.Homebrew(exe) { + return fmt.Errorf("this magpie was installed with Homebrew; update it with: brew upgrade magpie") + } fmt.Println(muted.Render(" downloading " + update.BinaryAsset() + " …")) if err := update.ReplaceBinary(ctx, rel); err != nil { return err