diff options
author | Sladyn <gunnerforlife00@gmail.com> | 2019-05-25 15:13:40 +0200 |
---|---|---|
committer | Amine Hilaly <hilalyamine@gmail.com> | 2019-05-29 22:58:01 +0200 |
commit | 2c4c0132bf8c9e9819cc9a76d4a04ed4daeedb3b (patch) | |
tree | e8c4e4c0f44fa614c3c8191ebe3d61f9776a7706 /repository | |
parent | f01b9bca12cb51f1f8f46b5e58bb3cb4be8126de (diff) | |
download | git-bug-2c4c0132bf8c9e9819cc9a76d4a04ed4daeedb3b.tar.gz |
Add GetRemotes functionalities
Diffstat (limited to 'repository')
-rw-r--r-- | repository/git.go | 22 | ||||
-rw-r--r-- | repository/mock_repo.go | 7 | ||||
-rw-r--r-- | repository/repo.go | 3 |
3 files changed, 32 insertions, 0 deletions
diff --git a/repository/git.go b/repository/git.go index 4d6ca19a..801504f2 100644 --- a/repository/git.go +++ b/repository/git.go @@ -162,6 +162,28 @@ func (repo *GitRepo) GetCoreEditor() (string, error) { return repo.runGitCommand("var", "GIT_EDITOR") } +// GetRemotes returns the configured remotes repositories. +func (repo *GitRepo) GetRemotes() (map[string]string, error) { + stdout, err := repo.runGitCommand("remote", "--verbose") + if err != nil { + return nil, err + } + + lines := strings.Split(stdout, "\n") + remotes := make(map[string]string, len(lines)) + + for _, line := range lines { + elements := strings.Fields(line) + if len(elements) != 3 { + return nil, fmt.Errorf("unexpected output format: %s", line) + } + + remotes[elements[0]] = elements[1] + } + + return remotes, nil +} + // StoreConfig store a single key/value pair in the config of the repo func (repo *GitRepo) StoreConfig(key string, value string) error { _, err := repo.runGitCommand("config", "--replace-all", key, value) diff --git a/repository/mock_repo.go b/repository/mock_repo.go index 14f5e7b5..2dc4868e 100644 --- a/repository/mock_repo.go +++ b/repository/mock_repo.go @@ -59,6 +59,13 @@ func (r *mockRepoForTest) GetCoreEditor() (string, error) { return "vi", nil } +// GetRemotes returns the configured remotes repositories. +func (r *mockRepoForTest) GetRemotes() (map[string]string, error) { + return map[string]string{ + "origin": "git://github.com/MichaelMure/git-bug", + }, nil +} + func (r *mockRepoForTest) StoreConfig(key string, value string) error { r.config[key] = value return nil diff --git a/repository/repo.go b/repository/repo.go index f3c2de6d..44204493 100644 --- a/repository/repo.go +++ b/repository/repo.go @@ -27,6 +27,9 @@ type RepoCommon interface { // GetCoreEditor returns the name of the editor that the user has used to configure git. GetCoreEditor() (string, error) + // GetRemotes returns the configured remotes repositories. + GetRemotes() (map[string]string, error) + // StoreConfig store a single key/value pair in the config of the repo StoreConfig(key string, value string) error |