Skip to content

Commit 85fcd49

Browse files
committed
chore(gates): keep rename origins unique across aggregate pairing
1 parent 1d0fdb3 commit 85fcd49

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎scripts/__tests__/committed-source-tree.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function renamedSince(
9494
for (const [file, origin] of origins) {
9595
if (origin !== null) renamed.set(file, origin);
9696
}
97+
const claimedOrigins = new Set(renamed.values());
9798
const aggregate = git(repoRoot, [
9899
'-c',
99100
'diff.renameLimit=0',
@@ -109,7 +110,10 @@ export function renamedSince(
109110
const from = aggregate[index++];
110111
if (kind?.startsWith('R')) {
111112
const to = aggregate[index++];
112-
if (from && to && !renamed.has(to) && !ended.has(to)) renamed.set(to, from);
113+
if (from && to && !renamed.has(to) && !ended.has(to) && !claimedOrigins.has(from)) {
114+
renamed.set(to, from);
115+
claimedOrigins.add(from);
116+
}
113117
}
114118
}
115119
return renamed;

‎scripts/__tests__/eager-closure-budgets.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,16 @@ test('a new file at a moved source cannot claim the original lineage when rename
560560
const paired = renamedSince(repo, base, 'HEAD');
561561
expect(paired.get('packages/demo/src/moved.ts')).toBe(original);
562562
expect(paired.has('packages/demo/src/new.ts')).toBe(false);
563+
fs.appendFileSync(
564+
path.join(repo, 'packages/demo/src/moved.ts'),
565+
'// public API documentation\n'.repeat(100),
566+
);
567+
fs.writeFileSync(path.join(repo, 'packages/demo/src/copy.ts'), 'export const a = 1;\n');
568+
execFileSync('git', ['add', '.'], { cwd: repo });
569+
execFileSync('git', ['commit', '-qm', 'copy old content'], { cwd: repo });
570+
const withCopy = renamedSince(repo, base, 'HEAD');
571+
expect(withCopy.get('packages/demo/src/moved.ts')).toBe(original);
572+
expect(withCopy.has('packages/demo/src/copy.ts')).toBe(false);
563573
});
564574

565575
test('rename detection survives a git mv with an edit and a hostile renameLimit', () => {

0 commit comments

Comments
 (0)