From f71626c7ecade5cf26baa9cb318cdd1c3d0c84c1 Mon Sep 17 00:00:00 2001 From: p4bl0 Date: Tue, 10 Aug 2010 22:25:11 +0200 Subject: [PATCH] now preventing commit when zero article (for real ^^) and push when fugitive.blog-url not set --- html-gen.sh | 3 +-- install.sh | 12 ++++++++++-- pre-commit.sh | 20 ++++++++++++++++++++ pre-receive.sh | 10 ++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 pre-commit.sh create mode 100644 pre-receive.sh 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"` diff --git a/install.sh b/install.sh index 5a2b2d2..2801336 100644 --- a/install.sh +++ b/install.sh @@ -12,6 +12,12 @@ fugitive_write_template() { fugitive_install_hooks() { echo -n "Installing fugitive hooks scripts... " + (base64 -d | gunzip) >> .git/hooks/pre-commit <> .git/hooks/pre-receive < .git/hooks/post-commit <> .git/hooks/post-receive </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 </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 ""` ' >&2 + echo "on the remote repository, aborting." >&2 + exit 1 +fi