git-bolt
Version:
Git utilities for faster development
57 lines (49 loc) • 1.82 kB
JavaScript
import chalk from 'chalk';
import fs from 'fs';
import git from 'isomorphic-git';
async function configCommand(configString) {
try {
if (!configString || !configString.includes('=')) {
console.error(chalk.red('Error: Invalid config format'));
console.log(chalk.yellow('Usage examples:'));
console.log(' npx git-bolt config author.name=John Doe');
console.log(' npx git-bolt config author.email=john@example.com');
process.exit(1);
}
const [path, value] = configString.split('=').map(s => s.trim());
// Validate path
if (!path || !value) {
console.error(chalk.red('Error: Both path and value are required'));
process.exit(1);
}
// Set the config value
await git.setConfig({
fs,
dir: '.',
path: path,
value: value
});
// Read back the value to confirm
const result = await git.getConfig({
fs,
dir: '.',
path: path
});
if (result?.value === value) {
console.log(chalk.green(`✓ Set ${path} = ${value}`));
} else {
console.error(chalk.red('Error: Failed to verify config value'));
process.exit(1);
}
} catch (error) {
if (error.message.includes('unable to resolve path')) {
console.error(chalk.red('Error: Git repository not initialized in this directory'));
console.log(chalk.yellow('Initialize repository first:'));
console.log(' npx git-bolt init <repository-url>');
} else {
console.error(chalk.red('Error setting config:'), error.message);
}
process.exit(1);
}
}
export { configCommand };