From 75ac0201d8f947180dcc0f5d6d4fa27bb6cd6461 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Wed, 15 Aug 2018 13:36:05 -0700 Subject: [PATCH] Added support for multiple repos lookup (as array) in .grav/config This will allow to keep clones of repositories on different folders and still be able to symlink them. Example of ~/.grav/config: ``` github_repos: - /Users/my_user/Projects/grav/ - /Users/my_user/Projects/personal/ - /Users/my_user/Projects/work/ ``` --- .../src/Grav/Console/Cli/InstallCommand.php | 29 ++++++++++++------- .../src/Grav/Console/Gpm/InstallCommand.php | 15 ++++++---- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php index 24d199b2a3..afcd80c02e 100644 --- a/system/src/Grav/Console/Cli/InstallCommand.php +++ b/system/src/Grav/Console/Cli/InstallCommand.php @@ -156,23 +156,32 @@ private function symlink() exec('cd ' . $this->destination); foreach ($this->config['links'] as $repo => $data) { - $from = $this->local_config[$data['scm'] . '_repos'] . $data['src']; + $repos = (array) $this->local_config[$data['scm'] . '_repos']; + $from = false; $to = $this->destination . $data['path']; - if (file_exists($from)) { - if (!file_exists($to)) { - symlink($from, $to); - $this->output->writeln('SUCCESS symlinked ' . $data['src'] . ' -> ' . $data['path'] . ''); - $this->output->writeln(''); - } else { - $this->output->writeln('destination: ' . $to . ' already exists, skipping...'); - $this->output->writeln(''); + foreach ($repos as $repo) { + $path = $repo . $data['src']; + if (file_exists($path)) { + $from = $path; + continue; } - } else { + } + + if (!$from) { $this->output->writeln('source: ' . $from . ' does not exists, skipping...'); $this->output->writeln(''); } + if (!file_exists($to)) { + symlink($from, $to); + $this->output->writeln('SUCCESS symlinked ' . $data['src'] . ' -> ' . $data['path'] . ''); + $this->output->writeln(''); + } else { + $this->output->writeln('destination: ' . $to . ' already exists, skipping...'); + $this->output->writeln(''); + } + } } } diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index d7e932e4ec..0311428254 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -444,18 +444,21 @@ private function getSymlinkSource($package) { $matches = $this->getGitRegexMatches($package); - foreach ($this->local_config as $path) { + foreach ($this->local_config as $paths) { if (Utils::endsWith($matches[2], '.git')) { $repo_dir = preg_replace('/\.git$/', '', $matches[2]); } else { $repo_dir = $matches[2]; } - - $from = rtrim($path, '/') . '/' . $repo_dir; - - if (file_exists($from)) { - return $from; + + $paths = (array) $paths; + foreach ($paths as $repo) { + $path = rtrim($repo, '/') . '/' . $repo_dir; + if (file_exists($path)) { + return $path; + } } + } return false;