( opts: ConfigGetWithDeps, )
| 227 | * --get` which exits 1 with no output for an unknown key. |
| 228 | */ |
| 229 | export async function configGetWith( |
| 230 | opts: ConfigGetWithDeps, |
| 231 | ): Promise<string | string[] | undefined> { |
| 232 | const dir = opts.dir ?? "/"; |
| 233 | try { |
| 234 | if (opts.all) { |
| 235 | const values = await opts.git.getConfigAll({ fs: opts.fs, dir, path: opts.path }); |
| 236 | return values.map((v) => String(v)); |
| 237 | } |
| 238 | const value = await opts.git.getConfig({ fs: opts.fs, dir, path: opts.path }); |
| 239 | if (value === undefined || value === null) return undefined; |
| 240 | return String(value); |
| 241 | } catch (cause) { |
| 242 | if (isNotARepositoryCause(cause)) throw new NotARepositoryError(dir, { cause }); |
| 243 | throw new GitError("ECONFIGFAIL", `git config failed: ${errorMessage(cause)}`, { |
| 244 | cause, |
| 245 | }); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | export interface GitConfigSetOptions { |
| 250 | dir?: string; |
no test coverage detected