Skip to content

Commit cee10eb

Browse files
committed
Merge branch 'release/2.2.0'
2 parents 6b7b767 + ed0a3be commit cee10eb

File tree

13 files changed

+1964
-2565
lines changed

13 files changed

+1964
-2565
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# v2.2.0
2+
## 04/17/2021
3+
4+
1. [](#improved)
5+
* 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.
6+
1. [](#bugfix)
7+
* 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)
8+
* 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)
9+
110
# v2.1.1
211
## 07/17/2020
312

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ 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
12+
913
## Videos: Setup and Demo
1014

1115
| Up and Running in 2 mins | 2-way Sync Demonstration |

app/wizard/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import request from 'admin/utils/request';
33
import toastr from 'admin/utils/toastr';
44
import { config } from 'grav-config';
55
import $ from 'jquery';
6+
import 'whatwg-fetch';
67

78
const WIZARD = $('[data-remodal-id="wizard"]');
89
const RESET_LOCAL = $('[data-remodal-id="reset-local"]');
910
const SERVICES = { 'github': 'github.com', 'bitbucket': 'bitbucket.org', 'gitlab': 'gitlab.com', 'allothers': 'allothers.repo' };
11+
const BRANCHES = { 'github': 'main', 'bitbucket': 'master', 'gitlab': 'master', 'allothers': 'master' };
1012
const TEMPLATES = {
1113
REPO_URL: 'https://{placeholder}/getgrav/grav.git'
1214
};
@@ -111,6 +113,7 @@ $(document).on('click', '[data-gitsync-action]', (event) => {
111113
const noUser = $('[name="gitsync[no_user]"]').is(':checked');
112114
const password = $('[name="gitsync[repo_password]"]').val();
113115
const repository = $('[name="gitsync[repo_url]"]').val();
116+
const branch = $('[name="gitsync[branch]"]').val();
114117
const webhook = $('[name="gitsync[webhook]"]').val();
115118
const webhook_enabled = $('[name="gitsync[webhook_enabled]"]').is(':checked');
116119
const webhook_secret = $('[name="gitsync[webhook_secret]"]').val();
@@ -134,8 +137,11 @@ $(document).on('click', '[data-gitsync-action]', (event) => {
134137
}
135138

136139
if (['save', 'test'].includes(action)) {
140+
target.find('.fa').removeClass(action === 'test' ? 'fa-plug' : 'fa-check').addClass('fa-spin fa-circle-o-notch');
141+
137142
if (error.length) {
138143
toastr.error(error.join('<br />'));
144+
target.find('.fa').removeClass('fa-spin fa-circle-o-notch').addClass(action === 'test' ? 'fa-plug' : 'fa-check');
139145

140146
return false;
141147
}
@@ -147,6 +153,8 @@ $(document).on('click', '[data-gitsync-action]', (event) => {
147153
$('[name="data[no_user]"]').val(noUser ? '1' : '0');
148154
$('[name="data[user]"]').val(user);
149155
$('[name="data[password]"]').val(password);
156+
$('[name="data[branch]"]').val(branch);
157+
$('[name="data[remote][branch]"]').val(branch);
150158
$('[name="data[webhook]"]').val(webhook);
151159
$(`[name="data[webhook_enabled]"][value="${webhook_enabled ? 1 : 0}"]`).prop('checked', true);
152160
$('[name="data[webhook_secret]"]').val(webhook_secret);
@@ -166,14 +174,16 @@ $(document).on('click', '[data-gitsync-action]', (event) => {
166174
const test = global.btoa(JSON.stringify({
167175
user: noUser ? '' : user,
168176
password,
169-
repository
177+
repository,
178+
branch
170179
}));
171180

172181
request(URI, {
173182
method: 'post',
174183
body: { test, task: 'testConnection' }
175184
});
176185

186+
target.find('.fa').removeClass('fa-spin fa-circle-o-notch').addClass('fa-plug');
177187
return false;
178188
}
179189

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

208218
if (STEP === 2) {
209219
const repoURL = $('[name="gitsync[repo_url]"]').val();
210-
if (!repoURL.length) {
220+
if (!repoURL.length || !branch) {
211221
disableButton(next);
212222
} else {
213223
enableButton(next);
@@ -283,7 +293,11 @@ $(document).on('change', '[name="gitsync[repository]"]', (event) => {
283293
WIZARD.find('.webhook-secret-wrapper')[service === 'bitbucket' ? 'addClass' : 'removeClass']('hidden');
284294
WIZARD
285295
.find('input[name="gitsync[repo_url]"][placeholder]')
286-
.attr('placeholder', TEMPLATES.REPO_URL.replace(/\{placeholder\}/, SERVICES[service]));
296+
.attr('placeholder', TEMPLATES.REPO_URL.replace(/\{placeholder\}/, SERVICES[service]))
297+
.end()
298+
.find('input[name="gitsync[branch]"]')
299+
.attr('placeholder', BRANCHES[service])
300+
.val(BRANCHES[service]);
287301
}
288302
});
289303

blueprints.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Git Sync
2-
version: 2.1.1
2+
type: plugin
3+
slug: git-sync
4+
version: 2.2.0
35
description: Allows to synchronize portions of Grav with Git Repositories (GitHub, BitBucket, GitLab)
46
icon: git
57
author:
@@ -36,7 +38,7 @@ form:
3638
type: bool
3739

3840
folders:
39-
type: selectize
41+
type: select
4042
multiple: true
4143
label: Folders to Sync
4244
classes: fancy

classes/AdminController.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ public function taskTestConnection()
6262
$data = $test ? json_decode($test, false) : new \stdClass();
6363

6464
try {
65-
Helper::testRepository($data->user, $data->password, $data->repository);
66-
echo json_encode([
67-
'status' => 'success',
68-
'message' => 'The connection to the repository has been successful.'
69-
]);
65+
$testResult = Helper::testRepository($data->user, $data->password, $data->repository, $data->branch);
66+
67+
if (!empty($testResult)) {
68+
echo json_encode([
69+
'status' => 'success',
70+
'message' => 'The connection to the repository has been successful.'
71+
]);
72+
} else {
73+
echo json_encode([
74+
'status' => 'error',
75+
'message' => 'Branch "' . $data->branch .'" not found in the repository.'
76+
]);
77+
}
7078
} catch (\Exception $e) {
7179
$invalid = str_replace($data->password, '{password}', $e->getMessage());
7280
echo json_encode([

classes/GitSync.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ public function getRuntimeInformation()
113113
* @param string $url
114114
* @return string[]
115115
*/
116-
public function testRepository($url)
116+
public function testRepository($url, $branch)
117117
{
118-
return $this->execute("ls-remote \"{$url}\"");
118+
$branch = $branch ? '"' . $branch . '"' : '';
119+
return $this->execute("ls-remote \"{$url}\" {$branch}");
119120
}
120121

121122
/**
@@ -127,7 +128,7 @@ public function initializeRepository()
127128
$branch = $this->getRemote('branch', null);
128129
$local_branch = $this->getConfig('branch', $branch);
129130
$this->execute('init');
130-
$this->execute('checkout ' . $local_branch, true);
131+
$this->execute('checkout -b ' . $local_branch, true);
131132
}
132133

133134
$this->enableSparseCheckout();
@@ -370,7 +371,7 @@ public function push($name = null, $branch = null)
370371
{
371372
$name = $this->getRemote('name', $name);
372373
$branch = $this->getRemote('branch', $branch);
373-
$local_branch = $this->getConfig('branch', $branch);
374+
$local_branch = $this->getConfig('branch', null);
374375

375376
return $this->execute("push {$name} {$local_branch}:{$branch}");
376377
}

classes/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public static function prepareRepository($user, $password, $repository)
7878
* @param string $repository
7979
* @return string[]
8080
*/
81-
public static function testRepository($user, $password, $repository)
81+
public static function testRepository($user, $password, $repository, $branch)
8282
{
8383
$git = new GitSync();
8484
$repository = self::prepareRepository($user, $password, $repository);
8585

8686
try {
87-
return $git->testRepository($repository);
87+
return $git->testRepository($repository, $branch);
8888
} catch (RuntimeException $e) {
8989
return [$e->getMessage()];
9090
}

0 commit comments

Comments
 (0)