Skip to content

Commit

Permalink
Attempt to fix handling of rcs init command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kpitt committed Sep 27, 2022
1 parent ac58b3d commit bfd9876
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
8 changes: 4 additions & 4 deletions internal/action/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 2 additions & 9 deletions internal/action/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion internal/store/leaf/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ var commandsWithError = set.Map([]string{
".move",
".otp",
".process",
".rcs.status",
".recipients.add",
".recipients.remove",
".show",
Expand Down

0 comments on commit bfd9876

Please sign in to comment.