or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced.mdblame.mdcheckout.mdconfig.mddiff-status.mdindex-operations.mdindex.mdobjects.mdreferences.mdremotes.mdrepository.mdrevwalk.mdsignatures.md

config.mddocs/

0

# Configuration Management

1

2

Git configuration management for repository and global settings. The Config class provides access to Git configuration values with support for multiple configuration levels (system, global, local) and different data types.

3

4

## Core Imports

5

6

```javascript

7

const NodeGit = require('nodegit');

8

const Config = NodeGit.Config;

9

```

10

11

## Capabilities

12

13

### Configuration Access

14

15

Open and access different levels of Git configuration.

16

17

```javascript { .api }

18

/**

19

* Open the global configuration file

20

* @returns {Promise<Config>} Global configuration instance

21

*/

22

Config.openDefault(): Promise<Config>;

23

24

/**

25

* Open configuration at a specific path

26

* @param {String} path - Path to configuration file

27

* @returns {Promise<Config>} Configuration instance

28

*/

29

Config.openOndisk(path): Promise<Config>;

30

31

/**

32

* Create a priority-based configuration from multiple sources

33

* @param {Config[]} configs - Array of config instances in priority order

34

* @returns {Promise<Config>} Combined configuration

35

*/

36

Config.openLevel(configs): Promise<Config>;

37

38

/**

39

* Find and open the global configuration file

40

* @returns {Promise<Config>} Global configuration

41

*/

42

Config.findGlobal(): Promise<Config>;

43

44

/**

45

* Find and open the system configuration file

46

* @returns {Promise<Config>} System configuration

47

*/

48

Config.findSystem(): Promise<Config>;

49

```

50

51

### Configuration Values

52

53

Read and write configuration values with proper type handling.

54

55

```javascript { .api }

56

/**

57

* Get a string configuration value

58

* @param {String} name - Configuration key name

59

* @returns {Promise<String>} Configuration value

60

*/

61

getString(name): Promise<String>;

62

63

/**

64

* Get a string configuration value (legacy method)

65

* @param {String} name - Configuration key name

66

* @returns {Promise<String>} Configuration value

67

*/

68

getStringBuf(name): Promise<String>;

69

70

/**

71

* Get a boolean configuration value

72

* @param {String} name - Configuration key name

73

* @returns {Promise<Boolean>} Configuration value

74

*/

75

getBool(name): Promise<Boolean>;

76

77

/**

78

* Get an integer configuration value

79

* @param {String} name - Configuration key name

80

* @returns {Promise<Number>} Configuration value

81

*/

82

getInt32(name): Promise<Number>;

83

84

/**

85

* Get a 64-bit integer configuration value

86

* @param {String} name - Configuration key name

87

* @returns {Promise<Number>} Configuration value

88

*/

89

getInt64(name): Promise<Number>;

90

91

/**

92

* Set a string configuration value

93

* @param {String} name - Configuration key name

94

* @param {String} value - Value to set

95

* @returns {Promise<void>}

96

*/

97

setString(name, value): Promise<void>;

98

99

/**

100

* Set a boolean configuration value

101

* @param {String} name - Configuration key name

102

* @param {Boolean} value - Value to set

103

* @returns {Promise<void>}

104

*/

105

setBool(name, value): Promise<void>;

106

107

/**

108

* Set an integer configuration value

109

* @param {String} name - Configuration key name

110

* @param {Number} value - Value to set

111

* @returns {Promise<void>}

112

*/

113

setInt32(name, value): Promise<void>;

114

115

/**

116

* Set a 64-bit integer configuration value

117

* @param {String} name - Configuration key name

118

* @param {Number} value - Value to set

119

* @returns {Promise<void>}

120

*/

121

setInt64(name, value): Promise<void>;

122

```

123

124

### Configuration Management

125

126

Manage configuration entries and snapshots.

127

128

```javascript { .api }

129

/**

130

* Delete a configuration entry

131

* @param {String} name - Configuration key name

132

* @returns {Promise<void>}

133

*/

134

deleteEntry(name): Promise<void>;

135

136

/**

137

* Iterate over all configuration entries

138

* @param {Function} callback - Function called for each entry

139

* @returns {Promise<void>}

140

*/

141

foreach(callback): Promise<void>;

142

143

/**

144

* Create a snapshot of the current configuration

145

* @returns {Promise<Config>} Configuration snapshot

146

*/

147

snapshot(): Promise<Config>;

148

149

/**

150

* Lock the configuration for atomic updates

151

* @returns {Promise<void>}

152

*/

153

lock(): Promise<void>;

154

155

/**

156

* Unlock the configuration

157

* @returns {Promise<void>}

158

*/

159

unlock(): Promise<void>;

160

```

161

162

**Usage Examples:**

163

164

```javascript

165

const NodeGit = require('nodegit');

166

167

// Read user configuration

168

NodeGit.Config.openDefault()

169

.then(config => {

170

return Promise.all([

171

config.getString('user.name'),

172

config.getString('user.email')

173

]);

174

})

175

.then(([name, email]) => {

176

console.log(`User: ${name} <${email}>`);

177

});

178

179

// Set repository-specific configuration

180

NodeGit.Repository.open('./my-repo')

181

.then(repo => repo.config())

182

.then(config => {

183

return Promise.all([

184

config.setString('user.name', 'Repository User'),

185

config.setString('user.email', 'repo@example.com'),

186

config.setBool('core.autocrlf', false)

187

]);

188

})

189

.then(() => {

190

console.log('Repository configuration updated');

191

});

192

193

// Iterate over all configuration entries

194

NodeGit.Config.openDefault()

195

.then(config => {

196

return config.foreach((entry) => {

197

console.log(`${entry.name()} = ${entry.value()}`);

198

return 0; // continue iteration

199

});

200

});

201

```

202

203

## Types

204

205

```javascript { .api }

206

interface ConfigEntry {

207

/** Get the configuration key name */

208

name(): string;

209

/** Get the configuration value */

210

value(): string;

211

/** Get the configuration level */

212

level(): number;

213

}

214

```

215

216

## Configuration Levels

217

218

```javascript { .api }

219

Config.LEVEL = {

220

/** System-wide configuration */

221

SYSTEM: 1,

222

/** User global configuration */

223

GLOBAL: 2,

224

/** Repository local configuration */

225

LOCAL: 3,

226

/** Application-specific configuration */

227

APP: 4,

228

/** Highest priority level */

229

HIGHEST: -1

230

};

231

```

232

233

## Configuration Value Types

234

235

```javascript { .api }

236

Config.MAP = {

237

/** String value type */

238

STRING: 0,

239

/** Boolean value type */

240

BOOL: 1,

241

/** 32-bit integer value type */

242

INT32: 2,

243

/** 64-bit integer value type */

244

INT64: 3

245

};

246

```