fix(integration): make private ref cas atomic

TASK-f40126ee-2485-45c8-a67b-4279e4e8704a
This commit is contained in:
thePR0M3TH3AN committed 2026-10-03 17:20:48 -04:00
1 parent 97973f0566
commit 8ea3bef13e
1 file changed
+7 -1
+7 -1
View File
@@ -112,11 +112,17 @@ export class GitPrivateRefAdapter {
compareAndSwapRefs({ expected = [], writes = [] } = {}) {
const commands = ['start'];
const writtenRefs = new Set(writes.map((entry) => entry.ref));
for (const { ref, sha: expectedSha } of expected) {
if (writtenRefs.has(ref)) continue;
commands.push(`verify ${text(ref, 'ref')} ${expectedSha ?? ZERO_SHA}`);
}
for (const { ref, sha: nextSha } of writes) {
const current = expected.find((entry) => entry.ref === ref)?.sha ?? null;
const expectedEntry = expected.find((entry) => entry.ref === ref);
if (!expectedEntry) throw new TorchError('Every private-ref write requires an exact expected value', {
code: 'ADOPTION_REF_CAS_EXPECTED_REQUIRED', details: { ref },
});
const current = expectedEntry.sha ?? null;
if (nextSha === null) commands.push(`delete ${text(ref, 'ref')} ${current ?? ZERO_SHA}`);
else commands.push(`update ${text(ref, 'ref')} ${sha(nextSha, 'next ref sha')} ${current ?? ZERO_SHA}`);
}