Skip to content

Commit

Permalink
Merge pull request #14 from BoGnY/main
Browse files Browse the repository at this point in the history
Fix directory separation problems on Windows machine
  • Loading branch information
TomasVotruba authored Sep 28, 2023
2 parents b4cbe14 + b8d0452 commit f63c6f4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Differ/PatchDiffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Nette\Utils\Strings;
use SebastianBergmann\Diff\Differ;
use Symplify\VendorPatches\Exception\ShouldNotHappenException;
use Symplify\VendorPatches\Utils\FileSystemHelper;
use Symplify\VendorPatches\ValueObject\OldAndNewFile;

/**
Expand Down Expand Up @@ -50,7 +51,7 @@ public function diff(OldAndNewFile $oldAndNewFile): string

private function resolveRelativeFilePath(string $beforeFilePath): string
{
$match = Strings::match($beforeFilePath, self::LOCAL_PATH_REGEX);
$match = Strings::match(FileSystemHelper::normalizePath($beforeFilePath), self::LOCAL_PATH_REGEX);

if (! isset($match['local_path'])) {
throw new ShouldNotHappenException();
Expand Down
3 changes: 2 additions & 1 deletion src/FileSystem/PathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Utils\Strings;
use Symplify\VendorPatches\Exception\ShouldNotHappenException;
use Symplify\VendorPatches\Utils\FileSystemHelper;
use Webmozart\Assert\Assert;

final class PathResolver
Expand All @@ -18,7 +19,7 @@ final class PathResolver

public static function resolveVendorDirectory(string $filePath): string
{
$match = Strings::match($filePath, self::VENDOR_PACKAGE_DIRECTORY_REGEX);
$match = Strings::match(FileSystemHelper::normalizePath($filePath), self::VENDOR_PACKAGE_DIRECTORY_REGEX);
if (! isset($match['vendor_package_directory'])) {
throw new ShouldNotHappenException('Could not resolve vendor package directory');
}
Expand Down
16 changes: 16 additions & 0 deletions src/Utils/FileSystemHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Symplify\VendorPatches\Utils;

final class FileSystemHelper
{
/**
* Converts backslashes to slashes.
*/
public static function normalizePath(string $path): string
{
return str_replace('\\', '/', $path);
}
}
3 changes: 2 additions & 1 deletion tests/PatchFileFactory/PatchFileFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Symplify\VendorPatches\PatchFileFactory;
use Symplify\VendorPatches\Tests\AbstractTestCase;
use Symplify\VendorPatches\Utils\FileSystemHelper;
use Symplify\VendorPatches\ValueObject\OldAndNewFile;

final class PatchFileFactoryTest extends AbstractTestCase
Expand All @@ -21,6 +22,6 @@ public function test(): void
);

$pathFilePath = $patchFileFactory->createPatchFilePath($oldAndNewFile, __DIR__ . '/Fixture');
$this->assertSame('patches/some-new-file-php.patch', $pathFilePath);
$this->assertSame('patches/some-new-file-php.patch', FileSystemHelper::normalizePath($pathFilePath));
}
}

0 comments on commit f63c6f4

Please sign in to comment.