Revert "MEDIUM: Update plugin gitbacked to v2016-08-14"

This reverts commit 24e82cfc5a.
This commit is contained in:
Bertrand Jacquin 2017-10-19 01:45:38 +01:00
parent 27153f9e6a
commit e872d726cb
No known key found for this signature in database
GPG Key ID: 5534871F2E2E93DA
7 changed files with 38 additions and 100 deletions

View File

@ -1,4 +1,4 @@
# gitbacked Plugin for DokuWiki
gitbacked Plugin for DokuWiki
Store/Sync pages and media files in a git repository
@ -6,14 +6,13 @@ 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 <wolfgang@gassler.org>
This program is free software; you can redistribute it and/or modify

View File

@ -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,56 +39,35 @@ 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');
Git::set_bin(Git::get_bin().' --work-tree '.escapeshellarg($repoWorkDir));
$repo->git_path .= ' --work-tree '.escapeshellarg($repoWorkDir);
$params = str_replace(
array('%mail%','%user%'),
array($this->getAuthorMail(),$this->getAuthor()),
$this->getConf('addParams'));
if ($params) {
Git::set_bin(Git::get_bin().' '.$params);
$repo->git_path .= ' '.$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) {
if (!$this->isIgnored($filePath)) {
$repo = $this->initRepo();
$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());
}
}

View File

@ -12,11 +12,9 @@ $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['gitPath'] = '';
$conf['repoPath'] = $GLOBALS['conf']['savedir'];
$conf['repoWorkDir'] = $GLOBALS['conf']['savedir'];
$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

View File

@ -14,6 +14,5 @@ $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');

View File

@ -15,6 +15,4 @@ $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)';

View File

@ -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,21 +82,20 @@ 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, $reference = null) {
return GitRepo::create_new($repo_path, $remote, true, $reference);
public static function &clone_remote($repo_path, $remote) {
return GitRepo::create_new($repo_path, $remote, true);
}
/**
@ -138,23 +137,16 @@ 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, $reference = null) {
public static function &create_new($repo_path, $source = null, $remote_source = false) {
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) {
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);
$repo->clone_remote($source);
} else {
$repo->clone_from($source);
}
@ -237,16 +229,6 @@ 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
*
@ -336,7 +318,7 @@ class GitRepo {
* Runs a 'git status' call
*
* Accept a convert to HTML bool
*
*
* @access public
* @param bool return string with <br />
* @return string
@ -364,7 +346,7 @@ class GitRepo {
}
return $this->run("add $files -v");
}
/**
* Runs a `git rm` call
*
@ -390,12 +372,10 @@ class GitRepo {
*
* @access public
* @param string commit message
* @param boolean should all files be committed automatically (-a flag)
* @return string
*/
public function commit($message = "", $commit_all = true) {
$flags = $commit_all ? '-av' : '-v';
return $this->run("commit ".$flags." -m ".escapeshellarg($message));
public function commit($message = "") {
return $this->run("commit -av -m ".escapeshellarg($message));
}
/**
@ -434,11 +414,10 @@ class GitRepo {
*
* @access public
* @param string source url
* @param string reference path
* @return string
*/
public function clone_remote($source, $reference) {
return $this->run("clone $reference $source ".$this->repo_path);
public function clone_remote($source) {
return $this->run("clone $source ".$this->repo_path);
}
/**
@ -590,7 +569,7 @@ class GitRepo {
if ($message === null) {
$message = $tag;
}
return $this->run("tag -a $tag -m " . escapeshellarg($message));
return $this->run("tag -a $tag -m $message");
}
/**
@ -640,27 +619,13 @@ 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) {
$path = $this->git_directory_path();
file_put_contents($path."/description", $new);
file_put_contents($this->repo_path."/.git/description", $new);
}
/**
@ -669,8 +634,7 @@ class GitRepo {
* @return string
*/
public function get_description() {
$path = $this->git_directory_path();
return file_get_contents($path."/description");
return file_get_contents($this->repo_path."/.git/description");
}
/**
@ -686,3 +650,4 @@ class GitRepo {
}
/* End of file */

View File

@ -1,7 +1,7 @@
base gitbacked
author Wolfgang Gassler (@woolfg), Carsten Teibes (@carstene1ns)
author Wolfgang Gassler
email wolfgang@gassler.org
date 2016-08-14
date 2012-10-31
name gitbacked plugin
desc Pages and Media are stored in Git
url https://github.com/woolfg/dokuwiki-plugin-gitbacked
url https://github.com/woolfg/gitbacked