@shutootaki/gwm
Version:
git worktree manager CLI
67 lines • 2.15 kB
JavaScript
import { existsSync } from 'fs';
import { join } from 'path';
import { computeFileHash } from './hash.js';
import { getTrustedInfo } from './cache.js';
/**
* Verify the trust status of project hooks
*
* @param repoRoot Repository root path
* @param config Loaded configuration
* @param hasProjectHooks Whether the project config contains hooks
*/
export function verifyTrust(repoRoot, config, hasProjectHooks) {
// No hooks configured
const commands = config.hooks?.post_create?.commands ?? [];
if (commands.length === 0 || config.hooks?.post_create?.enabled === false) {
return { status: 'no-hooks' };
}
// Hooks from global config only are always trusted
if (!hasProjectHooks) {
return { status: 'global-config' };
}
// Verify project config hooks
const projectConfigPath = join(repoRoot, 'gwm', 'config.toml');
if (!existsSync(projectConfigPath)) {
// Project config file does not exist (global only)
return { status: 'global-config' };
}
// Compute hash with error handling
let currentHash;
try {
currentHash = computeFileHash(projectConfigPath);
}
catch {
// If file read fails (e.g., race condition), treat as first-time
return {
status: 'needs-confirmation',
reason: 'first-time',
commands,
configPath: projectConfigPath,
configHash: '',
};
}
const trustedInfo = getTrustedInfo(repoRoot);
if (!trustedInfo) {
// First time execution
return {
status: 'needs-confirmation',
reason: 'first-time',
commands,
configPath: projectConfigPath,
configHash: currentHash,
};
}
if (trustedInfo.configHash !== currentHash) {
// Config file has changed
return {
status: 'needs-confirmation',
reason: 'config-changed',
commands,
configPath: projectConfigPath,
configHash: currentHash,
};
}
// Trusted
return { status: 'trusted' };
}
//# sourceMappingURL=verifier.js.map