Skip to content

Commit

Permalink
Changes to Repo.RmConfigs
Browse files Browse the repository at this point in the history
RmConfigs try to remove key/value or section from keyPrefix
  • Loading branch information
a-hilaly committed Jun 17, 2019
1 parent 470996a commit ee2ca51
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
8 changes: 6 additions & 2 deletions commands/bridge_rm.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package commands

import (
"fmt"

"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/bridge"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/util/interrupt"
"github.com/spf13/cobra"
)

func runBridgeRm(cmd *cobra.Command, args []string) error {
Expand All @@ -20,11 +23,12 @@ func runBridgeRm(cmd *cobra.Command, args []string) error {
return err
}

fmt.Printf("Successfully deleted bridge %v", args[0])
return nil
}

var bridgeRmCmd = &cobra.Command{
Use: "rm name <name>",
Use: "rm <name>",
Short: "Delete a configured bridge.",
PreRunE: loadRepo,
RunE: runBridgeRm,
Expand Down
2 changes: 1 addition & 1 deletion identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"strings"
"time"

"github.com/MichaelMure/git-bug/util/timestamp"
"github.com/pkg/errors"

"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/lamport"
"github.com/MichaelMure/git-bug/util/timestamp"
)

const identityRefPattern = "refs/identities/"
Expand Down
5 changes: 5 additions & 0 deletions repository/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ func (repo *GitRepo) ReadConfigString(key string) (string, error) {

// RmConfigs remove all key/value pair matching the key prefix
func (repo *GitRepo) RmConfigs(keyPrefix string) error {
// try to remove key/value pair by key
_, err := repo.runGitCommand("config", "--unset-all", keyPrefix)
if err != nil {
// try to remove section
_, err = repo.runGitCommand("config", "--remove-section", keyPrefix)
}

return err
}
Expand Down
17 changes: 16 additions & 1 deletion repository/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,32 @@ func TestConfig(t *testing.T) {

configs, err = repo.ReadConfigs("section")
assert.NoError(t, err)

assert.Equal(t, configs, map[string]string{
"section.key": "value",
})

_, err = repo.ReadConfigBool("section.true")
assert.Equal(t, ErrNoConfigEntry, err)

err = repo.RmConfigs("section.nonexistingkey")
assert.Error(t, err)

err = repo.RmConfigs("section.key")
assert.NoError(t, err)

_, err = repo.ReadConfigString("section.key")
assert.Equal(t, ErrNoConfigEntry, err)

err = repo.RmConfigs("nonexistingsection")
assert.Error(t, err)

err = repo.RmConfigs("section")
assert.NoError(t, err)

_, err = repo.ReadConfigString("section.key")
assert.Error(t, err)

err = repo.RmConfigs("section.key")
assert.Error(t, err)

}
1 change: 1 addition & 0 deletions repository/mock_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (r *mockRepoForTest) ReadConfigString(key string) (string, error) {
return val, nil
}

// RmConfig remove all key/value pair matching the key prefix
func (r *mockRepoForTest) RmConfigs(keyPrefix string) error {
for key := range r.config {
if strings.HasPrefix(key, keyPrefix) {
Expand Down

0 comments on commit ee2ca51

Please sign in to comment.