aboutsummaryrefslogtreecommitdiffstats
path: root/repository/git.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-05-27 21:18:46 +0200
committerMichael Muré <batolettre@gmail.com>2019-05-27 21:39:55 +0200
commitd564e37b317a2d59a9694d80b03b40e5d36f741f (patch)
treeba6bcdca38286372293b65f3c0b087cf95c066a1 /repository/git.go
parentc7abac388aadd274d4f23f996a15f8bba90f2a92 (diff)
downloadgit-bug-d564e37b317a2d59a9694d80b03b40e5d36f741f.tar.gz
repository: add ReadConfigBool and ReadConfigString functions
Diffstat (limited to 'repository/git.go')
-rw-r--r--repository/git.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/repository/git.go b/repository/git.go
index c982f820..4d6ca19a 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -8,6 +8,7 @@ import (
"io"
"os/exec"
"path"
+ "strconv"
"strings"
"github.com/MichaelMure/git-bug/util/git"
@@ -202,6 +203,40 @@ func (repo *GitRepo) ReadConfigs(keyPrefix string) (map[string]string, error) {
return result, nil
}
+func (repo *GitRepo) ReadConfigBool(key string) (bool, error) {
+ val, err := repo.ReadConfigString(key)
+ if err != nil {
+ return false, err
+ }
+
+ return strconv.ParseBool(val)
+}
+
+func (repo *GitRepo) ReadConfigString(key string) (string, error) {
+ stdout, err := repo.runGitCommand("config", "--get-all", key)
+
+ // / \
+ // / ! \
+ // -------
+ //
+ // 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 "", ErrNoConfigEntry
+ }
+
+ lines := strings.Split(stdout, "\n")
+
+ if len(lines) == 0 {
+ return "", ErrNoConfigEntry
+ }
+ if len(lines) > 1 {
+ return "", ErrMultipleConfigEntry
+ }
+
+ return lines[0], nil
+}
+
// RmConfigs remove all key/value pair matching the key prefix
func (repo *GitRepo) RmConfigs(keyPrefix string) error {
_, err := repo.runGitCommand("config", "--unset-all", keyPrefix)