diff --git a/cmd/krew/cmd/root.go b/cmd/krew/cmd/root.go index 6e4f292d..eb81ce09 100644 --- a/cmd/krew/cmd/root.go +++ b/cmd/krew/cmd/root.go @@ -150,14 +150,8 @@ func preRun(cmd *cobra.Command, _ []string) error { } if _, ok := os.LookupEnv(constants.EnableMultiIndexSwitch); ok { - isMigrated, err = indexmigration.Done(paths) - if err != nil { - return errors.Wrap(err, "error getting file info") - } - if !isMigrated { - if err := indexmigration.Migrate(paths); err != nil { - return errors.Wrap(err, "failed to automatically migrate index") - } + if err := indexmigration.Migrate(paths); err != nil { + return errors.Wrap(err, "failed to automatically migrate index") } } diff --git a/internal/indexmigration/migration.go b/internal/indexmigration/migration.go index b03ff1e2..c228a057 100644 --- a/internal/indexmigration/migration.go +++ b/internal/indexmigration/migration.go @@ -24,9 +24,9 @@ import ( "sigs.k8s.io/krew/internal/environment" ) -// Done checks if the krew installation requires a migration to support multiple indexes. +// done checks if the krew installation requires a migration to support multiple indexes. // A migration is necessary when the index directory contains a ".git" directory. -func Done(paths environment.Paths) (bool, error) { +func done(paths environment.Paths) (bool, error) { _, err := os.Stat(filepath.Join(paths.IndexBase(), ".git")) if err != nil && os.IsNotExist(err) { return true, nil @@ -36,14 +36,16 @@ func Done(paths environment.Paths) (bool, error) { // Migrate removes the index directory and then clones krew-index to the new default index path. func Migrate(paths environment.Paths) error { - isMigrated, err := Done(paths) + isMigrated, err := done(paths) if err != nil { return errors.Wrap(err, "failed to check if index migration is complete") } if isMigrated { - klog.V(2).Infoln("Already migrated") + klog.V(2).Infoln("already migrated") return nil } + + klog.Info("migrating krew index layout") indexPath := paths.IndexBase() tmpPath := filepath.Join(paths.BasePath(), "tmp_index_migration") newPath := filepath.Join(paths.IndexBase(), "default") @@ -60,6 +62,6 @@ func Migrate(paths environment.Paths) error { return errors.Wrapf(err, "could not move temporary index directory %q to new location %q", tmpPath, newPath) } - klog.Infof("Migration completed successfully.") + klog.Info("migration completed successfully") return nil } diff --git a/internal/indexmigration/migration_test.go b/internal/indexmigration/migration_test.go index a3155d38..21409144 100644 --- a/internal/indexmigration/migration_test.go +++ b/internal/indexmigration/migration_test.go @@ -51,7 +51,7 @@ func TestIsMigrated(t *testing.T) { } newPaths := environment.NewPaths(tmpDir.Root()) - actual, err := Done(newPaths) + actual, err := done(newPaths) if err != nil { t.Fatal(err) } @@ -83,8 +83,8 @@ func TestMigrate(t *testing.T) { if err != nil { t.Fatal(err) } - done, err := Done(newPaths) - if err != nil || !done { + migrationDone, err := done(newPaths) + if err != nil || !migrationDone { t.Errorf("expected migration to be done: %s", err) } })