Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalmh committed Sep 19, 2015
0 parents commit 90204c5
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## v0.0.1
+ Initial release
72 changes: 72 additions & 0 deletions git-commit-and-push-content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
require(__DIR__ . DS . 'helpers.php');

/*
* Pages
*/
kirby()->hook('panel.page.create', function ($page) {
gitCommit('create(page): ' . $page->uri());
});
kirby()->hook('panel.page.update', function ($page) {
gitCommit('update(page): ' . $page->uri());
});
kirby()->hook('panel.page.delete', function ($page) {
gitCommit('delete(page): ' . $page->uri());
});
kirby()->hook('panel.page.sort', function ($page) {
gitCommit('sort(page): ' . $page->uri());
});
kirby()->hook('panel.page.hide', function ($page) {
gitCommit('hide(page): ' . $page->uri());
});
kirby()->hook('panel.page.move', function ($page) {
gitCommit('move(page): ' . $page->uri());
});

/*
* File
*/
kirby()->hook('panel.file.move', function ($file) {
gitCommit('move(file): ' . $file->page()->uri() . '/' . $file->filename());
});
kirby()->hook('panel.file.upload', function ($file) {
gitCommit('upload(file): ' . $file->page()->uri() . '/' . $file->filename());
});
kirby()->hook('panel.file.replace', function ($file) {
gitCommit('replace(file): ' . $file->page()->uri() . '/' . $file->filename());
});
kirby()->hook('panel.file.rename', function ($file) {
gitCommit('rename(file): ' . $file->page()->uri() . '/' . $file->filename());
});
kirby()->hook('panel.file.update', function ($file) {
gitCommit('update(file): ' . $file->page()->uri() . '/' . $file->filename());
});
kirby()->hook('panel.file.sort', function ($file) {
gitCommit('sort(file): ' . $file->page()->uri() . '/' . $file->filename());
});
kirby()->hook('panel.file.delete', function ($file) {
gitCommit('delete(file): ' . $file->page()->uri() . '/' . $file->filename());
});

/*
* User
*/
kirby()->hook('panel.user.create', function ($user) {
gitCommit('create(user): ' . $user->username());
});
kirby()->hook('panel.user.update', function ($user) {
gitCommit('update(user): ' . $user->username());
});
kirby()->hook('panel.user.delete', function ($user) {
gitCommit('delete(user): ' . $user->username());
});

/*
* Avatar
*/
kirby()->hook('panel.avatar.upload', function ($avatar) {
gitCommit('upload(avatar): ' . $avatar->filename());
});
kirby()->hook('panel.avatar.delete', function ($avatar) {
gitCommit('delete(avatar): ' . $avatar->filename());
});
25 changes: 25 additions & 0 deletions helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Compose Commit message, appends " by Username"
*
* @param string $commitMessage
* @return false
*/
function gitCommit($commitMessage) {
exec(
'cd ../content/ && ' .
'git add -A &&' .
'git commit -m "' . $commitMessage . ' by ' . site()->user() . '"' .
(
server::get('SERVER_ADDR') != "localhost"
? ' && git push "ext::ssh -i ' .
c::get('gcapcSshKeyPath') . ' ' .
c::get('gcapcGitServer') . ' %S ' .
c::get('gcapcGitRepository') . '"'
: ''
),
$output
);

return false;
}
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "git-commit-and-push-content",
"readable": "Git Commit and Push Content",
"version": "0.0.1",
"stable": true,
"description": "Version Controle your Content-Folder",
"author": "Pascal Küsgen",
"url": "http://pascalmh.de"
}
57 changes: 57 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Kirby - Git Commit And Push Content

This is a plugin for [Kirby](http://getkirby.com/) that Commits and Pushes Changes made via the Panel to your Git Repository.

## Installation

### Create a new git repository for your content

Create a new git repository where you push your content to, name it `your-project_content`.

### Download and configure the Plugin

Put all the files into your `site/plugins/git-commit-and-push-content/` folder. If the `git-commit-and-push-content/` plugin folder doesn't exist then create it.

Or: go into you `site/plugins/` folder and `git clone https://github.com/Pascalmh/kirby-git-commit-and-push-content git-commit-and-push-content`.

Add this to your `site/config/config.php` and adapt it to your needs:
```php
// Plugin: git-commit-push-content
c::set('gcapcSshKeyPath', '.ssh/id_rsa'); // .ssh/id_rsa
c::set('gcapcGitServer', '[email protected]'); // [email protected]
c::set('gcapcGitRepository', 'your-project/your-project_content.git'); // your-project/your-project_content.git
```

`gcapcSshKeyPath` - Create a new Git User with Push Permissions, generate an ssh-key for it and put it on the server
`gcapcGitServer` - Hostname with optional user, for example `[email protected]`
`gcapcGitRepository` - your git repository `your-project/your-project_content.git`

### Init the content repo and push it

Remove `content/` folder from your current git repository
```
git rm --cached -r content
git add -A
git commit -m "Move Content Folder to separate repository"
```

Add `content/` folder to new git repository

```
cd content
git init
git remote add origin https://github.com/your-project/your-project_content.git
git add -A
git commit -m "Initial Content Commit"
git push origin master
```

## Usage

Just keep using the Panel as you are used to and watch the commits appear in you git repository!

If you are on localhost you need to push your changes manually.

## Author

Pascal 'Pascalmh' Küsgen <http://pascalmh.de>

0 comments on commit 90204c5

Please sign in to comment.