saadeghi/daisyui · error · Error

git ${args[0]} failed: ${details}

Error message

git ${args[0]} failed: ${details}

What it means

Thrown by the git() helper in pr-preview.mjs when execFileSync("git", args, ...) exited non-zero. The error message embeds the trimmed git stderr (or, if stderr is empty, the underlying error.message). The args[0] names which git subcommand failed.

Source

Thrown at packages/tailwind-play-share/pr-preview.mjs:101

      default:
        throw new Error(`Unknown option: ${argument}`)
    }
  }

  return options
}

function git(args) {
  try {
    return execFileSync("git", args, {
      cwd: repositoryRoot,
      encoding: "utf8",
      maxBuffer: 32 * 1024 * 1024,
      stdio: ["ignore", "pipe", "pipe"],
    })
  } catch (error) {
    const details = error.stderr?.trim() || error.message
    throw new Error(`git ${args[0]} failed: ${details}`)
  }
}

function componentNameFromPath(filePath) {
  return filePath.match(componentPathPattern)?.[1]
}

function isCssWhitespace(character) {
  return (
    character === " " ||
    character === "\n" ||
    character === "\r" ||
    character === "\t" ||
    character === "\f"
  )
}

function isCssHexDigit(character) {

View on GitHub (pinned to 42b09e637e)

Solutions

  1. Ensure both SHAs exist locally: `git cat-file -e ${sha}^{commit}`.
  2. Run inside the repository root with git on PATH.
  3. For shallow CI clones, deepen or fetch the base: `git fetch --depth=100 origin ${baseSha}`.
  4. Read the embedded git stderr - it states the exact git error.

Example fix

# before (shallow clone missing base)
pr-preview --base-sha $BASE --head-sha $HEAD --output out.json

# after
git fetch --unshallow  # or: git fetch origin $BASE
git cat-file -e ${BASE}^{commit} && git cat-file -e ${HEAD}^{commit}
pr-preview --base-sha $BASE --head-sha $HEAD --output out.json
Defensive patterns

Strategy: try-catch

Validate before calling

import { execSync } from "node:child_process"
function assertCommitsExist(...shas) {
  for (const sha of shas) {
    execSync(`git cat-file -e ${sha}^{commit}`, { stdio: "ignore" })
  }
}
assertCommitsExist(baseSha, headSha)

Try / catch

try {
  await generatePrPreview({ baseSha, headSha, output })
} catch (error) {
  if (/^git (diff|ls-tree|show) failed:/.test(error.message)) {
  // fetch missing commits, deepen clone, then retry
  }
  throw error
}

Prevention

When it happens

Trigger: Any git invocation inside buildPreviewInputs/listDocsPages/readFileAtRevision fails: `git diff`, `git ls-tree`, or `git show`. Triggers when the commit SHAs are missing/unknown, the pathspec matches nothing, or git is absent.

Common situations: Passing a base/head SHA that does not exist in the local clone (common in shallow CI checkouts), running outside a git repo, git not on PATH, or a shallow clone missing the base commit depth.

Related errors


AI-assisted analysis of saadeghi/daisyui@42b09e637e (2026-08-13). Data as JSON: /api/errors/d699aae35cb4b0dd. Report an issue: GitHub.