@jasondark/proompt
Version:
CLI tool for running AI prompts with structure and repeatability
65 lines • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getShortCommitHash = exports.getGitDiff = exports.getCurrentCommitHash = exports.isGitRepository = void 0;
const child_process_1 = require("child_process");
/**
* Check if the current directory is a git repository
*/
const isGitRepository = () => {
try {
(0, child_process_1.execSync)('git rev-parse --git-dir', { stdio: 'ignore' });
return true;
}
catch {
return false;
}
};
exports.isGitRepository = isGitRepository;
/**
* Get the current git commit hash
* @returns The current commit hash or null if not in a git repository
*/
const getCurrentCommitHash = () => {
try {
if (!(0, exports.isGitRepository)()) {
return null;
}
const hash = (0, child_process_1.execSync)('git rev-parse HEAD', { encoding: 'utf8' }).trim();
return hash;
}
catch {
return null;
}
};
exports.getCurrentCommitHash = getCurrentCommitHash;
/**
* Get git diff between two commits
* @param fromCommit The starting commit hash
* @param toCommit The ending commit hash (defaults to HEAD)
* @returns The git diff output or null if error
*/
const getGitDiff = (fromCommit, toCommit = 'HEAD') => {
try {
if (!(0, exports.isGitRepository)()) {
return null;
}
const diff = (0, child_process_1.execSync)(`git diff ${fromCommit} ${toCommit}`, {
encoding: 'utf8',
});
return diff;
}
catch {
return null;
}
};
exports.getGitDiff = getGitDiff;
/**
* Get a short version of the commit hash (first 7 characters)
* @returns The short commit hash or null if not in a git repository
*/
const getShortCommitHash = () => {
const fullHash = (0, exports.getCurrentCommitHash)();
return fullHash ? fullHash.substring(0, 7) : null;
};
exports.getShortCommitHash = getShortCommitHash;
//# sourceMappingURL=git.js.map