setConfig
Write an entry to the git config files.
param | type [= default] | description |
---|---|---|
fs | FsClient | a file system implementation |
dir | string | The working tree directory path |
gitdir | string = join(dir,'.git') | The git directory path |
path | string | The key of the git config entry |
value | string | boolean | number | void | A value to store at that path. (Use undefined as the value to delete a config entry.) |
append | boolean = false | If true, will append rather than replace when setting (use with multi-valued config options). |
return | Promise<void> | Resolves successfully when operation completed |
Caveats:
- Currently only the local
$GIT_DIR/config
file can be read or written. However support for the global~/.gitconfig
and system$(prefix)/etc/gitconfig
will be added in the future. - The current parser does not support the more exotic features of the git-config file format such as
[include]
and[includeIf]
.
Example Code:
// Write config value
await git.setConfig({
fs,
dir: '/tutorial',
path: 'user.name',
value: 'Mr. Test'
})
// Print out config file
let file = await fs.promises.readFile('/tutorial/.git/config', 'utf8')
console.log(file)
// Delete a config entry
await git.setConfig({
fs,
dir: '/tutorial',
path: 'user.name',
value: undefined
})
// Print out config file
file = await fs.promises.readFile('/tutorial/.git/config', 'utf8')
console.log(file)
Tip: If you need a clean slate, expand and run this snippet to clean up the file system.
window.fs = new LightningFS('fs', { wipe: true })
window.pfs = window.fs.promises
console.log('done')