fix(34): WR-02 undo a failed plugin:install or plugin:update
A failure after the first change left the application half-modified: a checkout moved into plugins/<vendor>/<name> but not registered, go.mod edited, submodules without summer.yaml entries (and the next install refused the leftover directory), or some submodules updated and others not. Both commands now snapshot go.mod, go.sum, go.work, go.work.sum, summer.yaml and .gitmodules (with its index entry) before applying; a failure restores them, removes the submodules the run added (index entry, submodule config, absorbed git dir, checkout; registered right after the move) and checks moved submodules out where they were. What cannot be undone is named in the error.
This commit is contained in:
@@ -499,19 +499,29 @@ func (u *updater) report() {
|
||||
|
||||
// apply checks submodules out at their new tags, requires the tags in
|
||||
// go.mod, runs one go get for the module updates and refreshes the
|
||||
// go.work overrides.
|
||||
// go.work overrides. A failure checks the submodules out where they were
|
||||
// and restores go.mod, go.sum and go.work.
|
||||
func (u *updater) apply() error {
|
||||
snap, err := snapshotApp(u.ctx, u.appDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// A failure puts every checkout and file back (WR-02).
|
||||
fail := func(err error) error { return snap.undo(u.ctx, u.out, err) }
|
||||
var getArgs []string
|
||||
for _, s := range u.steps {
|
||||
switch s.Src.Kind {
|
||||
case ModeModule:
|
||||
getArgs = append(getArgs, s.Src.Module+"@"+s.To.Version)
|
||||
case ModeSubmodule:
|
||||
if err := snap.movingCheckout(u.ctx, s.Src.Dir); err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
if err := checkout(u.ctx, s.Src.Dir, s.To.Version); err != nil {
|
||||
return err
|
||||
return fail(err)
|
||||
}
|
||||
if err := runGo(u.ctx, u.appDir, "mod", "edit", "-require="+s.Src.Module+"@"+s.To.Version); err != nil {
|
||||
return err
|
||||
return fail(err)
|
||||
}
|
||||
fmt.Fprintf(u.out, "Checked out %s at %s\n", s.ID, s.To.Version)
|
||||
}
|
||||
@@ -519,11 +529,11 @@ func (u *updater) apply() error {
|
||||
if len(getArgs) > 0 {
|
||||
fmt.Fprintf(u.out, "go get %s\n", strings.Join(getArgs, " "))
|
||||
if err := runGo(u.ctx, u.appDir, append([]string{"get", "--"}, getArgs...)...); err != nil {
|
||||
return err
|
||||
return fail(err)
|
||||
}
|
||||
}
|
||||
if err := refreshWorkOverrides(u.ctx, u.appDir, u.out); err != nil {
|
||||
return err
|
||||
return fail(err)
|
||||
}
|
||||
fmt.Fprintln(u.out, "Updated; run summer build")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user