@@ -111,13 +111,23 @@ type changesSinceContext struct {
111111 olderDiff []* diff.FileDiff
112112}
113113
114+ func diffToFilename (d * diff.FileDiff ) string {
115+ if d .NewName == "/dev/null" {
116+ // For deleted files, NewName is "/dev/null", so use OrigName instead
117+ return d .OrigName [2 :]
118+ }
119+ return d .NewName [2 :]
120+ }
121+
114122// Parse the diff output to get the file names and hunks
115123func toDiffFiles (fileDiffs []* diff.FileDiff ) ([]codeowners.DiffFile , error ) {
116124 diffFiles := make ([]codeowners.DiffFile , 0 , len (fileDiffs ))
117125
118126 for _ , d := range fileDiffs {
127+ fileName := diffToFilename (d )
128+
119129 newDiffFile := codeowners.DiffFile {
120- FileName : d . NewName [ 2 :] ,
130+ FileName : fileName ,
121131 Hunks : make ([]codeowners.HunkRange , 0 , len (d .Hunks )),
122132 }
123133 for _ , hunk := range d .Hunks {
@@ -147,8 +157,10 @@ func changesSince(context changesSinceContext) ([]codeowners.DiffFile, error) {
147157 diffFiles := make ([]codeowners.DiffFile , 0 , len (context .newerDiff ))
148158
149159 for _ , d := range context .newerDiff {
160+ fileName := diffToFilename (d )
161+
150162 newDiffFile := codeowners.DiffFile {
151- FileName : d . NewName [ 2 :] ,
163+ FileName : fileName ,
152164 Hunks : make ([]codeowners.HunkRange , 0 , len (d .Hunks )),
153165 }
154166 for _ , hunk := range d .Hunks {
@@ -177,8 +189,10 @@ func getGitDiff(data DiffContext, executor gitCommandExecutor) ([]*diff.FileDiff
177189 return nil , err
178190 }
179191 gitDiff = slices .DeleteFunc (gitDiff , func (d * diff.FileDiff ) bool {
192+ fileName := diffToFilename (d )
193+
180194 for _ , dir := range data .IgnoreDirs {
181- if strings .HasPrefix (d . NewName [ 2 :] , dir ) {
195+ if strings .HasPrefix (fileName , dir ) {
182196 return true
183197 }
184198 }
0 commit comments