@@ -544,24 +544,41 @@ static int ApplyGitDiff(IWinGetSQLiteIndex index, string repoPath, string fromSh
544544
545545 foreach ( var change in diff )
546546 {
547- string entryPath = change . Status == ChangeKind . Deleted ? change . OldPath : change . Path ;
548-
549- if ( ! entryPath . StartsWith ( "manifests/" , StringComparison . OrdinalIgnoreCase ) ||
550- ! entryPath . EndsWith ( ".yaml" , StringComparison . OrdinalIgnoreCase ) )
547+ // For renames, the old and new paths can be in different directories (e.g., a
548+ // version bump moves manifests from /1.0.0/ to /2.0.0/). We must record the
549+ // deletion against the OLD directory and the addition against the NEW directory
550+ // independently; collapsing both sides to a single path would cause the update
551+ // path to look up the wrong tree when extracting the pre-commit state.
552+
553+ // Old side: record deletion in the source directory.
554+ if ( change . Status == ChangeKind . Deleted || change . Status == ChangeKind . Renamed )
551555 {
552- continue ;
556+ string oldPath = change . OldPath ;
557+ if ( oldPath . StartsWith ( "manifests/" , StringComparison . OrdinalIgnoreCase ) &&
558+ oldPath . EndsWith ( ".yaml" , StringComparison . OrdinalIgnoreCase ) )
559+ {
560+ int lastSlash = oldPath . LastIndexOf ( '/' ) ;
561+ string dir = lastSlash > 0 ? oldPath [ ..lastSlash ] : string . Empty ;
562+ dirChanges . TryGetValue ( dir , out var flags ) ;
563+ dirChanges [ dir ] = ( flags . AnyAdded , true , flags . AnyModified ) ;
564+ }
553565 }
554566
555- int lastSlash = entryPath . LastIndexOf ( '/' ) ;
556- string dir = lastSlash > 0 ? entryPath [ ..lastSlash ] : string . Empty ;
557-
558- dirChanges . TryGetValue ( dir , out var flags ) ;
559- dirChanges [ dir ] = change . Status switch
567+ // New side: record addition/modification in the destination directory.
568+ if ( change . Status != ChangeKind . Deleted )
560569 {
561- ChangeKind . Added => ( true , flags . AnyDeleted , flags . AnyModified ) ,
562- ChangeKind . Deleted => ( flags . AnyAdded , true , flags . AnyModified ) ,
563- _ => ( flags . AnyAdded , flags . AnyDeleted , true ) ,
564- } ;
570+ string newPath = change . Path ;
571+ if ( newPath . StartsWith ( "manifests/" , StringComparison . OrdinalIgnoreCase ) &&
572+ newPath . EndsWith ( ".yaml" , StringComparison . OrdinalIgnoreCase ) )
573+ {
574+ int lastSlash = newPath . LastIndexOf ( '/' ) ;
575+ string dir = lastSlash > 0 ? newPath [ ..lastSlash ] : string . Empty ;
576+ dirChanges . TryGetValue ( dir , out var flags ) ;
577+ dirChanges [ dir ] = ( change . Status == ChangeKind . Added || change . Status == ChangeKind . Renamed )
578+ ? ( true , flags . AnyDeleted , flags . AnyModified )
579+ : ( flags . AnyAdded , flags . AnyDeleted , true ) ;
580+ }
581+ }
565582 }
566583
567584 if ( dirChanges . Count == 0 ) continue ; // No manifest changes in this commit
0 commit comments