about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-18 13:57:39 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-18 13:57:39 -0700
commit5aa38b5237b60795fb119165993e80bd2e906555 (patch)
treec1607b543def0495b21281f4dcc82249c1dda7f7
parent13ba3defe91b4de6ab3da7e937ee448c49909725 (diff)
downloadmu-5aa38b5237b60795fb119165993e80bd2e906555.tar.gz
1815 - git commit only if lesson/.git exists
We want to avoid accidentally mixing lessons into ourselves. Require
users to git-enable it first.
-rw-r--r--082persist.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/082persist.cc b/082persist.cc
index 3f9850fe..2c798cfb 100644
--- a/082persist.cc
+++ b/082persist.cc
@@ -42,9 +42,19 @@ case SAVE: {
   ofstream fout("lesson/recipe.mu");
   fout << contents;
   fout.close();
+  if (!exists("lesson/.git")) break;
   // bug in git: git diff -q messes up --exit-code
   int status = system("cd lesson; git diff --exit-code >/dev/null || git commit -a -m . >/dev/null");
   if (status != 0)
     raise << "error in commit: contents " << contents << '\n';
   break;
 }
+
+:(code)
+bool exists(const string& filename) {
+  struct stat dummy;
+  return 0 == stat(filename.c_str(), &dummy);
+}
+
+:(before "End Includes")
+#include<sys/stat.h>