MCPcopy Create free account
hub / github.com/isomorphic-git/isomorphic-git / set

Method set

src/models/GitConfig.js:212–274  ·  view source on GitHub ↗
(path, value, append = false)

Source from the content-addressed store, hash-verified

210 }
211
212 async set(path, value, append = false) {
213 const {
214 section,
215 subsection,
216 name,
217 path: normalizedPath,
218 sectionPath,
219 isSection,
220 } = normalizePath(path)
221
222 const configIndex = findLastIndex(
223 this.parsedConfig,
224 config => config.path === normalizedPath
225 )
226 if (value == null) {
227 if (configIndex !== -1) {
228 this.parsedConfig.splice(configIndex, 1)
229 }
230 } else {
231 if (configIndex !== -1) {
232 const config = this.parsedConfig[configIndex]
233 // Name should be overwritten in case the casing changed
234 const modifiedConfig = Object.assign({}, config, {
235 name,
236 value,
237 modified: true,
238 })
239 if (append) {
240 this.parsedConfig.splice(configIndex + 1, 0, modifiedConfig)
241 } else {
242 this.parsedConfig[configIndex] = modifiedConfig
243 }
244 } else {
245 const sectionIndex = this.parsedConfig.findIndex(
246 config => config.path === sectionPath
247 )
248 const newConfig = {
249 section,
250 subsection,
251 name,
252 value,
253 modified: true,
254 path: normalizedPath,
255 }
256 if (SECTION_REGEX.test(section) && VARIABLE_NAME_REGEX.test(name)) {
257 if (sectionIndex >= 0) {
258 // Reuse existing section
259 this.parsedConfig.splice(sectionIndex + 1, 0, newConfig)
260 } else {
261 // Add a new section
262 const newSection = {
263 isSection,
264 section,
265 subsection,
266 modified: true,
267 path: sectionPath,
268 }
269 this.parsedConfig.push(newSection, newConfig)

Callers 12

appendMethod · 0.95
getRemoteHelperForMethod · 0.45
updateCachedIndexFileFunction · 0.45
acquireMethod · 0.45
updateRemoteRefsMethod · 0.45
constructorMethod · 0.45
readdirMethod · 0.45
fromIdxMethod · 0.45
fromPackMethod · 0.45
_addEntryMethod · 0.45
wrapMethod · 0.45
constructorMethod · 0.45

Calls 2

normalizePathFunction · 0.85
findLastIndexFunction · 0.85

Tested by

no test coverage detected