@@ -537,12 +537,31 @@ test('later edits preserve a committed rename but deletion ends its lineage', ()
537537 ) ;
538538 execFileSync ( 'git' , [ 'rm' , moved ] , { cwd : repo } ) ;
539539 execFileSync ( 'git' , [ 'commit' , '-qm' , 'remove' ] , { cwd : repo } ) ;
540- fs . writeFileSync ( path . join ( repo , moved ) , 'export const unrelated = true;\n' ) ;
540+ fs . writeFileSync (
541+ path . join ( repo , moved ) ,
542+ createCommittedSourceTree ( repo , base ) . readFile ( path . join ( repo , 'packages/demo/src/entry.ts' ) ) ,
543+ ) ;
541544 execFileSync ( 'git' , [ 'add' , moved ] , { cwd : repo } ) ;
542545 execFileSync ( 'git' , [ 'commit' , '-qm' , 'new entry' ] , { cwd : repo } ) ;
543546 expect ( renamedSince ( repo , base , 'HEAD' ) . has ( moved ) ) . toBe ( false ) ;
544547} ) ;
545548
549+ test ( 'a new file at a moved source cannot claim the original lineage when renamed' , ( ) => {
550+ const repo = mkGitFixtureRepo ( 'renamed-since-reused-source-' ) ;
551+ const base = execFileSync ( 'git' , [ 'rev-parse' , 'HEAD' ] , { cwd : repo } ) . toString ( ) . trim ( ) ;
552+ const original = 'packages/demo/src/entry.ts' ;
553+ execFileSync ( 'git' , [ 'mv' , original , 'packages/demo/src/moved.ts' ] , { cwd : repo } ) ;
554+ execFileSync ( 'git' , [ 'commit' , '-qm' , 'move' ] , { cwd : repo } ) ;
555+ fs . writeFileSync ( path . join ( repo , original ) , 'export const a = 1;\n' ) ;
556+ execFileSync ( 'git' , [ 'add' , original ] , { cwd : repo } ) ;
557+ execFileSync ( 'git' , [ 'commit' , '-qm' , 'new source' ] , { cwd : repo } ) ;
558+ execFileSync ( 'git' , [ 'mv' , original , 'packages/demo/src/new.ts' ] , { cwd : repo } ) ;
559+ execFileSync ( 'git' , [ 'commit' , '-qm' , 'move new source' ] , { cwd : repo } ) ;
560+ const paired = renamedSince ( repo , base , 'HEAD' ) ;
561+ expect ( paired . get ( 'packages/demo/src/moved.ts' ) ) . toBe ( original ) ;
562+ expect ( paired . has ( 'packages/demo/src/new.ts' ) ) . toBe ( false ) ;
563+ } ) ;
564+
546565test ( 'rename detection survives a git mv with an edit and a hostile renameLimit' , ( ) => {
547566 // The daemon move is the load-bearing case: `git mv` PLUS a per-file edit makes the rename
548567 // inexact, and a clone-side `diff.renameLimit` below the file count silently disables the
0 commit comments