From d1afddfdc3f5d901b26a064d9422978e5e8a8acd Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Tue, 3 Oct 2017 03:41:10 +0200 Subject: [PATCH] edit: save changes as git commit Assume direct access to repository if .git is writable, which is preferable to daily crons to save authors and reedits. --- edit.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/edit.php b/edit.php index ca9639c..9ba0d04 100644 --- 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"); -- 2.30.0