Skip to content

Commit 8be0bb0

Browse files
committed
Allow using several git repos
- improvements due to code review: - changed config 'initRepo' -> 'autoDetermineRepos' to leverage self explanation - added missing language description for this config Fixes #47
1 parent 8574d38 commit 8be0bb0

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

action/editcommit.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,33 @@ public function register(Doku_Event_Handler $controller) {
3030
$controller->register_hook('DOKUWIKI_DONE', 'AFTER', $this, 'handle_periodic_pull');
3131
}
3232

33-
private function initRepo($initRepo=True, $filePath="") {
34-
if($initRepo) {
35-
$repoPath = GitBackedUtil::getEffectivePath($this->getConf('repoPath'));
36-
} else {
33+
private function initRepo($isAutoDetermineRepos=false, $filePath="") {
34+
if($isAutoDetermineRepos) {
3735
$repoPath = dirname($filePath);
36+
} else {
37+
//get path to the repo root (by default DokuWiki's savedir)
38+
$repoPath = GitBackedUtil::getEffectivePath($this->getConf('repoPath'));
3839
}
3940
//set the path to the git binary
4041
$gitPath = trim($this->getConf('gitPath'));
4142
if ($gitPath !== '') {
4243
Git::set_bin($gitPath);
4344
}
44-
if ($initRepo) {
45+
if ($isAutoDetermineRepos) {
46+
$repo = new GitRepo($repoPath, $this, false, false);
47+
} else {
4548
//init the repo and create a new one if it is not present
4649
io_mkdir_p($repoPath);
4750
$repo = new GitRepo($repoPath, $this, true, true);
48-
} else {
49-
$repo = new GitRepo($repoPath, $this, false, false);
5051
}
5152
//set git working directory (by default DokuWiki's savedir)
52-
if ($initRepo) {
53+
if ($isAutoDetermineRepos) {
54+
$repoWorkDir = "";
55+
} else {
5356
$repoWorkDir = $this->getConf('repoWorkDir');
5457
if (!empty($repoWorkDir)) {
5558
$repoWorkDir = GitBackedUtil::getEffectivePath($repoWorkDir);
5659
}
57-
} else {
58-
$repoWorkDir = "";
5960
}
6061

6162
Git::set_bin(empty($repoWorkDir) ? Git::get_bin() : Git::get_bin().' --work-tree '.escapeshellarg($repoWorkDir));
@@ -87,11 +88,11 @@ private function isIgnored($filePath) {
8788
private function commitFile($filePath,$message) {
8889
if (!$this->isIgnored($filePath)) {
8990
try {
90-
$initRepo = $this->getConf('initRepo');
91-
if ($initRepo) {
92-
$repo = $this->initRepo();
91+
$isAutoDetermineRepos = $this->getConf('autoDetermineRepos');
92+
if ($isAutoDetermineRepos) {
93+
$repo = $this->initRepo($isAutoDetermineRepos, $filePath);
9394
} else {
94-
$repo = $this->initRepo($initRepo, $filePath);
95+
$repo = $this->initRepo();
9596
}
9697

9798
//add the changed file and set the commit message

conf/default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Wolfgang Gassler <[email protected]>
66
*/
77

8-
$conf['initRepo'] = 1;
8+
$conf['autoDetermineRepos'] = 1;
99
$conf['pushAfterCommit'] = 0;
1010
$conf['periodicPull'] = 0;
1111
$conf['periodicMinutes'] = 60;

conf/metadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Wolfgang Gassler <[email protected]>
66
*/
77

8-
$meta['initRepo'] = array('onoff');
8+
$meta['autoDetermineRepos'] = array('onoff');
99
$meta['pushAfterCommit'] = array('onoff');
1010
$meta['periodicPull'] = array('onoff');
1111
$meta['periodicMinutes'] = array('numeric');

lang/de/settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @author Markus Hoffrogge <[email protected]>
77
*/
88

9+
$lang['autoDetermineRepos'] = 'Erkennt existierende git repo(s) in dem Pfad der geänderten Datei. Wenn gesetzt, dann werden die Einstellungen <code>repoPath</code> und <code>repoWorkDir</code> ignoriert.';
910
$lang['pushAfterCommit'] = 'Push des aktiven Branch zum remote origin nach jedem commit';
1011
$lang['periodicPull'] = 'Pull des remote git Repositories alle "periodicMinutes", getriggert von einem http Page Request';
1112
$lang['periodicMinutes'] = 'Zeitraum (in Minuten) zwischen den periodischen pull requests';

lang/en/settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @author Wolfgang Gassler <[email protected]>
77
*/
88

9+
$lang['autoDetermineRepos'] = 'Determine existing git repo(s) from the path of the file to commit. If set, then the configs <code>repoPath</code> and <code>repoWorkDir</code> are ignored.';
910
$lang['pushAfterCommit'] = 'Push active branch to remote origin after every commit';
1011
$lang['periodicPull'] = 'Pull the remote git repository every "periodicMinutes" triggered by a http page request';
1112
$lang['periodicMinutes'] = 'Timespan (in minutes) between periodic pull requests';

0 commit comments

Comments
 (0)