All files / packages/design-system/scripts/core get-sha.js

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                        16x 16x         3x          
/**
 * Get SHA utility
 * Returns the git SHA for the current commit
 */
import { execSync } from 'node:child_process';
 
/**
 * Get the SHA for the current git commit
 * @param {string} cwd - Current working directory
 * @returns {string} SHA or 'development' if not in a git repo
 */
export function getSha(cwd) {
  try {
    return execSync('git rev-parse --short HEAD', {
      cwd,
      encoding: 'utf8',
    }).trim();
  } catch (e) {
    return 'development';
  }
}
 
export default getSha;