Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
w00fz committed Apr 17, 2021
2 parents 6b7b767 + ed0a3be commit cee10eb
Show file tree
Hide file tree
Showing 13 changed files with 1,964 additions and 2,565 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# v2.2.0
## 04/17/2021

1. [](#improved)
* Better support for branches other than `master`. This includes the transition to `main` from GitHub and the groundwork to support other big providers making the change as announced soon. GitSync is now capable of preset the branch based on the provider selected. You are now also able to specify any custom branch and when testing the repository connection it will also ensure the branch exists and provide feedback if not.
1. [](#bugfix)
* Changing remote branch is now going to properly reference it instead of remaining stuck to `master` [#192](https://github.com/trilbymedia/grav-plugin-git-sync/issues/192), [#183](https://github.com/trilbymedia/grav-plugin-git-sync/issues/183)
* Fixed issue where the Folders to synchronize from the Wizard wouldn't get properly saved [#178](https://github.com/trilbymedia/grav-plugin-git-sync/issues/178)

# v2.1.1
## 07/17/2020

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ 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

| Up and Running in 2 mins | 2-way Sync Demonstration |
Expand Down
20 changes: 17 additions & 3 deletions app/wizard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import request from 'admin/utils/request';
import toastr from 'admin/utils/toastr';
import { config } from 'grav-config';
import $ from 'jquery';
import 'whatwg-fetch';

const WIZARD = $('[data-remodal-id="wizard"]');
const RESET_LOCAL = $('[data-remodal-id="reset-local"]');
const SERVICES = { 'github': 'github.com', 'bitbucket': 'bitbucket.org', 'gitlab': 'gitlab.com', 'allothers': 'allothers.repo' };
const BRANCHES = { 'github': 'main', 'bitbucket': 'master', 'gitlab': 'master', 'allothers': 'master' };
const TEMPLATES = {
REPO_URL: 'https://{placeholder}/getgrav/grav.git'
};
Expand Down Expand Up @@ -111,6 +113,7 @@ $(document).on('click', '[data-gitsync-action]', (event) => {
const noUser = $('[name="gitsync[no_user]"]').is(':checked');
const password = $('[name="gitsync[repo_password]"]').val();
const repository = $('[name="gitsync[repo_url]"]').val();
const branch = $('[name="gitsync[branch]"]').val();
const webhook = $('[name="gitsync[webhook]"]').val();
const webhook_enabled = $('[name="gitsync[webhook_enabled]"]').is(':checked');
const webhook_secret = $('[name="gitsync[webhook_secret]"]').val();
Expand All @@ -134,8 +137,11 @@ $(document).on('click', '[data-gitsync-action]', (event) => {
}

if (['save', 'test'].includes(action)) {
target.find('.fa').removeClass(action === 'test' ? 'fa-plug' : 'fa-check').addClass('fa-spin fa-circle-o-notch');

if (error.length) {
toastr.error(error.join('<br />'));
target.find('.fa').removeClass('fa-spin fa-circle-o-notch').addClass(action === 'test' ? 'fa-plug' : 'fa-check');

return false;
}
Expand All @@ -147,6 +153,8 @@ $(document).on('click', '[data-gitsync-action]', (event) => {
$('[name="data[no_user]"]').val(noUser ? '1' : '0');
$('[name="data[user]"]').val(user);
$('[name="data[password]"]').val(password);
$('[name="data[branch]"]').val(branch);
$('[name="data[remote][branch]"]').val(branch);
$('[name="data[webhook]"]').val(webhook);
$(`[name="data[webhook_enabled]"][value="${webhook_enabled ? 1 : 0}"]`).prop('checked', true);
$('[name="data[webhook_secret]"]').val(webhook_secret);
Expand All @@ -166,14 +174,16 @@ $(document).on('click', '[data-gitsync-action]', (event) => {
const test = global.btoa(JSON.stringify({
user: noUser ? '' : user,
password,
repository
repository,
branch
}));

request(URI, {
method: 'post',
body: { test, task: 'testConnection' }
});

target.find('.fa').removeClass('fa-spin fa-circle-o-notch').addClass('fa-plug');
return false;
}

Expand Down Expand Up @@ -207,7 +217,7 @@ $(document).on('click', '[data-gitsync-action]', (event) => {

if (STEP === 2) {
const repoURL = $('[name="gitsync[repo_url]"]').val();
if (!repoURL.length) {
if (!repoURL.length || !branch) {
disableButton(next);
} else {
enableButton(next);
Expand Down Expand Up @@ -283,7 +293,11 @@ $(document).on('change', '[name="gitsync[repository]"]', (event) => {
WIZARD.find('.webhook-secret-wrapper')[service === 'bitbucket' ? 'addClass' : 'removeClass']('hidden');
WIZARD
.find('input[name="gitsync[repo_url]"][placeholder]')
.attr('placeholder', TEMPLATES.REPO_URL.replace(/\{placeholder\}/, SERVICES[service]));
.attr('placeholder', TEMPLATES.REPO_URL.replace(/\{placeholder\}/, SERVICES[service]))
.end()
.find('input[name="gitsync[branch]"]')
.attr('placeholder', BRANCHES[service])
.val(BRANCHES[service]);
}
});

Expand Down
6 changes: 4 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Git Sync
version: 2.1.1
type: plugin
slug: git-sync
version: 2.2.0
description: Allows to synchronize portions of Grav with Git Repositories (GitHub, BitBucket, GitLab)
icon: git
author:
Expand Down Expand Up @@ -36,7 +38,7 @@ form:
type: bool

folders:
type: selectize
type: select
multiple: true
label: Folders to Sync
classes: fancy
Expand Down
18 changes: 13 additions & 5 deletions classes/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,19 @@ public function taskTestConnection()
$data = $test ? json_decode($test, false) : new \stdClass();

try {
Helper::testRepository($data->user, $data->password, $data->repository);
echo json_encode([
'status' => 'success',
'message' => 'The connection to the repository has been successful.'
]);
$testResult = Helper::testRepository($data->user, $data->password, $data->repository, $data->branch);

if (!empty($testResult)) {
echo json_encode([
'status' => 'success',
'message' => 'The connection to the repository has been successful.'
]);
} else {
echo json_encode([
'status' => 'error',
'message' => 'Branch "' . $data->branch .'" not found in the repository.'
]);
}
} catch (\Exception $e) {
$invalid = str_replace($data->password, '{password}', $e->getMessage());
echo json_encode([
Expand Down
9 changes: 5 additions & 4 deletions classes/GitSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ public function getRuntimeInformation()
* @param string $url
* @return string[]
*/
public function testRepository($url)
public function testRepository($url, $branch)
{
return $this->execute("ls-remote \"{$url}\"");
$branch = $branch ? '"' . $branch . '"' : '';
return $this->execute("ls-remote \"{$url}\" {$branch}");
}

/**
Expand All @@ -127,7 +128,7 @@ public function initializeRepository()
$branch = $this->getRemote('branch', null);
$local_branch = $this->getConfig('branch', $branch);
$this->execute('init');
$this->execute('checkout ' . $local_branch, true);
$this->execute('checkout -b ' . $local_branch, true);
}

$this->enableSparseCheckout();
Expand Down Expand Up @@ -370,7 +371,7 @@ public function push($name = null, $branch = null)
{
$name = $this->getRemote('name', $name);
$branch = $this->getRemote('branch', $branch);
$local_branch = $this->getConfig('branch', $branch);
$local_branch = $this->getConfig('branch', null);

return $this->execute("push {$name} {$local_branch}:{$branch}");
}
Expand Down
4 changes: 2 additions & 2 deletions classes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public static function prepareRepository($user, $password, $repository)
* @param string $repository
* @return string[]
*/
public static function testRepository($user, $password, $repository)
public static function testRepository($user, $password, $repository, $branch)
{
$git = new GitSync();
$repository = self::prepareRepository($user, $password, $repository);

try {
return $git->testRepository($repository);
return $git->testRepository($repository, $branch);
} catch (RuntimeException $e) {
return [$e->getMessage()];
}
Expand Down
Loading

0 comments on commit cee10eb

Please sign in to comment.