Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
add subcommand "gopass git remote remove" (gopasspw#771)
Browse files Browse the repository at this point in the history
* add remote remove

* apply feedback from PR review

* adding command to list of commands in test

* adding extra tests to make the code coverage tool happy

* remove unnecessary new
  • Loading branch information
campoy authored and dominikschulz committed May 17, 2018
1 parent 2d2e45b commit 46ac859
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,21 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
},
},
},
{
Name: "remove",
Usage: "Remove git remote",
Description: "Remove a git remote",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.GitRemoveRemote(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "store",
Usage: "Store to operate on",
},
},
},
},
},
{
Expand Down
1 change: 1 addition & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var commandsWithError = map[string]struct{}{
".git.pull": {},
".git.push": {},
".git.remote.add": {},
".git.remote.remove": {},
".grep": {},
".history": {},
".init": {},
Expand Down
12 changes: 12 additions & 0 deletions pkg/action/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ func (s *Action) GitAddRemote(ctx context.Context, c *cli.Context) error {
return s.Store.GitAddRemote(ctx, store, remote, url)
}

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

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

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

// GitPull pulls from a git remote
func (s *Action) GitPull(ctx context.Context, c *cli.Context) error {
store := c.String("store")
Expand Down
4 changes: 4 additions & 0 deletions pkg/action/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func TestGit(t *testing.T) {
assert.Error(t, act.GitAddRemote(ctx, c))
buf.Reset()

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

// GitPull
assert.Error(t, act.GitPull(ctx, c))
buf.Reset()
Expand Down
1 change: 1 addition & 0 deletions pkg/backend/rcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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)
Expand Down
5 changes: 5 additions & 0 deletions pkg/backend/rcs/git/cli/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ func (g *Git) AddRemote(ctx context.Context, remote, url string) error {
return g.Cmd(ctx, "gitAddRemote", "remote", "add", remote, url)
}

// RemoveRemote removes a remote
func (g *Git) RemoveRemote(ctx context.Context, remote string) error {
return g.Cmd(ctx, "gitRemoveRemote", "remote", "remove", remote)
}

// Revisions will list all available revisions of the named entity
// see http://blog.lost-theory.org/post/how-to-parse-git-log-output/
// and https://git-scm.com/docs/git-log#_pretty_formats
Expand Down
2 changes: 2 additions & 0 deletions pkg/backend/rcs/git/cli/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func TestGit(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "git", 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"))

gitdir2 := filepath.Join(td, "git2")
assert.NoError(t, os.Mkdir(gitdir2, 0755))
Expand Down
5 changes: 5 additions & 0 deletions pkg/backend/rcs/git/gogit/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ func (g *Git) AddRemote(ctx context.Context, remote, url string) error {
return err
}

// RemoveRemote removes a remote
func (g *Git) RemoveRemote(ctx context.Context, remote string) error {
return g.repo.DeleteRemote(remote)
}

// Name returns go-git
func (g *Git) Name() string {
return "go-git"
Expand Down
2 changes: 2 additions & 0 deletions pkg/backend/rcs/git/gogit/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ func TestInit(t *testing.T) {
assert.Error(t, g.InitConfig(ctx, "foo", "bar"))
assert.Equal(t, "go-git", g.Name())
assert.NoError(t, g.AddRemote(ctx, "foo", "file:///tmp/foo"))
assert.NoError(t, g.RemoveRemote(ctx, "foo"))
assert.Error(t, g.RemoveRemote(ctx, "foo"))

// list remotes
list, err = g.repo.Remotes()
Expand Down
5 changes: 5 additions & 0 deletions pkg/backend/rcs/noop/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (g *Noop) AddRemote(ctx context.Context, remote, url string) error {
return nil
}

// RemoveRemote does nothing
func (g *Noop) RemoveRemote(ctx context.Context, remote string) error {
return nil
}

// Revisions is not implemented
func (g *Noop) Revisions(context.Context, string) ([]backend.Revision, error) {
return nil, fmt.Errorf("not yet implemented for %s", g.Name())
Expand Down
1 change: 1 addition & 0 deletions pkg/backend/rcs/noop/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ func TestNoop(t *testing.T) {
body, err := g.GetRevision(ctx, "foo", "bar")
assert.NoError(t, err)
assert.Equal(t, "", string(body))
assert.NoError(t, g.RemoveRemote(ctx, "foo"))
}
6 changes: 6 additions & 0 deletions pkg/store/root/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func (r *Store) GitAddRemote(ctx context.Context, name, remote, url string) erro
return store.RCS().AddRemote(ctx, remote, url)
}

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

// GitPull performs a git pull
func (r *Store) GitPull(ctx context.Context, name, origin, remote string) error {
ctx, store, _ := r.getStore(ctx, name)
Expand Down

0 comments on commit 46ac859

Please sign in to comment.