now preventing commit when zero article (for real ^^) and push when fugitive.blog-url not set

This commit is contained in:
p4bl0 2010-08-10 22:25:11 +02:00
parent d0618efb64
commit f71626c7ec
4 changed files with 41 additions and 4 deletions

View File

@ -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"`

View File

@ -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"

20
pre-commit.sh Normal file
View File

@ -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

10
pre-receive.sh Normal file
View File

@ -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