Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ func (a *App) CLI() *CLI {
Short: "",
Long: "update",
Args: "",
IsHidden: core.NoSelfUpdate,
Description: "Update the fetch binary in place",
Default: "",
IsSet: func() bool {
Expand Down
12 changes: 10 additions & 2 deletions internal/core/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ type TerminalSize struct {
HeightPx int // Height in pixels (0 if unavailable)
}

var packageManager string // set via ldflags to disable self-update (e.g. "Homebrew")

var (
IsStderrTerm bool
IsStdoutTerm bool
IsStderrTerm bool
IsStdoutTerm bool
NoSelfUpdate bool
PackageManager string

UserAgent string
Version string
Expand All @@ -29,6 +33,10 @@ func init() {
IsStderrTerm = isTerminal(int(os.Stderr.Fd()))
IsStdoutTerm = isTerminal(int(os.Stdout.Fd()))

// Set whether self-update is disabled.
PackageManager = packageManager
NoSelfUpdate = PackageManager != ""

// Set executable version and user-agent.
Version = getVersion()
UserAgent = "fetch/" + Version
Expand Down
20 changes: 19 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func main() {
}

// Start async update, if necessary.
if !app.Update && app.Cfg.AutoUpdate != nil && *app.Cfg.AutoUpdate >= 0 {
if !app.Update && !core.NoSelfUpdate && app.Cfg.AutoUpdate != nil && *app.Cfg.AutoUpdate >= 0 {
checkForUpdate(ctx, handle.Stderr(), *app.Cfg.AutoUpdate)
}

Expand Down Expand Up @@ -94,6 +94,11 @@ func main() {
// Attempt to update the current executable.
verbosity := getVerbosity(app)
if app.Update {
if core.NoSelfUpdate {
p := handle.Stderr()
core.WriteErrorMsg(p, errSelfUpdateDisabled(core.PackageManager))
os.Exit(1)
}
p := handle.Stderr()
timeout := getValue(app.Cfg.Timeout)
status := update.Update(ctx, p, timeout, verbosity == core.VSilent, app.DryRun)
Expand Down Expand Up @@ -289,6 +294,19 @@ func writeCLIErr(p *core.Printer, err error) {
p.Flush()
}

type errSelfUpdateDisabled string

func (err errSelfUpdateDisabled) Error() string {
return "self-update is disabled for this installation; please update using " + string(err)
}

func (err errSelfUpdateDisabled) PrintTo(p *core.Printer) {
p.WriteString("self-update is disabled for this installation; please update using ")
p.Set(core.Bold)
p.WriteString(string(err))
p.Reset()
}

type errShellNotSupported string

func (err errShellNotSupported) Error() string {
Expand Down