]> git.plutz.net Git - shellwiki/commitdiff
track pages in git
authorPaul Hänsch <paul@plutz.net>
Fri, 20 May 2022 10:09:11 +0000 (12:09 +0200)
committerPaul Hänsch <paul@plutz.net>
Fri, 20 May 2022 10:09:11 +0000 (12:09 +0200)
handlers/30_edit.sh
index.cgi

index aa55796ccce501fae8af249458bbef2513ee5994..6dfe2e863f26d86862a5ee0d3c11183967f66052 100755 (executable)
@@ -25,16 +25,25 @@ if [ "$edit_page" = "$PATH_INFO" ]; then
   # END EDIT SCRIPT, continue in index.cgi
 
 elif [ "$edit_action" = update ]; then
-  if mkdir -p -- "${edit_file%/#page.md}" \
-       && S_LOCK "$edit_file"; then
+  if  mkdir -p -- "${edit_file%/#page.md}" \
+      && S_LOCK "$edit_file"; then
     POST pagetext >"$edit_file"
     S_RELEASE "$edit_file"
-    REDIRECT "${_BASE}${PATH_INFO%\[edit\]}"
   else
     export ERRMSG="ERR_NOLOCK"
     REDIRECT "${_BASE}${PATH_INFO%\[edit\]}/[edit]"
   fi
 
+  if [ "$(which git)" ]; then
+    git -C "$_DATA" add \
+      -- "pages/$edit_page/#page.md"
+    git -C "$_DATA" commit -m \
+      "Page # ${edit_page} # updated by user @ ${USER_NAME} @" \
+      -- "pages/$edit_page/#page.md"
+  fi
+
+  REDIRECT "${_BASE}${PATH_INFO%\[edit\]}"
+
 elif [ "$edit_action" = cancel ]; then
   S_RELEASE "$edit_file"
   REDIRECT "${_BASE}${PATH_INFO%\[edit\]}"
index 57398a4ff7f9aabc4879b9a2b20cfb5b3b6dcb94..2248308ddd05ce61252beb9e1edd7fe333efdfa8 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -19,6 +19,21 @@ wiki_text() {
   cat -- "$mdfile"
 }
 
+if [ "$(which git)" -a ! -f "$_DATA/.gitignore" ]; then
+  cat >"$_DATA/.gitignore" <<-EOF
+       users.db
+       serverkey
+       */#attachments/
+       */#cache/
+       */#page.lock
+       */#page.*.cache
+       */#page.*.cache.*
+       EOF
+  git init "$_DATA"
+  git -C "$_DATA" add .gitignore
+  git -C "$_DATA" commit -m 'initialization' -- .gitignore
+fi 1>&2
+
 for handler in "$_EXEC"/handlers/*; do
   . "$handler" && break
 done