From 8899a8271338ba19f32bae1b30e0df0392afe1bc Mon Sep 17 00:00:00 2001
From: Boris Kolpackov <boris@codesynthesis.com>
Date: Tue, 30 Aug 2011 16:37:11 +0200
Subject: Add error handling to git scripts

---
 git/branch.sh   |  6 ++++++
 git/checkout.sh |  6 ++++++
 git/commit.sh   | 12 ++++++++++++
 git/diff.sh     | 13 +++++++++++++
 git/fetch.sh    |  6 ++++++
 git/pull.sh     |  6 ++++++
 git/push.sh     |  5 +++++
 git/rebase.sh   |  6 ++++++
 git/remote.sh   |  6 ++++++
 git/stash.sh    |  6 ++++++
 git/stat.sh     |  6 ++++++
 git/tag.sh      |  6 ++++++
 12 files changed, 84 insertions(+)

diff --git a/git/branch.sh b/git/branch.sh
index 4362fb4..14d72dd 100755
--- a/git/branch.sh
+++ b/git/branch.sh
@@ -11,5 +11,11 @@ for i in $modules; do
   echo "branch $i" 1>&2
   cd $i
   git branch $*
+
+  if [ $? -ne 0 ]; then
+    echo "branch FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/checkout.sh b/git/checkout.sh
index 2cf5717..11643c4 100755
--- a/git/checkout.sh
+++ b/git/checkout.sh
@@ -16,5 +16,11 @@ for i in $modules; do
   echo "checkout $i" 1>&2
   cd $i
   git checkout $*
+
+  if [ $? -ne 0 ]; then
+    echo "checkout FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/commit.sh b/git/commit.sh
index 16a8076..cc05cf5 100755
--- a/git/commit.sh
+++ b/git/commit.sh
@@ -38,8 +38,20 @@ for i in $modules; do
   cd $i
   if [ "$add" = "y" ]; then
     git add .
+
+    if [ $? -ne 0 ]; then
+      echo "add FAILED" 1>&2
+      exit 1
+    fi
+
   fi
   git commit -F $msg_file
+
+  if [ $? -ne 0 ]; then
+    echo "commit FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
 
diff --git a/git/diff.sh b/git/diff.sh
index 19737e9..bd4639e 100755
--- a/git/diff.sh
+++ b/git/diff.sh
@@ -10,7 +10,20 @@ wd=`pwd`
 for i in $modules; do
   echo "diff $i" 1>&2
   cd $i
+
   git --no-pager diff
+
+  if [ $? -ne 0 ]; then
+    echo "diff FAILED" 1>&2
+    exit 1
+  fi
+
   git --no-pager diff --check
+
+  if [ $? -ne 0 ]; then
+    echo "diff --check FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/fetch.sh b/git/fetch.sh
index a18be15..185d531 100755
--- a/git/fetch.sh
+++ b/git/fetch.sh
@@ -11,5 +11,11 @@ for i in $modules; do
   echo "fetch $i" 1>&2
   cd $i
   git fetch $*
+
+  if [ $? -ne 0 ]; then
+    echo "fetch FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/pull.sh b/git/pull.sh
index cf94cf0..07684da 100755
--- a/git/pull.sh
+++ b/git/pull.sh
@@ -11,5 +11,11 @@ for i in $modules; do
   echo "pull $i" 1>&2
   cd $i
   git pull $*
+
+  if [ $? -ne 0 ]; then
+    echo "pull FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/push.sh b/git/push.sh
index cd1c1b8..d288f3a 100755
--- a/git/push.sh
+++ b/git/push.sh
@@ -25,5 +25,10 @@ for i in $modules; do
     git push $ops origin $1
   fi
 
+  if [ $? -ne 0 ]; then
+    echo "push FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/rebase.sh b/git/rebase.sh
index 67313b1..4248048 100755
--- a/git/rebase.sh
+++ b/git/rebase.sh
@@ -16,5 +16,11 @@ for i in $modules; do
   echo "rebase $i" 1>&2
   cd $i
   git rebase $*
+
+  if [ $? -ne 0 ]; then
+    echo "rebase FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/remote.sh b/git/remote.sh
index 8d67450..acc1e4a 100755
--- a/git/remote.sh
+++ b/git/remote.sh
@@ -11,5 +11,11 @@ for i in $modules; do
   echo "remote $i" 1>&2
   cd $i
   git remote $*
+
+  if [ $? -ne 0 ]; then
+    echo "remote FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/stash.sh b/git/stash.sh
index 63a6022..139f294 100755
--- a/git/stash.sh
+++ b/git/stash.sh
@@ -11,5 +11,11 @@ for i in $modules; do
   echo "stash $i" 1>&2
   cd $i
   git stash $*
+
+  if [ $? -ne 0 ]; then
+    echo "stash FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/stat.sh b/git/stat.sh
index 39eb081..5b9ea45 100755
--- a/git/stat.sh
+++ b/git/stat.sh
@@ -11,5 +11,11 @@ for i in $modules; do
   echo "stat $i" 1>&2
   cd $i
   git status
+
+  if [ $? -ne 0 ]; then
+    echo "stat FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
diff --git a/git/tag.sh b/git/tag.sh
index 99ba938..935934f 100755
--- a/git/tag.sh
+++ b/git/tag.sh
@@ -16,5 +16,11 @@ for i in $modules; do
   echo "tag $i" 1>&2
   cd $i
   git tag -a $1 -m "Tag version $1"
+
+  if [ $? -ne 0 ]; then
+    echo "tag FAILED" 1>&2
+    exit 1
+  fi
+
   cd $wd
 done
-- 
cgit v1.1