summaryrefslogtreecommitdiffstats
path: root/update_all_submodules
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2012-12-04 03:44:32 +0100
committerSlávek Banko <slavek.banko@axis.cz>2012-12-04 03:44:32 +0100
commit95dd4739aa62188f6ffbfdf80b6537357559a7ec (patch)
treefa3730e7ea8f71643e57b69fcb488bb32921a57c /update_all_submodules
parent5ead2a2d3b029dbdc616c282d7aa6b6fc7ea7907 (diff)
downloadscripts-95dd4739aa62188f6ffbfdf80b6537357559a7ec.tar.gz
scripts-95dd4739aa62188f6ffbfdf80b6537357559a7ec.zip
Updating git scripts
+ add support for gitfile (submodules with git >= 1.7.8) + add gituser detection from git configuration + add support for branches + various optimizations
Diffstat (limited to 'update_all_submodules')
-rwxr-xr-xupdate_all_submodules57
1 files changed, 36 insertions, 21 deletions
diff --git a/update_all_submodules b/update_all_submodules
index d0bf837..8e6668f 100755
--- a/update_all_submodules
+++ b/update_all_submodules
@@ -6,17 +6,28 @@ if [[ -e /var/lock/update-tde-git-submodules ]]; then
exit 0
fi
+if [[ ! -e .git ]] ||
+ [[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
+ echo "Current directory does not contain a .git folder. Exiting..."
+ exit 1
+fi
+
+branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"`
+if [[ -z "$branch" ]] ||
+ [[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
+ echo "There is not active upstream branch. Exiting..."
+ exit 1
+fi
+
touch /var/lock/update-tde-git-submodules
PARENTDIR=$PWD
echo "Working in $PARENTDIR"
-if [[ ! -d .git ]]; then
- echo "Current directory does not contain a .git folder. Exiting..."
- exit 1
-fi
git pull
-git reset --hard HEAD
-git clean -d -x -f
+if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
+ git reset --hard HEAD
+ git clean -dxff
+fi
exec 3< submodules
while read <&3
@@ -26,25 +37,29 @@ do
if [[ $DIR2UPDATE != "" ]]; then
echo "Attempting to reset submodule $DIR2UPDATE"
cd $PARENTDIR/$DIR2UPDATE/..
- while [[ ! -d .git ]]; do
- cd ../
- done
- git submodule init
- git submodule update
+ cd `git rev-parse --show-toplevel`
+ if [[ -z "`grep \"^Updated: $PWD$\" /var/lock/update-tde-git-submodules`" ]]; then
+ echo "Updated: $PWD" >>/var/lock/update-tde-git-submodules
+ git submodule init
+ git submodule update
+ fi
cd $PARENTDIR/$DIR2UPDATE
- git reset --hard HEAD
- git clean -d -x -f
- git checkout master
+ if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
+ git reset --hard HEAD
+ git clean -dxff
+ fi
+ git checkout $branch
git pull
cd ..
- while [[ ! -d .git ]]; do
- cd ../
- done
+ cd `git rev-parse --show-toplevel`
echo "Committing changes to $PWD"
-# git commit -a -m "Reset submodule to latest HEAD"
- git add $PARENTDIR/$DIR2UPDATE
- git commit $PARENTDIR/$DIR2UPDATE -m "Reset submodule $DIR2UPDATE to latest HEAD"
- git push origin master
+ if [[ ! -z "`git status --porcelain $PARENTDIR/$DIR2UPDATE`" ]]; then
+ git add $PARENTDIR/$DIR2UPDATE
+ git commit $PARENTDIR/$DIR2UPDATE -m "Reset submodule $DIR2UPDATE to latest HEAD"
+ fi
+ if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
+ git push origin HEAD
+ fi
fi
done
exec 3>&-