diff --git a/public_html/lib/plugins/gitbacked/README b/public_html/lib/plugins/gitbacked/README.md
similarity index 89%
rename from public_html/lib/plugins/gitbacked/README
rename to public_html/lib/plugins/gitbacked/README.md
index 6ef56bbe..9b1e9b2b 100644
--- a/public_html/lib/plugins/gitbacked/README
+++ b/public_html/lib/plugins/gitbacked/README.md
@@ -1,4 +1,4 @@
-gitbacked Plugin for DokuWiki
+# gitbacked Plugin for DokuWiki
Store/Sync pages and media files in a git repository
@@ -6,13 +6,14 @@ All documentation for this plugin can be found at
http://www.dokuwiki.org/plugin:gitbacked
If you install this plugin manually, make sure it is installed in
-lib/plugins/gitbacked/ - if the folder is called different it
+`lib/plugins/gitbacked/` - if the folder is called different it
will not work!
Please refer to http://www.dokuwiki.org/plugins for additional info
on how to install plugins in DokuWiki.
-----
+## License
+
Copyright (C) Wolfgang Gassler
This program is free software; you can redistribute it and/or modify
diff --git a/public_html/lib/plugins/gitbacked/action/editcommit.php b/public_html/lib/plugins/gitbacked/action/editcommit.php
index a888e95e..311c6ef9 100644
--- a/public_html/lib/plugins/gitbacked/action/editcommit.php
+++ b/public_html/lib/plugins/gitbacked/action/editcommit.php
@@ -24,7 +24,7 @@ class action_plugin_gitbacked_editcommit extends DokuWiki_Action_Plugin {
io_mkdir_p($this->temp_dir);
}
- public function register(Doku_Event_Handler &$controller) {
+ public function register(Doku_Event_Handler $controller) {
$controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'handle_io_wikipage_write');
$controller->register_hook('MEDIA_UPLOAD_FINISH', 'AFTER', $this, 'handle_media_upload');
@@ -39,35 +39,56 @@ class action_plugin_gitbacked_editcommit extends DokuWiki_Action_Plugin {
} else {
$repoPath = DOKU_INC.$this->getConf('repoPath');
}
+ //set the path to the git binary
+ $gitPath = trim($this->getConf('gitPath'));
+ if ($gitPath !== '') {
+ Git::set_bin($gitPath);
+ }
//init the repo and create a new one if it is not present
io_mkdir_p($repoPath);
$repo = new GitRepo($repoPath, true, true);
//set git working directory (by default DokuWiki's savedir)
$repoWorkDir = DOKU_INC.$this->getConf('repoWorkDir');
- $repo->git_path .= ' --work-tree '.escapeshellarg($repoWorkDir);
+ Git::set_bin(Git::get_bin().' --work-tree '.escapeshellarg($repoWorkDir));
$params = str_replace(
array('%mail%','%user%'),
array($this->getAuthorMail(),$this->getAuthor()),
$this->getConf('addParams'));
if ($params) {
- $repo->git_path .= ' '.$params;
+ Git::set_bin(Git::get_bin().' '.$params);
}
return $repo;
}
+ private function isIgnored($filePath) {
+ $ignore = false;
+ $ignorePaths = trim($this->getConf('ignorePaths'));
+ if ($ignorePaths !== '') {
+ $paths = explode(',',$ignorePaths);
+ foreach($paths as $path) {
+ if (strstr($filePath,$path)) {
+ $ignore = true;
+ }
+ }
+ }
+ return $ignore;
+ }
+
private function commitFile($filePath,$message) {
- $repo = $this->initRepo();
+ if (!$this->isIgnored($filePath)) {
+ $repo = $this->initRepo();
- //add the changed file and set the commit message
- $repo->add($filePath);
- $repo->commit($message);
+ //add the changed file and set the commit message
+ $repo->add($filePath);
+ $repo->commit($message);
- //if the push after Commit option is set we push the active branch to origin
- if ($this->getConf('pushAfterCommit')) {
- $repo->push('origin',$repo->active_branch());
- }
+ //if the push after Commit option is set we push the active branch to origin
+ if ($this->getConf('pushAfterCommit')) {
+ $repo->push('origin',$repo->active_branch());
+ }
+ }
}
diff --git a/public_html/lib/plugins/gitbacked/conf/default.php b/public_html/lib/plugins/gitbacked/conf/default.php
index 319a31e3..b0b04070 100644
--- a/public_html/lib/plugins/gitbacked/conf/default.php
+++ b/public_html/lib/plugins/gitbacked/conf/default.php
@@ -12,9 +12,11 @@ $conf['commitPageMsg'] = 'Wiki page %page% changed with summary [%summary%] by %
$conf['commitPageMsgDel'] = 'Wiki page %page% deleted with reason [%summary%] by %user%';
$conf['commitMediaMsg'] = 'Wiki media %media% uploaded by %user%';
$conf['commitMediaMsgDel'] = 'Wiki media %media% deleted by %user%';
-$conf['repoPath'] = $GLOBALS['conf']['savedir'];
-$conf['repoWorkDir'] = $GLOBALS['conf']['savedir'];
+$conf['repoPath'] = $GLOBALS['conf']['savedir'];
+$conf['repoWorkDir'] = $GLOBALS['conf']['savedir'];
+$conf['gitPath'] = '';
$conf['addParams'] = '';
+$conf['ignorePaths'] = '';
/* plugin/gitbacked: Define a nice author (until addParams is fixed)
* MUST NOT be defined in conf/local.php as $GLOBALS['USERINFO'] does not yet exist there
diff --git a/public_html/lib/plugins/gitbacked/conf/metadata.php b/public_html/lib/plugins/gitbacked/conf/metadata.php
index d3bce744..b71a89f1 100644
--- a/public_html/lib/plugins/gitbacked/conf/metadata.php
+++ b/public_html/lib/plugins/gitbacked/conf/metadata.php
@@ -14,5 +14,6 @@ $meta['commitMediaMsg'] = array('string');
$meta['commitMediaMsgDel'] = array('string');
$meta['repoPath'] = array('string');
$meta['repoWorkDir'] = array('string');
+$meta['gitPath'] = array('string');
$meta['addParams'] = array('string');
-
+$meta['ignorePaths'] = array('string');
diff --git a/public_html/lib/plugins/gitbacked/lang/en/settings.php b/public_html/lib/plugins/gitbacked/lang/en/settings.php
index c5ff0080..43089507 100644
--- a/public_html/lib/plugins/gitbacked/lang/en/settings.php
+++ b/public_html/lib/plugins/gitbacked/lang/en/settings.php
@@ -15,4 +15,6 @@ $lang['commitMediaMsg'] = 'Commit message for media files (%user%,%media% are re
$lang['commitMediaMsgDel'] = 'Commit message for deleted media files (%user%,%media% are replaced by the corresponding values)';
$lang['repoPath'] = 'Path of the git repo (e.g. the savedir '.$GLOBALS['conf']['savedir'].')';
$lang['repoWorkDir'] = 'Path of the git working tree, must contain "pages" and "media" directories (e.g. the savedir '.$GLOBALS['conf']['savedir'].')';
+$lang['gitPath'] = 'Path to the git binary (if empty, the default "/usr/bin/git" will be used)';
$lang['addParams'] = 'Additional git parameters (added to the git execution command) (%user% and %mail% are replaced by the corresponding values)';
+$lang['ignorePaths'] = 'Paths/files which are ignored and not added to git (comma-separated)';
diff --git a/public_html/lib/plugins/gitbacked/lib/Git.php b/public_html/lib/plugins/gitbacked/lib/Git.php
index 6089d35e..be2f0b6b 100644
--- a/public_html/lib/plugins/gitbacked/lib/Git.php
+++ b/public_html/lib/plugins/gitbacked/lib/Git.php
@@ -48,7 +48,7 @@ class Git {
public static function get_bin() {
return self::$bin;
}
-
+
/**
* Sets up library for use in a default Windows environment
*/
@@ -82,20 +82,21 @@ class Git {
public static function open($repo_path) {
return new GitRepo($repo_path);
}
-
+
/**
* Clones a remote repo into a directory and then returns a GitRepo object
* for the newly created local repo
- *
+ *
* Accepts a creation path and a remote to clone from
- *
+ *
* @access public
* @param string repository path
* @param string remote source
+ * @param string reference path
* @return GitRepo
**/
- public static function &clone_remote($repo_path, $remote) {
- return GitRepo::create_new($repo_path, $remote, true);
+ public static function &clone_remote($repo_path, $remote, $reference = null) {
+ return GitRepo::create_new($repo_path, $remote, true, $reference);
}
/**
@@ -137,16 +138,23 @@ class GitRepo {
* @access public
* @param string repository path
* @param string directory to source
+ * @param string reference path
* @return GitRepo
*/
- public static function &create_new($repo_path, $source = null, $remote_source = false) {
+ public static function &create_new($repo_path, $source = null, $remote_source = false, $reference = null) {
if (is_dir($repo_path) && file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
throw new Exception('"'.$repo_path.'" is already a git repository');
} else {
$repo = new self($repo_path, true, false);
if (is_string($source)) {
if ($remote_source) {
- $repo->clone_remote($source);
+ if (!is_dir($reference) || !is_dir($reference.'/.git')) {
+ throw new Exception('"'.$reference.'" is not a git repository. Cannot use as reference.');
+ } else if (strlen($reference)) {
+ $reference = realpath($reference);
+ $reference = "--reference $reference";
+ }
+ $repo->clone_remote($source, $reference);
} else {
$repo->clone_from($source);
}
@@ -229,6 +237,16 @@ class GitRepo {
}
}
+ /**
+ * Get the path to the git repo directory (eg. the ".git" directory)
+ *
+ * @access public
+ * @return string
+ */
+ public function git_directory_path() {
+ return ($this->bare) ? $this->repo_path : $this->repo_path."/.git";
+ }
+
/**
* Tests if git is installed
*
@@ -318,7 +336,7 @@ class GitRepo {
* Runs a 'git status' call
*
* Accept a convert to HTML bool
- *
+ *
* @access public
* @param bool return string with
* @return string
@@ -346,7 +364,7 @@ class GitRepo {
}
return $this->run("add $files -v");
}
-
+
/**
* Runs a `git rm` call
*
@@ -372,10 +390,12 @@ class GitRepo {
*
* @access public
* @param string commit message
+ * @param boolean should all files be committed automatically (-a flag)
* @return string
*/
- public function commit($message = "") {
- return $this->run("commit -av -m ".escapeshellarg($message));
+ public function commit($message = "", $commit_all = true) {
+ $flags = $commit_all ? '-av' : '-v';
+ return $this->run("commit ".$flags." -m ".escapeshellarg($message));
}
/**
@@ -414,10 +434,11 @@ class GitRepo {
*
* @access public
* @param string source url
+ * @param string reference path
* @return string
*/
- public function clone_remote($source) {
- return $this->run("clone $source ".$this->repo_path);
+ public function clone_remote($source, $reference) {
+ return $this->run("clone $reference $source ".$this->repo_path);
}
/**
@@ -569,7 +590,7 @@ class GitRepo {
if ($message === null) {
$message = $tag;
}
- return $this->run("tag -a $tag -m $message");
+ return $this->run("tag -a $tag -m " . escapeshellarg($message));
}
/**
@@ -619,13 +640,27 @@ class GitRepo {
return $this->run("pull $remote $branch");
}
+ /**
+ * List log entries.
+ *
+ * @param strgin $format
+ * @return string
+ */
+ public function log($format = null) {
+ if ($format === null)
+ return $this->run('log');
+ else
+ return $this->run('log --pretty=format:"' . $format . '"');
+ }
+
/**
* Sets the project description.
*
* @param string $new
*/
public function set_description($new) {
- file_put_contents($this->repo_path."/.git/description", $new);
+ $path = $this->git_directory_path();
+ file_put_contents($path."/description", $new);
}
/**
@@ -634,7 +669,8 @@ class GitRepo {
* @return string
*/
public function get_description() {
- return file_get_contents($this->repo_path."/.git/description");
+ $path = $this->git_directory_path();
+ return file_get_contents($path."/description");
}
/**
@@ -650,4 +686,3 @@ class GitRepo {
}
/* End of file */
-
diff --git a/public_html/lib/plugins/gitbacked/plugin.info.txt b/public_html/lib/plugins/gitbacked/plugin.info.txt
index 15a80890..f3ac1ee0 100644
--- a/public_html/lib/plugins/gitbacked/plugin.info.txt
+++ b/public_html/lib/plugins/gitbacked/plugin.info.txt
@@ -1,7 +1,7 @@
base gitbacked
-author Wolfgang Gassler
+author Wolfgang Gassler (@woolfg), Carsten Teibes (@carstene1ns)
email wolfgang@gassler.org
-date 2012-10-31
+date 2016-08-14
name gitbacked plugin
desc Pages and Media are stored in Git
-url https://github.com/woolfg/gitbacked
+url https://github.com/woolfg/dokuwiki-plugin-gitbacked