Skip to content

Commit

Permalink
Remove obsolete RCS commands
Browse files Browse the repository at this point in the history
- `rcs status` duplicates the functionality of `git status`.
- `RCSRemoveRemote` is never used.
- `RCSPull`, `RCSPush`, and `RCSAddRemote` are used as store functions
  from other actions, but the action functions are unused.
  • Loading branch information
kpitt committed Sep 27, 2022
1 parent f2eeb96 commit 788aa6e
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 159 deletions.
13 changes: 0 additions & 13 deletions internal/action/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,19 +754,6 @@ func (s *Action) GetCommands() []*cli.Command {
},
},
},
{
Name: "status",
Usage: "RCS status",
Description: "Show the RCS status",
Before: s.IsInitialized,
Action: s.RCSStatus,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "store",
Usage: "Store to operate on",
},
},
},
},
},
{
Expand Down
67 changes: 0 additions & 67 deletions internal/action/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/kpitt/gopass/internal/backend"
"github.com/kpitt/gopass/internal/cui"
"github.com/kpitt/gopass/internal/out"
si "github.com/kpitt/gopass/internal/store"
"github.com/kpitt/gopass/pkg/ctxutil"
"github.com/kpitt/gopass/pkg/debug"
"github.com/kpitt/gopass/pkg/termio"
Expand Down Expand Up @@ -97,69 +96,3 @@ func (s *Action) getUserData(ctx context.Context, store, name, email string) (st

return name, email
}

// RCSAddRemote adds a new git remote.
func (s *Action) RCSAddRemote(c *cli.Context) error {
ctx := ctxutil.WithGlobalFlags(c)
store := c.String("store")
remote := c.Args().Get(0)
url := c.Args().Get(1)

if remote == "" || url == "" {
return exit.Error(exit.Usage, nil, "Usage: %s git remote add <REMOTE> <URL>", s.Name)
}

return s.Store.RCSAddRemote(ctx, store, remote, url)
}

// RCSRemoveRemote removes a git remote.
func (s *Action) RCSRemoveRemote(c *cli.Context) error {
ctx := ctxutil.WithGlobalFlags(c)
store := c.String("store")
remote := c.Args().Get(0)

if remote == "" {
return exit.Error(exit.Usage, nil, "Usage: %s git remote rm <REMOTE>", s.Name)
}

return s.Store.RCSRemoveRemote(ctx, store, remote)
}

// RCSPull pulls from a git remote.
func (s *Action) RCSPull(c *cli.Context) error {
ctx := ctxutil.WithGlobalFlags(c)
store := c.String("store")
origin := c.Args().Get(0)
branch := c.Args().Get(1)

return s.Store.RCSPull(ctx, store, origin, branch)
}

// RCSPush pushes to a git remote.
func (s *Action) RCSPush(c *cli.Context) error {
ctx := ctxutil.WithGlobalFlags(c)
store := c.String("store")
origin := c.Args().Get(0)
branch := c.Args().Get(1)

if err := s.Store.RCSPush(ctx, store, origin, branch); err != nil {
if errors.Is(err, si.ErrGitNoRemote) {
out.Noticef(ctx, "No Git remote. Not pushing")

return nil
}

return exit.Error(exit.Git, err, "Failed to push to remote")
}
out.OKf(ctx, "Pushed to git remote")

return nil
}

// RCSStatus prints the rcs status.
func (s *Action) RCSStatus(c *cli.Context) error {
ctx := ctxutil.WithGlobalFlags(c)
store := c.String("store")

return s.Store.RCSStatus(ctx, store)
}
17 changes: 0 additions & 17 deletions internal/action/rcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,4 @@ func TestGit(t *testing.T) { //nolint:paralleltest
name, email := act.getUserData(ctx, "", "", "")
assert.Equal(t, "0xDEADBEEF", name)
assert.Equal(t, "0xDEADBEEF", email)

// GitAddRemote
assert.Error(t, act.RCSAddRemote(c))
buf.Reset()

// GitRemoveRemote
assert.Error(t, act.RCSRemoveRemote(c))
buf.Reset()

// GitPull
assert.Error(t, act.RCSPull(c))
buf.Reset()

// GitPush
assert.NoError(t, act.RCSPush(c))
assert.Contains(t, buf.String(), "No Git remote.")
buf.Reset()
}
2 changes: 0 additions & 2 deletions internal/backend/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ type rcs interface {

InitConfig(ctx context.Context, name, email string) error
AddRemote(ctx context.Context, remote, location string) error
RemoveRemote(ctx context.Context, remote string) error

Revisions(ctx context.Context, name string) ([]Revision, error)
GetRevision(ctx context.Context, name, revision string) ([]byte, error)

Status(ctx context.Context) ([]byte, error)
Compact(ctx context.Context) error
}

Expand Down
5 changes: 0 additions & 5 deletions internal/backend/storage/fs/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ func (s *Store) GetRevision(ctx context.Context, name string, revision string) (
return []byte(""), backend.ErrNotSupported
}

// Status is not implemented.
func (s *Store) Status(context.Context) ([]byte, error) {
return []byte(""), backend.ErrNotSupported
}

// Compact is not implemented.
func (s *Store) Compact(context.Context) error {
return nil
Expand Down
1 change: 0 additions & 1 deletion internal/backend/storage/fs/rcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ func TestRCS(t *testing.T) {
body, err := g.GetRevision(ctx, "foo", "latest")
require.Error(t, err)
assert.Equal(t, "", string(body))
assert.Error(t, g.RemoveRemote(ctx, "foo"))
}
12 changes: 0 additions & 12 deletions internal/backend/storage/gitfs/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,6 @@ func (g *Git) GetRevision(ctx context.Context, name, revision string) ([]byte, e
return stdout, nil
}

// Status return the git status output.
func (g *Git) Status(ctx context.Context) ([]byte, error) {
stdout, stderr, err := g.captureCmd(ctx, "GitStatus", "status")
if err != nil {
debug.Log("Command failed: %s\n%s", string(stdout), string(stderr))

return nil, err
}

return stdout, nil
}

// Compact will run git gc.
func (g *Git) Compact(ctx context.Context) error {
return g.Cmd(ctx, "gitGC", "gc", "--aggressive")
Expand Down
2 changes: 0 additions & 2 deletions internal/backend/storage/gitfs/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ func TestGit(t *testing.T) { //nolint:paralleltest
require.NotNil(t, git)
assert.Equal(t, "gitfs", git.Name())
assert.NoError(t, git.AddRemote(ctx, "foo", "file:///tmp/foo"))
assert.NoError(t, git.RemoveRemote(ctx, "foo"))
assert.Error(t, git.RemoveRemote(ctx, "foo"))
})

t.Run("clone existing repo", func(t *testing.T) { //nolint:paralleltest
Expand Down
16 changes: 0 additions & 16 deletions internal/store/leaf/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"github.com/kpitt/gopass/internal/backend"
"github.com/kpitt/gopass/internal/out"
"github.com/kpitt/gopass/internal/store"
"github.com/kpitt/gopass/pkg/debug"
"github.com/kpitt/gopass/pkg/gopass"
Expand Down Expand Up @@ -53,18 +52,3 @@ func (s *Store) GetRevision(ctx context.Context, name, revision string) (gopass.

return sec, nil
}

// GitStatus shows the git status output.
func (s *Store) GitStatus(ctx context.Context, _ string) error {
debug.Log("RCS status for %s", s.path)
buf, err := s.storage.Status(ctx)
if err != nil {
debug.Log("RCS status failed for %s: %s", s.path, err)

return fmt.Errorf("failed to get RCS status for %s: %w", s.path, err)
}

out.Printf(ctx, string(buf))

return nil
}
5 changes: 0 additions & 5 deletions internal/store/mockstore/inmem/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ func (m *InMem) GetRevision(context.Context, string, string) ([]byte, error) {
return []byte("foo\nbar"), nil
}

// Status is not implemented.
func (m *InMem) Status(context.Context) ([]byte, error) {
return []byte(""), nil
}

// Compact is not implemented.
func (m *InMem) Compact(context.Context) error {
return nil
Expand Down
17 changes: 0 additions & 17 deletions internal/store/root/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/kpitt/gopass/internal/backend"
"github.com/kpitt/gopass/internal/out"
"github.com/kpitt/gopass/pkg/ctxutil"
"github.com/kpitt/gopass/pkg/gopass"
)
Expand Down Expand Up @@ -32,13 +31,6 @@ func (r *Store) RCSAddRemote(ctx context.Context, name, remote, url string) erro
return store.Storage().AddRemote(ctx, remote, url)
}

// RCSRemoveRemote removes a git remote.
func (r *Store) RCSRemoveRemote(ctx context.Context, name, remote string) error {
store, _ := r.getStore(name)

return store.Storage().RemoveRemote(ctx, remote)
}

// RCSPull performs a git pull.
func (r *Store) RCSPull(ctx context.Context, name, origin, remote string) error {
store, _ := r.getStore(name)
Expand Down Expand Up @@ -67,12 +59,3 @@ func (r *Store) GetRevision(ctx context.Context, name, revision string) (context

return ctx, sec, err
}

// RCSStatus show the git status.
// TODO this should likely iterate over all stores.
func (r *Store) RCSStatus(ctx context.Context, name string) error {
store, name := r.getStore(name)
out.Printf(ctx, "Store: %s", store.Path())

return store.GitStatus(ctx, name)
}
2 changes: 0 additions & 2 deletions internal/store/root/rcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func TestRCS(t *testing.T) {
rs, err := createRootStore(ctx, u)
require.NoError(t, err)

assert.Error(t, rs.RCSStatus(ctx, ""))

revs, err := rs.ListRevisions(ctx, "foo")
assert.NoError(t, err)
assert.Equal(t, 1, len(revs))
Expand Down

0 comments on commit 788aa6e

Please sign in to comment.