/**
 * Get the current Git commit hash.
 * @returns The current Git commit hash, or null if it cannot be determined.
 */
export async function getGitCommitHash(): Promise<string | null> {
  if (process.env.SOURCE_COMMIT) {
    return process.env.SOURCE_COMMIT
  }

  try {
    const { exec } = await import('child_process')
    const hash = await new Promise<string>((res, rej) => {
      exec('git rev-parse HEAD', (err, stdout) => (err ? rej(err) : res(stdout.trim())))
    })
    return hash
  } catch {
    return null
  }
}
