Add restore (x): make a repository exactly what git records

Restores the selection and all submodules below it recursively, asking
only if work would be lost. May clone/fetch missing objects (D23).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 12:38:29 +02:00
co-authored by Claude Opus 5.5
parent a328d3cc3a
commit 7980d3356a
16 changed files with 1260 additions and 118 deletions
+36
View File
@@ -33,6 +33,42 @@ type Locator interface {
Dir(path string) string
}
// Restorer is implemented by providers that can make a repository (and all
// submodules below it) exactly what git records. Path "" is the
// superproject. Restore may clone or fetch objects that are missing, but must
// never prompt the user.
type Restorer interface {
// RestoreLoss reports what Restore would discard, read from the disk at
// this moment.
RestoreLoss(ctx context.Context, path string) (Loss, error)
Restore(ctx context.Context, path string) error
}
// Loss is what a restore discards. The zero Loss means nothing is lost.
type Loss struct {
Files int // changed, conflicted and untracked files and directories
Modules int // repositories with a loss, the repository itself included
Operations int // merges, rebases, cherry-picks, reverts in progress
Commits int // commits that no branch, tag or remote ref reaches
Repositories int // untracked repositories with their own .git directory
Unknown int // repositories whose state could not be read
}
// Empty reports whether nothing would be lost.
func (l Loss) Empty() bool { return l == Loss{} }
// Add sums two losses.
func (l Loss) Add(o Loss) Loss {
return Loss{
Files: l.Files + o.Files,
Modules: l.Modules + o.Modules,
Operations: l.Operations + o.Operations,
Commits: l.Commits + o.Commits,
Repositories: l.Repositories + o.Repositories,
Unknown: l.Unknown + o.Unknown,
}
}
// Change reports that the git metadata of a repository changed.
type Change struct {
Path string // "" is the superproject