INNER CODE UNIT · JavaScript

calculateFileHash

rancher/terraform-provider-rancher2 · agent-scripts/gating.js:8

export function calculateFileHash(filePath) {
  try {
    const content = fs.readFileSync(filePath);
    return crypto.createHash('sha256').update(content).digest('hex');
  } catch (err) {
    console.error('🔒 Hook Debug: calculateFileHash failed:', err.message || err);
    return null;
  }
}

// Calculate active local diff hash securely (staged + unstaged combined, relative to main on feature branches)
export function calculateDiffHash() {
  try {
    const currentBranch = execSync('git branch --show-current', { stdio: ['ignore', 'pipe', 'ignore'] })
      .toString()
      .trim();
    const diffCmdArgs = currentBranch !== 'main' && currentBranch !== '' ? ['diff', 'main'] : ['diff', 'HEAD'];
    const diff = execFileSync('git', diffCmdArgs, { stdio: ['ignore', 'pipe', 'ignore'] }).toString();

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…