MCPcopy Create free account
hub / github.com/cli/cli / Migrate

Method Migrate

internal/config/config.go:190–217  ·  view source on GitHub ↗
(m gh.Migration)

Source from the content-addressed store, hash-verified

188}
189
190func (c *cfg) Migrate(m gh.Migration) error {
191 // If there is no version entry we must never have applied a migration, and the following conditional logic
192 // handles the version as an empty string correctly.
193 version := c.Version().UnwrapOrZero()
194
195 // If migration has already occurred then do not attempt to migrate again.
196 if m.PostVersion() == version {
197 return nil
198 }
199
200 // If migration is incompatible with current version then return an error.
201 if m.PreVersion() != version {
202 return fmt.Errorf("failed to migrate as %q pre migration version did not match config version %q", m.PreVersion(), version)
203 }
204
205 if err := m.Do(c.cfg); err != nil {
206 return fmt.Errorf("failed to migrate config: %s", err)
207 }
208
209 c.Set("", versionKey, m.PostVersion())
210
211 // Then write out our migrated config.
212 if err := c.Write(); err != nil {
213 return fmt.Errorf("failed to write config after migration: %s", err)
214 }
215
216 return nil
217}
218
219func (c *cfg) CacheDir() string {
220 return ghConfig.CacheDir()

Calls 8

VersionMethod · 0.95
SetMethod · 0.95
WriteMethod · 0.95
UnwrapOrZeroMethod · 0.80
PostVersionMethod · 0.65
PreVersionMethod · 0.65
ErrorfMethod · 0.65
DoMethod · 0.65