Skip to content
Extraits de code Groupes Projets
Valider 2806c06a rédigé par JamesRezo's avatar JamesRezo :tada:
Parcourir les fichiers

feat(mode-dev): git command lines in RemoteUrls

parent 97315acb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -2,6 +2,9 @@
namespace Spip\Composer\Git;
use Composer\IO\IOInterface;
use Composer\Util\ProcessExecutor;
/**
* git utilities
* @since 0.6.0
......@@ -14,6 +17,13 @@ class RemoteUrls
'git.spip.net',
];
private ProcessExecutor $processor;
public function __construct(private IOInterface $io)
{
$this->processor = new ProcessExecutor($io);
}
protected function regexp(): string
{
return '(' . \implode('|', \str_replace('.', '\.',$this->matching)) . ')';
......@@ -34,4 +44,19 @@ class RemoteUrls
{
return \preg_replace(',git@'.$this->regexp().':,', 'https://$1/', $url);
}
public function getRemote(string $path): string
{
return 'git -C '.$path.' remote get-url origin';
}
public function setRemote(string $path, string $newUrl): string
{
return 'git -C '.$path.' remote set-url origin '.$newUrl;
}
public function getProcessor(): ProcessExecutor
{
return $this->processor;
}
}
......@@ -3,7 +3,6 @@
namespace Spip\Composer;
use Composer\Script\Event;
use Composer\Util\ProcessExecutor;
use Spip\Composer\Git\RemoteUrls;
class ModeDev
......@@ -11,7 +10,7 @@ class ModeDev
public static function activate(Event $event)
{
$io = $event->getIO();
$processor = new ProcessExecutor($io);
$changer = new RemoteUrls($io);
$rootPackage = $event->getComposer()->getPackage();
$extra = $rootPackage->getExtra();
$extensions = $extra['spip']['extensions'] ?? []; // -> plugins-dist/
......@@ -47,14 +46,13 @@ class ModeDev
return $list;
}, []);
$changer = new RemoteUrls();
foreach ($toChange as $path) {
$url = '';
$processor->execute('git -C '.$path.' remote get-url origin', $url);
$changer->getProcessor()->execute($changer->getRemote($path), $url);
$newUrl = $changer->toSsh($url);
if ($newUrl !== $url) {
$io->write($url . ' -> ' . $newUrl);
$processor->execute('git -C '.$path.' remote set-url origin '.$newUrl);
$changer->getProcessor()->execute($changer->setRemote($path, $newUrl));
}
}
$io->write('Done.');
......
......@@ -2,6 +2,8 @@
namespace Spip\Test\Composer\Git;
use Composer\IO\NullIO;
use Composer\Util\ProcessExecutor;
use PHPUnit\Framework\TestCase;
use Spip\Composer\Git\RemoteUrls;
......@@ -14,7 +16,7 @@ class RemoteUrlsTest extends TestCase
protected function setUp(): void
{
$this->changer = new RemoteUrls();
$this->changer = new RemoteUrls(new NullIO());
}
public static function dataHttpsToSsh()
......@@ -68,4 +70,19 @@ class RemoteUrlsTest extends TestCase
{
$this->assertSame($expected, $this->changer->toHttps($url));
}
public function testGetRemote()
{
$this->assertSame('git -C test remote get-url origin', $this->changer->getRemote('test'));
}
public function testSetRemote()
{
$this->assertSame('git -C test remote set-url origin test-url', $this->changer->setRemote('test', 'test-url'));
}
public function testGetProcessor()
{
$this->assertInstanceOf(ProcessExecutor::class, $this->changer->getProcessor());
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter