aboutsummaryrefslogtreecommitdiffstats
path: root/repository
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-24 16:24:38 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-24 16:24:38 +0200
commit061e83d4b4aa66c2691b3699a3e770b2a58d26df (patch)
treeab82b815a91054fc498dbd7564cc61322b5fd338 /repository
parent43bda202fa347e6893671b05376c0e4fcb9196f4 (diff)
downloadgit-bug-061e83d4b4aa66c2691b3699a3e770b2a58d26df.tar.gz
commands: add "bridge rm"
Diffstat (limited to 'repository')
-rw-r--r--repository/git.go15
-rw-r--r--repository/mock_repo.go9
-rw-r--r--repository/repo.go3
3 files changed, 26 insertions, 1 deletions
diff --git a/repository/git.go b/repository/git.go
index 51c4f46b..af251aa2 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -170,8 +170,14 @@ func (repo *GitRepo) StoreConfig(key string, value string) error {
func (repo *GitRepo) ReadConfigs(keyPrefix string) (map[string]string, error) {
stdout, err := repo.runGitCommand("config", "--get-regexp", keyPrefix)
+ // / \
+ // / ! \
+ // -------
+ //
+ // There can be a legitimate error here, but I see no portable way to
+ // distinguish them from the git error that say "no matching value exist"
if err != nil {
- return nil, err
+ return nil, nil
}
lines := strings.Split(stdout, "\n")
@@ -194,6 +200,13 @@ func (repo *GitRepo) ReadConfigs(keyPrefix string) (map[string]string, error) {
return result, nil
}
+// RmConfigs remove all key/value pair matching the key prefix
+func (repo *GitRepo) RmConfigs(keyPrefix string) error {
+ _, err := repo.runGitCommand("config", "--remove-section", keyPrefix)
+
+ return err
+}
+
// FetchRefs fetch git refs from a remote
func (repo *GitRepo) FetchRefs(remote, refSpec string) (string, error) {
stdout, err := repo.runGitCommand("fetch", remote, refSpec)
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 2389a8e0..74de8f57 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -73,6 +73,15 @@ func (r *mockRepoForTest) ReadConfigs(keyPrefix string) (map[string]string, erro
return result, nil
}
+func (r *mockRepoForTest) RmConfigs(keyPrefix string) error {
+ for key := range r.config {
+ if strings.HasPrefix(key, keyPrefix) {
+ delete(r.config, key)
+ }
+ }
+ return nil
+}
+
// PushRefs push git refs to a remote
func (r *mockRepoForTest) PushRefs(remote string, refSpec string) (string, error) {
return "", nil
diff --git a/repository/repo.go b/repository/repo.go
index c029a145..d0004c8b 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -28,6 +28,9 @@ type RepoCommon interface {
// ReadConfigs read all key/value pair matching the key prefix
ReadConfigs(keyPrefix string) (map[string]string, error)
+
+ // RmConfigs remove all key/value pair matching the key prefix
+ RmConfigs(keyPrefix string) error
}
// Repo represents a source code repository.