update

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 24 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package update replaces the running git-stack binary with the latest GitHub release.

It talks plain HTTPS to the GitHub releases API and the release assets, so it works without gh being logged in. Assets are the archives goreleaser publishes (git-stack_<ver>_<os>_<arch>.tar.gz plus checksums.txt); the archive is verified against checksums.txt before anything is written.

Index

Constants

View Source
const (
	// DefaultCheckTTL is how long one check is trusted before the next
	// command asks GitHub again.
	DefaultCheckTTL = 24 * time.Hour
	// DefaultCheckTimeout bounds one background request; a slow network
	// must never hold a command up.
	DefaultCheckTimeout = 5 * time.Second
)

Defaults for Checker.

View Source
const DefaultRepo = "DomBlack/git-stack"

DefaultRepo is the GitHub repository releases are published from.

Variables

This section is empty.

Functions

func DefaultCacheDir added in v0.1.5

func DefaultCacheDir() (string, error)

DefaultCacheDir is where the user wide cache lives: the OS cache directory (XDG_CACHE_HOME or ~/.cache on Linux, ~/Library/Caches on macOS) plus git-stack.

Types

type Check added in v0.1.5

type Check struct {
	// Current is the running binary.
	Current version.Info
	// contains filtered or unexported fields
}

Check is one run's view of the latest release.

func (*Check) Available added in v0.1.5

func (ch *Check) Available() (latest string, ok bool)

Available reports the newer release worth mentioning, if there is one: this run's answer when it has already arrived, otherwise the previous run's. Dev builds are left alone (they were built that way on purpose, and update would not replace them anyway), as are binaries ahead of the latest release.

func (*Check) Done added in v0.1.5

func (ch *Check) Done() <-chan struct{}

Done is closed once the background refresh has finished (or was not needed). Commands never wait on it; tests do.

type Checker added in v0.1.5

type Checker struct {
	Client  *Client
	Store   *cache.Store
	TTL     time.Duration // zero: DefaultCheckTTL
	Timeout time.Duration // zero: DefaultCheckTimeout
}

Checker keeps the latest release up to date in the background. Start returns straight away with whatever the last run found; when that is older than TTL it asks GitHub once more in a goroutine and records the answer for the next run. A command never waits for it.

func (*Checker) Start added in v0.1.5

func (c *Checker) Start(ctx context.Context, current version.Info) *Check

Start reads the cached answer and, when it is stale or missing, refreshes it in the background. The returned Check answers from the cache until the refresh lands.

type Client

type Client struct {
	HTTP      *http.Client
	BaseURL   string // GitHub API base, https://api.github.com
	Repo      string // owner/name
	UserAgent string
}

Client fetches releases. The zero value is not usable; use New.

func New

func New(current version.Info) *Client

New returns a client for the public GitHub API.

func (*Client) Install added in v0.3.1

func (c *Client) Install(ctx context.Context, p Plan, o Options) (Result, error)

Install downloads the planned release, verifies it against the release's checksums.txt and replaces o.Target with it.

func (*Client) Latest

func (c *Client) Latest(ctx context.Context) (Release, error)

Latest fetches the newest release.

func (*Client) Notes added in v0.4.0

func (c *Client) Notes(ctx context.Context, from, to string) ([]ReleaseNote, error)

Notes returns the releases newer than from, up to and including to, newest first: every version someone on from gets by updating to to. A from that isn't a release (a dev build, "") gets to alone, since there's no telling what it already has. Drafts and prereleases are left out.

func (*Client) Plan added in v0.3.1

func (c *Client) Plan(ctx context.Context, o Options) (Plan, error)

Plan fetches the latest release and decides, without downloading anything, whether Run would install it. The CLI uses Plan and Install as two steps so the download gets its own headline.

func (*Client) ReleasesURL added in v0.4.0

func (c *Client) ReleasesURL() string

ReleasesURL is the page listing every release, for when more than one is being skipped.

func (*Client) Run

func (c *Client) Run(ctx context.Context, o Options) (Result, error)

Run compares the running binary with the latest release and, unless told otherwise, downloads and installs it.

type Doctor added in v0.5.0

type Doctor struct {
	Client *Client
	// Options are what an update would use (Current, Target, GOOS, GOARCH).
	Options Options
	// AfterUpdate runs once the binary has been replaced, with its path (the
	// CLI hands over to the new binary to refresh what install set up). Nil
	// leaves the check without a fix: the MCP server reports, it doesn't
	// replace the binary it runs as.
	AfterUpdate func(ctx context.Context, target string) error
	// contains filtered or unexported fields
}

Doctor checks whether git-stack itself is the latest release.

func (*Doctor) Checks added in v0.5.0

func (d *Doctor) Checks(*git.Repo) []doctor.Check

Checks implements doctor.Provider.

type Known added in v0.1.5

type Known struct {
	Latest string `json:"latest"`
}

Known is what the background check remembers between runs.

type Options

type Options struct {
	// Current is the running binary's version.
	Current version.Info
	// Target is the file to replace, normally os.Executable with symlinks resolved.
	Target string
	// GOOS and GOARCH pick the asset.
	GOOS, GOARCH string
	// Check only reports; nothing is downloaded.
	Check bool
	// Force replaces the binary even when it is up to date, ahead, or a dev build.
	Force bool
}

Options control Run.

type Plan added in v0.3.1

type Plan struct {
	Result  Result
	Release Release
	Install bool
}

Plan is what Run would do: the latest release, and whether it is to be installed (Result.Status says why not when it isn't).

type PullRequest added in v0.4.0

type PullRequest struct {
	Number int
	Title  string
	URL    string
}

PullRequest is one entry in a release's list of changes.

type Release

type Release struct {
	Tag    string
	Assets map[string]string // asset name -> download URL
}

Release is a published release and its downloadable assets.

type ReleaseNote added in v0.4.0

type ReleaseNote struct {
	Tag     string
	Summary string
	URL     string
	// Breaking lists the pull requests in the release's "Breaking changes"
	// section, the one GitHub's generated notes give PRs labelled
	// breaking-change.
	Breaking []PullRequest
}

ReleaseNote is what update shows for one release: the one line summary its notes open with and the pull requests listed under breaking changes.

type Result

type Result struct {
	Status  Status
	Current string
	Latest  string
	// DevBuild is true when the running binary is not a release.
	DevBuild bool
	Target   string
}

Result reports the outcome of Run.

type Status

type Status int

Status says what Run did.

const (
	// StatusUpToDate: the binary already is the latest release.
	StatusUpToDate Status = iota
	// StatusAhead: the binary is newer than the latest release.
	StatusAhead
	// StatusAvailable: a release is available but nothing was changed (Check,
	// or a dev build without Force).
	StatusAvailable
	// StatusUpdated: the binary was replaced.
	StatusUpdated
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL