fix(pncc): resolve committed artifacts from exact tree entries

This commit is contained in:
冰朔 2026-09-03 12:24:25 +08:00
commit 4117696ad8

View file

@ -76,10 +76,13 @@ function exactGitRoot(repository) {
function committedArtifact(repository, head, path) { function committedArtifact(repository, head, path) {
validateRelativePath(path) validateRelativePath(path)
const object = validateFullHead(String(runGit(repository, ['rev-parse', `${head}:${path}`], 'PNCC_GIT_OBJECT_ID_READ')).trim().toLowerCase()) const treeEntry = String(runGit(repository, ['ls-tree', head, '--', path], 'PNCC_GIT_TREE_ENTRY_READ')).trim()
const match = treeEntry.match(/^([0-9]{6}) blob ([0-9a-f]{40})\t(.+)$/u)
if (!match || match[3] !== path) fail('PNCC_COMMITTED_PATH_NOT_EXACT_BLOB', path)
const mode = match[1]
const object = validateFullHead(match[2].toLowerCase())
const type = String(runGit(repository, ['cat-file', '-t', object], 'PNCC_GIT_OBJECT_TYPE_READ')).trim() const type = String(runGit(repository, ['cat-file', '-t', object], 'PNCC_GIT_OBJECT_TYPE_READ')).trim()
if (type !== 'blob') fail('PNCC_COMMITTED_OBJECT_NOT_BLOB', path) if (type !== 'blob') fail('PNCC_COMMITTED_OBJECT_NOT_BLOB', path)
const mode = String(runGit(repository, ['ls-tree', head, '--', path], 'PNCC_GIT_OBJECT_MODE_READ')).trim().split(/\s+/u)[0]
if (!['100644', '100755'].includes(mode)) fail('PNCC_COMMITTED_OBJECT_NOT_REGULAR_FILE', path) if (!['100644', '100755'].includes(mode)) fail('PNCC_COMMITTED_OBJECT_NOT_REGULAR_FILE', path)
const bytes = runGit(repository, ['cat-file', 'blob', object], 'PNCC_GIT_OBJECT_READ', { encoding: 'buffer' }) const bytes = runGit(repository, ['cat-file', 'blob', object], 'PNCC_GIT_OBJECT_READ', { encoding: 'buffer' })
if (!Buffer.isBuffer(bytes) || bytes.length === 0 || bytes.length > MAX_ARTIFACT_BYTES) { if (!Buffer.isBuffer(bytes) || bytes.length === 0 || bytes.length > MAX_ARTIFACT_BYTES) {