MCPcopy Create free account
hub / github.com/git-bug/git-bug / ReadString

Method ReadString

repository/gogit_config.go:108–151  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

106}
107
108func (cr *goGitConfigReader) ReadString(key string) (string, error) {
109 cfg, err := cr.getConfig()
110 if err != nil {
111 return "", err
112 }
113
114 split := strings.Split(key, ".")
115
116 if len(split) <= 1 {
117 return "", fmt.Errorf("invalid key")
118 }
119
120 sectionName := split[0]
121 if !cfg.Raw.HasSection(sectionName) {
122 return "", newErrNoConfigEntry(key)
123 }
124 section := cfg.Raw.Section(sectionName)
125
126 switch {
127 case len(split) == 2:
128 optionName := split[1]
129 if !section.HasOption(optionName) {
130 return "", newErrNoConfigEntry(key)
131 }
132 if len(section.OptionAll(optionName)) > 1 {
133 return "", newErrMultipleConfigEntry(key)
134 }
135 return section.Option(optionName), nil
136 default:
137 subsectionName := strings.Join(split[1:len(split)-1], ".")
138 optionName := split[len(split)-1]
139 if !section.HasSubsection(subsectionName) {
140 return "", newErrNoConfigEntry(key)
141 }
142 subsection := section.Subsection(subsectionName)
143 if !subsection.HasOption(optionName) {
144 return "", newErrNoConfigEntry(key)
145 }
146 if len(subsection.OptionAll(optionName)) > 1 {
147 return "", newErrMultipleConfigEntry(key)
148 }
149 return subsection.Option(optionName), nil
150 }
151}
152
153func (cr *goGitConfigReader) ReadTimestamp(key string) (time.Time, error) {
154 value, err := cr.ReadString(key)

Callers 2

ReadBoolMethod · 0.95
ReadTimestampMethod · 0.95

Calls 3

newErrNoConfigEntryFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected