Skip to content

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
w00fz committed Apr 27, 2021
2 parents cee10eb + 5845627 commit 0a3a6cf
Show file tree
Hide file tree
Showing 27 changed files with 765 additions and 254 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# v2.3.0
## 04/27/2021

1. [](#new)
* Added new Advanced Git Ignore field where it is possible to specify custom git ignore entries to play along with GitSync [#197](https://github.com/trilbymedia/grav-plugin-git-sync/issues/197) [#117](https://github.com/trilbymedia/grav-plugin-git-sync/issues/117)
* Support `ssh://` protocol and SSH Key authentication ([read more](https://github.com/trilbymedia/grav-plugin-git-sync#ssh--enterprise)) [#110](https://github.com/trilbymedia/grav-plugin-git-sync/issues/110)
1. [](#improved)
* Updated PHP Encryption dependency
1. [](#bugfix)
* Fixed issue with Flex Objects, preventing GitSync's settings to get refreshed `onAdminSave` when "Sync on Page Save" disabled
* Return raw URL for repositories setup with `ssh://` protocol, instead of injecting the password like `git://` and `http://` protocols do [#104](https://github.com/trilbymedia/grav-plugin-git-sync/issues/104)

# v2.2.0
## 04/17/2021

Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ Git Sync captures any change that you make on your site and instantly updates yo

Thanks to this powerful bi-directional flow, Git Sync can now turn your site into a collaborative environment where the source of truth is always your git repository and unlimited collaborators and sites can share and contribute to the same content.

> :warning: With GitHub’s recent change of repository default branches being named ‘main’ instead of ‘master’ the following work-around is needed until GitHub also addresses automatic default branch re-routing:
> 1. Once you have created your new repo, create a new branch called ‘master’
> 2. Set the default branch of the repo to this newly created ‘master’ branch

## Videos: Setup and Demo

Expand All @@ -33,6 +30,7 @@ After having installed the plugin, make sure to go in the plugin settings in ord
* Easy step-by-step Wizard setup will guide you through a detailed process for setting things up
* Supported hosting services: [GitHub](https://github.com), [BitBucket](https://bitbucket.org), [GitLab](https://gitlab.com) as well as any self-hosted and git service with webhooks support.
* Private repositories
* Basic SSH / Enterprise support (You will need SSH Key properly setup on your machine)
* Synchronize any folder under `user` (pages, themes, config)
* 2FA (Two-Factor Authentication) and Access Token support
* Webhooks support allow for automatic synchronization from the Git Repository with secure Webhook URL auto-generated and support for Webhook Secret (when available)
Expand Down Expand Up @@ -70,6 +68,18 @@ In order for the plugin to work, the server needs to run `git` 1.7.1 and above.

The PHP `exec()` and `escapeshellarg()` functions are mandatory. Ensure the options to be enabled in your PHP.

# SSH / Enterprise

Since version v2.3.0, GitSync supports SSH authentication. This means you can omit password altogether and rely on the Repository URL and SSH key on your machine, that you can point to from the Advanced settings in GitSync.

Please note that In order to be able to sparse-checkout and push changes, it is expected you have an ssh-key configured for accessing the repository. This is usually found under `~/.ssh` and it needs to be configured for the same user that runs the web-server.

Point it to the secret (not the public) and make also sure you have strict permissions to the file. (`-rw-------`).

Example: private_key: `/home/www-data/.ssh/id_rsa`

> **IMPORTANT**: SSH keys with passphrase are **NOT** supported. To remove a passphrase, run the `ssh-keygen -p` command and when asked for the new passphrase leave blank and return.
# Known Issues and Resolutions
**Q:** `error: The requested URL returned error: 403 Forbidden while accessing...` [#39](https://github.com/trilbymedia/grav-plugin-git-sync/issues/39)
**A:** This might be caused by your computer having stored in the registry a user/password that might conflict with the one you are intending to use.
Expand Down
25 changes: 24 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Git Sync
type: plugin
slug: git-sync
version: 2.2.0
version: 2.3.0
description: Allows to synchronize portions of Grav with Git Repositories (GitHub, BitBucket, GitLab)
icon: git
author:
Expand Down Expand Up @@ -243,6 +243,29 @@ form:
help: If the default `git` command doesn't work on your machine or if you want to specify a custom path, do it in here
placeholder: /usr/bin/git

git.ignore:
type: textarea
label: Git Ignore
help: Add custom git ignore rules to go along with GitSync. One per line
rows: 6
placeholder: |
node_modules
/.idea
git.private_key:
type: text
label: Private SSH Key
placeholder: ~/.ssh/id_rsa
markdown: true
description: >
In order to be able to sparse-checkout and push changes, it is expected you have an ssh-key configured for accessing the repository. This is usually found under `~/.ssh` and it needs to be configured for the same user that runs the web-server. <br />
<br />
Point it to the secret (not the public) and make also sure you have strict permissions to the file. (`-rw-------`). <br />
<br />
Example: `private_key: /home/www-data/.ssh/id_rsa`<br />
<br />
**IMPORTANT**: SSH keys with passphrase are __NOT__ supported. To remove a passphrase, run the `ssh-keygen -p` command and when asked for the new passphrase leave blank and return.
logging:
type: toggle
default: 0
Expand Down
12 changes: 11 additions & 1 deletion classes/GitSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,17 @@ public function setUser($name = null, $email = null)
{
$name = $this->getConfig('git', $name)['name'];
$email = $this->getConfig('git', $email)['email'];
$privateKey = $this->getGitConfig('private_key', null);

$this->execute("config user.name \"{$name}\"");
$this->execute("config user.email \"{$email}\"");

if ($privateKey) {
$this->execute('config core.sshCommand "ssh -i ' . $privateKey . ' -F /dev/null"');
} else {
$this->execute('config --unset core.sshCommand');
}

return true;
}

Expand Down Expand Up @@ -214,6 +221,9 @@ public function enableSparseCheckout()
}
}

$ignoreEntries = explode("\n", $this->getGitConfig('ignore', ''));
$ignore = array_merge($ignore, $ignoreEntries);

$file = File::instance(rtrim($this->repositoryPath, '/') . '/.gitignore');
$file->save(implode("\r\n", $ignore));
$file->free();
Expand Down Expand Up @@ -471,7 +481,7 @@ public function execute($command, $quiet = false)
exec($command, $output, $returnValue);
}

if ($returnValue !== 0 && !$quiet) {
if ($returnValue !== 0 && (!empty($output) && $returnValue === 5) && !$quiet) {
throw new \RuntimeException(implode("\r\n", $output));
}

Expand Down
5 changes: 5 additions & 0 deletions classes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Defuse\Crypto\Crypto;
use Grav\Common\Config\Config;
use Grav\Common\Grav;
use Grav\Common\Utils;
use SebastianBergmann\Git\RuntimeException;

class Helper
Expand Down Expand Up @@ -69,6 +70,10 @@ public static function prepareRepository($user, $password, $repository)
$user = $user ? urlencode($user) . ':' : '';
$password = urlencode($password);

if (Utils::startsWith($repository, 'ssh://')) {
return $repository;
}

return str_replace('://', "://${user}${password}@", $repository);
}

Expand Down
25 changes: 16 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions git-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Grav\Common\Config\Config;
use Grav\Common\Data\Data;
use Grav\Common\Grav;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Plugin;
use Grav\Common\Scheduler\Scheduler;
use Grav\Plugin\GitSync\AdminController;
Expand Down Expand Up @@ -376,15 +377,15 @@ public function onAdminSave(Event $event)
*/
public function onAdminAfterSave(Event $event)
{
if (!$this->grav['config']->get('plugins.git-sync.sync.on_save', true)) {
return;
}

$obj = $event['object'];
$adminPath = trim($this->grav['admin']->base, '/');
$uriPath = $this->grav['uri']->path();
$isPluginRoute = $uriPath === "/$adminPath/plugins/" . $this->name;

if ($obj instanceof PageInterface && !$this->grav['config']->get('plugins.git-sync.sync.on_save', true)) {
return;
}

if ($obj instanceof Data) {
$folders = $this->git->getConfig('folders', $event['object']->get('folders', []));
$data_type = preg_replace('#^/' . preg_quote($adminPath, '#') . '/#', '', $uriPath);
Expand Down
38 changes: 35 additions & 3 deletions vendor/composer/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
*
* @author Fabien Potencier <[email protected]>
* @author Jordi Boggiano <[email protected]>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
* @see https://www.php-fig.org/psr/psr-0/
* @see https://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
private $vendorDir;

// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
Expand All @@ -57,10 +59,17 @@ class ClassLoader
private $missingClasses = array();
private $apcuPrefix;

private static $registeredLoaders = array();

public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
}

public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
}

return array();
Expand Down Expand Up @@ -300,6 +309,15 @@ public function getApcuPrefix()
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);

if (null === $this->vendorDir) {
//no-op
} elseif ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}

/**
Expand All @@ -308,6 +326,10 @@ public function register($prepend = false)
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));

if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}

/**
Expand Down Expand Up @@ -367,6 +389,16 @@ public function findFile($class)
return $file;
}

/**
* Returns the currently registered loaders indexed by their corresponding vendor directories.
*
* @return self[]
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}

private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
Expand Down
Loading

0 comments on commit 0a3a6cf

Please sign in to comment.