Skip to content

Commit 0a3a6cf

Browse files
committed
Merge branch 'release/2.3.0'
2 parents cee10eb + 5845627 commit 0a3a6cf

27 files changed

+765
-254
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# v2.3.0
2+
## 04/27/2021
3+
4+
1. [](#new)
5+
* 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)
6+
* 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)
7+
1. [](#improved)
8+
* Updated PHP Encryption dependency
9+
1. [](#bugfix)
10+
* Fixed issue with Flex Objects, preventing GitSync's settings to get refreshed `onAdminSave` when "Sync on Page Save" disabled
11+
* 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)
12+
113
# v2.2.0
214
## 04/17/2021
315

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ Git Sync captures any change that you make on your site and instantly updates yo
66

77
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.
88

9-
> :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:
10-
> 1. Once you have created your new repo, create a new branch called ‘master’
11-
> 2. Set the default branch of the repo to this newly created ‘master’ branch
129

1310
## Videos: Setup and Demo
1411

@@ -33,6 +30,7 @@ After having installed the plugin, make sure to go in the plugin settings in ord
3330
* Easy step-by-step Wizard setup will guide you through a detailed process for setting things up
3431
* 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.
3532
* Private repositories
33+
* Basic SSH / Enterprise support (You will need SSH Key properly setup on your machine)
3634
* Synchronize any folder under `user` (pages, themes, config)
3735
* 2FA (Two-Factor Authentication) and Access Token support
3836
* Webhooks support allow for automatic synchronization from the Git Repository with secure Webhook URL auto-generated and support for Webhook Secret (when available)
@@ -70,6 +68,18 @@ In order for the plugin to work, the server needs to run `git` 1.7.1 and above.
7068

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

71+
# SSH / Enterprise
72+
73+
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.
74+
75+
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.
76+
77+
Point it to the secret (not the public) and make also sure you have strict permissions to the file. (`-rw-------`).
78+
79+
Example: private_key: `/home/www-data/.ssh/id_rsa`
80+
81+
> **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.
82+
7383
# Known Issues and Resolutions
7484
**Q:** `error: The requested URL returned error: 403 Forbidden while accessing...` [#39](https://github.com/trilbymedia/grav-plugin-git-sync/issues/39)
7585
**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.

blueprints.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Git Sync
22
type: plugin
33
slug: git-sync
4-
version: 2.2.0
4+
version: 2.3.0
55
description: Allows to synchronize portions of Grav with Git Repositories (GitHub, BitBucket, GitLab)
66
icon: git
77
author:
@@ -243,6 +243,29 @@ form:
243243
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
244244
placeholder: /usr/bin/git
245245

246+
git.ignore:
247+
type: textarea
248+
label: Git Ignore
249+
help: Add custom git ignore rules to go along with GitSync. One per line
250+
rows: 6
251+
placeholder: |
252+
node_modules
253+
/.idea
254+
255+
git.private_key:
256+
type: text
257+
label: Private SSH Key
258+
placeholder: ~/.ssh/id_rsa
259+
markdown: true
260+
description: >
261+
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 />
262+
<br />
263+
Point it to the secret (not the public) and make also sure you have strict permissions to the file. (`-rw-------`). <br />
264+
<br />
265+
Example: `private_key: /home/www-data/.ssh/id_rsa`<br />
266+
<br />
267+
**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.
268+
246269
logging:
247270
type: toggle
248271
default: 0

classes/GitSync.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,17 @@ public function setUser($name = null, $email = null)
145145
{
146146
$name = $this->getConfig('git', $name)['name'];
147147
$email = $this->getConfig('git', $email)['email'];
148+
$privateKey = $this->getGitConfig('private_key', null);
148149

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

153+
if ($privateKey) {
154+
$this->execute('config core.sshCommand "ssh -i ' . $privateKey . ' -F /dev/null"');
155+
} else {
156+
$this->execute('config --unset core.sshCommand');
157+
}
158+
152159
return true;
153160
}
154161

@@ -214,6 +221,9 @@ public function enableSparseCheckout()
214221
}
215222
}
216223

224+
$ignoreEntries = explode("\n", $this->getGitConfig('ignore', ''));
225+
$ignore = array_merge($ignore, $ignoreEntries);
226+
217227
$file = File::instance(rtrim($this->repositoryPath, '/') . '/.gitignore');
218228
$file->save(implode("\r\n", $ignore));
219229
$file->free();
@@ -471,7 +481,7 @@ public function execute($command, $quiet = false)
471481
exec($command, $output, $returnValue);
472482
}
473483

474-
if ($returnValue !== 0 && !$quiet) {
484+
if ($returnValue !== 0 && (!empty($output) && $returnValue === 5) && !$quiet) {
475485
throw new \RuntimeException(implode("\r\n", $output));
476486
}
477487

classes/Helper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Defuse\Crypto\Crypto;
66
use Grav\Common\Config\Config;
77
use Grav\Common\Grav;
8+
use Grav\Common\Utils;
89
use SebastianBergmann\Git\RuntimeException;
910

1011
class Helper
@@ -69,6 +70,10 @@ public static function prepareRepository($user, $password, $repository)
6970
$user = $user ? urlencode($user) . ':' : '';
7071
$password = urlencode($password);
7172

73+
if (Utils::startsWith($repository, 'ssh://')) {
74+
return $repository;
75+
}
76+
7277
return str_replace('://', "://${user}${password}@", $repository);
7378
}
7479

composer.lock

Lines changed: 16 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sync.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Grav\Common\Config\Config;
77
use Grav\Common\Data\Data;
88
use Grav\Common\Grav;
9+
use Grav\Common\Page\Interfaces\PageInterface;
910
use Grav\Common\Plugin;
1011
use Grav\Common\Scheduler\Scheduler;
1112
use Grav\Plugin\GitSync\AdminController;
@@ -376,15 +377,15 @@ public function onAdminSave(Event $event)
376377
*/
377378
public function onAdminAfterSave(Event $event)
378379
{
379-
if (!$this->grav['config']->get('plugins.git-sync.sync.on_save', true)) {
380-
return;
381-
}
382-
383380
$obj = $event['object'];
384381
$adminPath = trim($this->grav['admin']->base, '/');
385382
$uriPath = $this->grav['uri']->path();
386383
$isPluginRoute = $uriPath === "/$adminPath/plugins/" . $this->name;
387384

385+
if ($obj instanceof PageInterface && !$this->grav['config']->get('plugins.git-sync.sync.on_save', true)) {
386+
return;
387+
}
388+
388389
if ($obj instanceof Data) {
389390
$folders = $this->git->getConfig('folders', $event['object']->get('folders', []));
390391
$data_type = preg_replace('#^/' . preg_quote($adminPath, '#') . '/#', '', $uriPath);

vendor/composer/ClassLoader.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
*
3838
* @author Fabien Potencier <[email protected]>
3939
* @author Jordi Boggiano <[email protected]>
40-
* @see http://www.php-fig.org/psr/psr-0/
41-
* @see http://www.php-fig.org/psr/psr-4/
40+
* @see https://www.php-fig.org/psr/psr-0/
41+
* @see https://www.php-fig.org/psr/psr-4/
4242
*/
4343
class ClassLoader
4444
{
45+
private $vendorDir;
46+
4547
// PSR-4
4648
private $prefixLengthsPsr4 = array();
4749
private $prefixDirsPsr4 = array();
@@ -57,10 +59,17 @@ class ClassLoader
5759
private $missingClasses = array();
5860
private $apcuPrefix;
5961

62+
private static $registeredLoaders = array();
63+
64+
public function __construct($vendorDir = null)
65+
{
66+
$this->vendorDir = $vendorDir;
67+
}
68+
6069
public function getPrefixes()
6170
{
6271
if (!empty($this->prefixesPsr0)) {
63-
return call_user_func_array('array_merge', $this->prefixesPsr0);
72+
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
6473
}
6574

6675
return array();
@@ -300,6 +309,15 @@ public function getApcuPrefix()
300309
public function register($prepend = false)
301310
{
302311
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
312+
313+
if (null === $this->vendorDir) {
314+
//no-op
315+
} elseif ($prepend) {
316+
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
317+
} else {
318+
unset(self::$registeredLoaders[$this->vendorDir]);
319+
self::$registeredLoaders[$this->vendorDir] = $this;
320+
}
303321
}
304322

305323
/**
@@ -308,6 +326,10 @@ public function register($prepend = false)
308326
public function unregister()
309327
{
310328
spl_autoload_unregister(array($this, 'loadClass'));
329+
330+
if (null !== $this->vendorDir) {
331+
unset(self::$registeredLoaders[$this->vendorDir]);
332+
}
311333
}
312334

313335
/**
@@ -367,6 +389,16 @@ public function findFile($class)
367389
return $file;
368390
}
369391

392+
/**
393+
* Returns the currently registered loaders indexed by their corresponding vendor directories.
394+
*
395+
* @return self[]
396+
*/
397+
public static function getRegisteredLoaders()
398+
{
399+
return self::$registeredLoaders;
400+
}
401+
370402
private function findFileWithExtension($class, $ext)
371403
{
372404
// PSR-4 lookup

0 commit comments

Comments
 (0)