Skip to content

Commit 9600b67

Browse files
authored
When searching for file by path, also search for the filepath before the file was renamed. (#1210)
1 parent 4dede86 commit 9600b67

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Service/CodeReview/DiffFinder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function findFileByPath(array $files, ?string $filePath): ?DiffFile
3232

3333
// filepath matched, but not the hash
3434
$partiallyMatchedFile = null;
35+
$renameMatchedFile = null;
3536

3637
foreach ($files as $file) {
3738
if ($file->getPathname() === $filePath) {
@@ -41,9 +42,12 @@ public function findFileByPath(array $files, ?string $filePath): ?DiffFile
4142
return $file;
4243
}
4344
}
45+
if ($file->isRename() && $file->filePathBefore === $filePath) {
46+
$renameMatchedFile = $file;
47+
}
4448
}
4549

46-
return $partiallyMatchedFile;
50+
return $partiallyMatchedFile ?? $renameMatchedFile;
4751
}
4852

4953
/**

tests/Unit/Service/CodeReview/DiffFinderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testFindFileByPath(): void
4242

4343
static::assertNull($this->finder->findFileByPath($files, null));
4444
static::assertSame($fileA, $this->finder->findFileByPath($files, '/path/to/file/deleted.txt'));
45-
static::assertNull($this->finder->findFileByPath($files, '/path/to/file/changed.txt'));
45+
static::assertSame($fileB, $this->finder->findFileByPath($files, '/path/to/file/changed.txt'));
4646
static::assertSame($fileB, $this->finder->findFileByPath($files, '/path/to/file/changed.doc'));
4747
static::assertSame($fileC, $this->finder->findFileByPath($files, '/path/to/file/created.txt'));
4848

0 commit comments

Comments
 (0)