aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/bridge_rm.go8
-rw-r--r--identity/identity.go2
-rw-r--r--repository/git.go5
-rw-r--r--repository/git_test.go17
-rw-r--r--repository/mock_repo.go1
5 files changed, 29 insertions, 4 deletions
diff --git a/commands/bridge_rm.go b/commands/bridge_rm.go
index 5d38083c..1c840e8a 100644
--- a/commands/bridge_rm.go
+++ b/commands/bridge_rm.go
@@ -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 {
@@ -20,11 +23,12 @@ func runBridgeRm(cmd *cobra.Command, args []string) error {
return err
}
+ fmt.Printf("Successfully removed bridge configuration %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,
diff --git a/identity/identity.go b/identity/identity.go
index be3c16ec..f952bbf9 100644
--- a/identity/identity.go
+++ b/identity/identity.go
@@ -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/"
diff --git a/repository/git.go b/repository/git.go
index 801504f2..c8c45d6a 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -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
}
diff --git a/repository/git_test.go b/repository/git_test.go
index 32634cfb..8bd3aa8e 100644
--- a/repository/git_test.go
+++ b/repository/git_test.go
@@ -35,7 +35,6 @@ func TestConfig(t *testing.T) {
configs, err = repo.ReadConfigs("section")
assert.NoError(t, err)
-
assert.Equal(t, configs, map[string]string{
"section.key": "value",
})
@@ -43,9 +42,25 @@ func TestConfig(t *testing.T) {
_, 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)
+
}
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 2dc4868e..23534b89 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -103,6 +103,7 @@ func (r *mockRepoForTest) ReadConfigString(key string) (string, error) {
return val, nil
}
+// RmConfigs 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) {