Skip to content

Commit

Permalink
Added support for multiple repos lookup (as array) in .grav/config
Browse files Browse the repository at this point in the history
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/
```
  • Loading branch information
w00fz committed Aug 15, 2018
1 parent 42ff8ea commit 75ac020
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
29 changes: 19 additions & 10 deletions system/src/Grav/Console/Cli/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<green>SUCCESS</green> symlinked <magenta>' . $data['src'] . '</magenta> -> <cyan>' . $data['path'] . '</cyan>');
$this->output->writeln('');
} else {
$this->output->writeln('<red>destination: ' . $to . ' already exists, skipping...</red>');
$this->output->writeln('');
foreach ($repos as $repo) {
$path = $repo . $data['src'];
if (file_exists($path)) {
$from = $path;
continue;
}
} else {
}

if (!$from) {
$this->output->writeln('<red>source: ' . $from . ' does not exists, skipping...</red>');
$this->output->writeln('');
}

if (!file_exists($to)) {
symlink($from, $to);
$this->output->writeln('<green>SUCCESS</green> symlinked <magenta>' . $data['src'] . '</magenta> -> <cyan>' . $data['path'] . '</cyan>');
$this->output->writeln('');
} else {
$this->output->writeln('<red>destination: ' . $to . ' already exists, skipping...</red>');
$this->output->writeln('');
}

}
}
}
15 changes: 9 additions & 6 deletions system/src/Grav/Console/Gpm/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 75ac020

Please sign in to comment.