From 2c4c0132bf8c9e9819cc9a76d4a04ed4daeedb3b Mon Sep 17 00:00:00 2001 From: Sladyn Date: Sat, 25 May 2019 15:13:40 +0200 Subject: Add GetRemotes functionalities --- repository/git.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'repository/git.go') diff --git a/repository/git.go b/repository/git.go index 4d6ca19a0..801504f2e 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) -- cgit v1.2.3