git-bolt
Version:
Git utilities for faster development
44 lines (35 loc) • 1.11 kB
JavaScript
import chalk from 'chalk';
import fs from 'fs';
import git from 'isomorphic-git';
async function commitCommand(options) {
try {
const message = options.message || 'Update files';
// Get git author info
let author = {
name: 'Git Bolt User',
email: 'user@example.com'
};
// Try to read author from git config
try {
const name = await git.getConfig({ fs, dir: '.', path: 'user.name' });
const email = await git.getConfig({ fs, dir: '.', path: 'user.email' });
if (name) author.name = name;
if (email) author.email = email;
} catch (e) {
// Use default if config not available
}
// Add all changes that are already staged
console.log(chalk.blue('Committing staged changes...'));
const commitResult = await git.commit({
fs,
dir: '.',
message,
author
});
console.log(chalk.green(`Committed successfully: ${commitResult}`));
} catch (error) {
console.error(chalk.red('Error during commit:'), error.message);
process.exit(1);
}
}
export { commitCommand };