diff options
-rw-r--r-- | html-gen.sh | 3 | ||||
-rw-r--r-- | install.sh | 12 | ||||
-rw-r--r-- | pre-commit.sh | 20 | ||||
-rw-r--r-- | pre-receive.sh | 10 |
4 files changed, 41 insertions, 4 deletions
diff --git a/html-gen.sh b/html-gen.sh index 7847a7d..d66dc12 100644 --- a/html-gen.sh +++ b/html-gen.sh @@ -36,8 +36,7 @@ for f in "$articles_dir"/*; do done | sort -nr | cut -d' ' -f2 > "$articles_sorted" if [ "`head -1 $articles_sorted`" = "" ]; then - echo "[fugitive] Need at least one article, aborting." >&2 - exit 1 + echo "[fugitive] WARNING: there's no article, errors may occur." >&2 fi articles_sorted_with_delete=`mktemp --suffix "-fugitive"` @@ -12,6 +12,12 @@ fugitive_write_template() { fugitive_install_hooks() { echo -n "Installing fugitive hooks scripts... " + (base64 -d | gunzip) >> .git/hooks/pre-commit <<EOF +#INCLUDE:pre-commit.sh# +EOF + (base64 -d | gunzip) >> .git/hooks/pre-receive <<EOF +#INCLUDE:pre-receive.sh# +EOF (base64 -d | gunzip) > .git/hooks/post-commit <<EOF #INCLUDE:post-commit.sh# EOF @@ -22,6 +28,8 @@ EOF tee -a .git/hooks/post-commit) >> .git/hooks/post-receive <<EOF #INCLUDE:html-gen.sh# EOF + chmod +x .git/hooks/pre-commit + chmod +x .git/hooks/pre-receive chmod +x .git/hooks/post-commit chmod +x .git/hooks/post-receive echo "done." @@ -89,14 +97,14 @@ EOF echo "done." echo -n "Importing files into git repository... " git add _templates/* _public/*.css >/dev/null - git commit -m "fugitive inital import" >/dev/null 2>&1 + git commit --no-verify -m "fugitive inital import" >/dev/null 2>&1 echo "done." echo "Writing dummy article (README) and adding it to the repos... " (base64 -d | gunzip) > _articles/README <<EOF #INCLUDE:README# EOF git add _articles/README - git commit -m "fugitive: README" >/dev/null + git commit --no-verify -m "fugitive: README" >/dev/null echo "done." fi echo "Installation complete, please set your blog url using" diff --git a/pre-commit.sh b/pre-commit.sh new file mode 100644 index 0000000..225c73e --- /dev/null +++ b/pre-commit.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +articles_dir=`git config --get fugitive.articles-dir` + +article_exists=`mktemp --suffix "-fugitive"` +for f in "$articles_dir"/*; do + ts=`git log --format="%at" -- "$f" | tail -1` + if [ "$ts" != "" ]; then + echo "1" + break + fi +done > "$article_exists" +article_exists=`cat $article_exists` +non_tracked=`git status --porcelain | grep -E '^(A|R)' | grep "$articles_dir"` + +if [ "$article_exists" = "" -a "$non_tracked" = "" ]; then + echo -n "[fugitive] ERROR: need at least one article (you can use " >&2 + echo '`git commit --no-verify` to bypass), aborting.' >&2 + exit 1 +fi diff --git a/pre-receive.sh b/pre-receive.sh new file mode 100644 index 0000000..63bc870 --- /dev/null +++ b/pre-receive.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +blog_url=`git config --get fugitive.blog-url` +if [ "$blog_url" = "" ]; then + echo -n "[fugitive] ERROR: git config fugitive.blog-url is empty and" >&2 + echo -n " should not be, please set it with " >&2 + echo -n '`git config fugitive.blog-url "<url>"` ' >&2 + echo "on the remote repository, aborting." >&2 + exit 1 +fi |