From bfd987622dfc77a391ce2bf1c368709eb2e6a2b4 Mon Sep 17 00:00:00 2001 From: Kenny Pitt Date: Thu, 25 Aug 2022 12:07:49 -0400 Subject: [PATCH] Attempt to fix handling of `rcs init` command If a store does not exist, then it should be initialized with the `init` command. The purpose of the `rcs init` command is to initialize a Git repository in an existing "fs" store that has no revision control, so we won't get the desired result if we fail the init, or if we just do nothing, when the store is using the "fs" backend. It also makes no sense to check the backend for the context because that is initialized from the root store only, and the actual storage could be different if the "--store" option was used. --- internal/action/init.go | 8 ++++---- internal/action/rcs.go | 11 ++--------- internal/store/leaf/rcs.go | 3 ++- main_test.go | 1 - 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/internal/action/init.go b/internal/action/init.go index bb8c58cfa5..2ffc5f3851 100644 --- a/internal/action/init.go +++ b/internal/action/init.go @@ -142,12 +142,12 @@ func (s *Action) init(ctx context.Context, alias, path string, keys ...string) e } } - if backend.HasStorageBackend(ctx) { - bn := backend.StorageBackendName(backend.GetStorageBackend(ctx)) - debug.Log("Initializing RCS (%s)...", bn) + be := backend.GetStorageBackend(ctx) + if be == backend.GitFS { + debug.Log("Initializing git repository...") if err := s.rcsInit(ctx, alias, ctxutil.GetUsername(ctx), ctxutil.GetEmail(ctx)); err != nil { debug.Log("Stacktrace: %+v\n", err) - out.Errorf(ctx, "✗ Failed to init Version Control (%s): %s", bn, err) + out.Errorf(ctx, "✗ Failed to initialize git repository: %s", err) } debug.Log("RCS initialized as %s", s.Store.Storage(ctx, alias).Name()) } else { diff --git a/internal/action/rcs.go b/internal/action/rcs.go index 587cae3f9e..974620220a 100644 --- a/internal/action/rcs.go +++ b/internal/action/rcs.go @@ -38,17 +38,10 @@ func (s *Action) RCSInit(c *cli.Context) error { } func (s *Action) rcsInit(ctx context.Context, store, un, ue string) error { - be := backend.GetStorageBackend(ctx) - // TODO this should rather ask s.Store if it HasRCSInit or something. - if be == backend.FS { - return nil - } - - bn := backend.StorageBackendName(be) userName, userEmail := s.getUserData(ctx, store, un, ue) if err := s.Store.RCSInit(ctx, store, userName, userEmail); err != nil { if errors.Is(err, backend.ErrNotSupported) { - debug.Log("RCSInit not supported for backend %s in %q", bn, store) + debug.Log("RCSInit not supported for storage backend in %q", store) return nil } @@ -60,7 +53,7 @@ func (s *Action) rcsInit(ctx context.Context, store, un, ue string) error { return fmt.Errorf("failed to run git init: %w", err) } - out.Printf(ctx, "Initialized git repository for %q <%s>...", un, ue) + out.Printf(ctx, "Initialized git repository for %q <%s>...", userName, userEmail) return nil } diff --git a/internal/store/leaf/rcs.go b/internal/store/leaf/rcs.go index 91863585f3..91189c37d0 100644 --- a/internal/store/leaf/rcs.go +++ b/internal/store/leaf/rcs.go @@ -14,7 +14,8 @@ import ( // GitInit initializes the git storage. func (s *Store) GitInit(ctx context.Context) error { - storage, err := backend.InitStorage(ctx, backend.GetStorageBackend(ctx), s.path) + // The desired storage type for `GitInit` is always GitFS. + storage, err := backend.InitStorage(ctx, backend.GitFS, s.path) if err != nil { return err } diff --git a/main_test.go b/main_test.go index 67a2f46c53..9fdf41c486 100644 --- a/main_test.go +++ b/main_test.go @@ -78,7 +78,6 @@ var commandsWithError = set.Map([]string{ ".move", ".otp", ".process", - ".rcs.status", ".recipients.add", ".recipients.remove", ".show",