aboutsummaryrefslogtreecommitdiff
path: root/commit
diff options
context:
space:
mode:
Diffstat (limited to 'commit')
-rwxr-xr-xcommit77
1 files changed, 77 insertions, 0 deletions
diff --git a/commit b/commit
new file mode 100755
index 0000000..6f9dd48
--- /dev/null
+++ b/commit
@@ -0,0 +1,77 @@
+#!/bin/bash
+#
+# Commit both on git and svn.
+#
+
+# Check if a folder is inside a git repository
+function is_git {
+ # simple git folder checker
+ # usage: is_git <folder>
+ if [ -z "$1" ]; then
+ false
+ elif [ ! -d "$1" ]; then
+ false
+ elif [ -d "$1/.git" ]; then
+ true
+ else
+ ( cd "$1" && git status &> /dev/null )
+
+ if [ "$?" != "128" ]; then
+ true
+ else
+ false
+ fi
+ fi
+}
+
+# Check if a folder is inside a svn repository
+function is_svn {
+ # simple svn folder checker
+ # usage: is_svn <folder>
+
+ if [ -d "$1/.svn" ]; then
+ return
+ else
+ return 1
+ fi
+}
+
+# Push to repositories
+function git_push {
+ if [ "`git remote | wc -l`" == "0" ]; then
+ return
+ elif git remote | grep -q 'all'; then
+ git push all --all
+ elif git remote | grep -q 'origin'; then
+ git push --all
+ fi
+}
+
+# Check user information
+function git_user {
+ if ! grep -q "^\[user\]" .git/config; then
+ echo "No user configuration section found in the repository."
+ echo "This might be a privacy issue"
+
+ if [ -e "$HOME/.gitconfig" ]; then
+ echo "You should try to use your default setting:"
+ echo "cat <<EOF >> .git/config"
+ grep -A 2 "^\[user\]" $HOME/.gitconfig
+ echo "EOF"
+ fi
+
+ exit 1
+ fi
+}
+
+if [ ! -z "$1" ]; then
+ if is_svn .; then
+ svn commit -m "$*"
+ fi
+
+ if is_git .; then
+ git_user
+ git commit -a -m "$*"
+ git_push
+ fi
+fi