Overview
Concrete tool for snapshotting local/remote divergence before an in-place update provided by the internal/update package.
Description
Check acquires an install lock, resolves the install root, fetches the source repository's default branch (branch-scoped, no tags, no submodules), computes ahead/behind counts, lists incoming commits (capped), detects blocking local source changes, checks rollback availability, and returns a Snapshot. The source repository's own default branch is auto-detected so a fork whose default differs from main still works. Snapshot carries Installed, Commit, RemoteCommit, Behind, Ahead, Incoming, BlockingChanges, CanBuild, HasRollback, RollbackTo, CheckError.
Usage
- Self-update step 1 (snapshot & preview): called via
-check-update flag; printSnapshot renders the result.
Code Reference
Source Location
- Repository: CyberStrikeAI
- File: internal/update/update.go
- Lines: DefaultRepoURL L41, Snapshot struct L174, Check L384-460
Signature
var DefaultRepoURL = "https://github.com/AIPentest/CyberStrikeAI.git"
type Options struct {
Root, Repo, BinaryName string
}
type Snapshot struct {
Root, Installed, Branch, Commit, Subject string
TargetBranch, RemoteCommit, RemoteSubject string
Behind, Ahead int
Incoming []Commit
BlockingChanges []Change
CanBuild, BuildPending, HasRollback bool
RollbackTo, CheckError string
// ...
}
func Check(ctx context.Context, opts Options) (*Snapshot, error)
Import
import "cyberstrike-ai/internal/update"
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| ctx |
context.Context |
Yes |
45-min timeout
|
| opts |
Options |
Yes |
Root (install dir), Repo (source URL)
|
Outputs
| Name |
Type |
Description
|
| returns |
*Snapshot, error |
Divergence + incoming + blocking + rollback info
|
Usage Examples
Check for Updates
snap, err := update.Check(ctx, update.Options{
Root: ".",
Repo: config.LoadUpdateRepo("config.yaml"),
})
if err != nil { log.Fatal(err) }
if snap.UpdateAvailable() {
fmt.Printf("%d commits behind, incoming:\n", snap.Behind)
for _, c := range snap.Incoming {
fmt.Printf(" %s %s\n", c.Commit, c.Subject)
}
}
Related Pages
Implements Principle
Requires Environment