edit: save changes as git commit
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 3 Oct 2017 01:41:10 +0000 (03:41 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 4 Oct 2017 22:26:32 +0000 (00:26 +0200)
Assume direct access to repository if .git is writable, which is preferable
to daily crons to save authors and reedits.

edit.php

index ca9639c3da44f2049cf14bb2318ec1be0b919b34..9ba0d04c02c34d2265851839eedd045cdcbfba95 100644 (file)
--- a/edit.php
+++ b/edit.php
@@ -60,5 +60,19 @@ if (!file_exists(dirname($filename)) and !mkdir(dirname($filename)))
 if (!file_put_contents($filename, $upload))
        abort("fout bij schrijven van $filename", '500 save error');
 
+if (is_writable('../.git')) {
+       $gitmsg = preg_replace('/\.html$/', '', $filename).": edit from {$_SERVER['REMOTE_ADDR']}";
+       $gitcmd = 'git';
+       $gitcmd .= ' -c user.name='.escapeshellarg($User['name']);
+       $gitcmd .= ' -c user.email='.escapeshellarg("{$User['name']}@lijtweg.nl");
+       $gitcmd .= ' commit -q';
+       $gitcmd .= ' -m '.escapeshellarg($gitmsg);
+       $gitcmd .= ' -- '.escapeshellarg($filename);
+       exec("$gitcmd 2>&1", $gitlog, $gitstatus);
+       if ($gitstatus) {
+               trigger_error("git commit failure $gitstatus: ".implode("\n", $gitlog), E_USER_WARNING);
+       }
+}
+
 abort("Bestand opgeslagen");