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
pull/1/head
Slávek Banko 12 years ago
parent 5ead2a2d3b
commit 95dd4739aa

@ -1,17 +1,29 @@
#!/bin/bash #!/bin/bash
if [[ ! -d .git ]]; then if [[ ! -e .git ]] ||
[[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
echo "This script can only be run from a top level git directory. Exiting..." echo "This script can only be run from a top level git directory. Exiting..."
exit 1 exit 1
fi 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
echo "Preparing $PWD for development use" echo "Preparing $PWD for development use"
if [[ $1 == "" ]]; then if [[ $1 == "" ]]; then
read -p "Enter your TDE GIT username []: " -e gituser gituser=`sed -n "/^\[remote \"origin\"\]/,/url/s/\turl = http:\/\/\([^@]*\)@.*/\1/p" <\`git rev-parse --git-dir\`/config | grep -v "\(anonymous\|system\)"`
else else
gituser=$1 gituser=$1
fi fi
if [[ $gituser == "" ]]; then
read -p "Enter your TDE GIT username []: " -e gituser
fi
if [[ $gituser == "" ]]; then if [[ $gituser == "" ]]; then
gituser="anonymous" gituser="anonymous"
fi fi
@ -19,8 +31,10 @@ fi
read -p "Enter your commit message []: " -e commitmessage read -p "Enter your commit message []: " -e commitmessage
git submodule foreach "git commit -a -m \"$commitmessage\" || true" git submodule foreach "git commit -a -m \"$commitmessage\" || true"
git submodule foreach "sed -i \"s/system@scm\.trinitydesktop\.org/$gituser@scm\.trinitydesktop\.org/g\" .git/config" git submodule foreach "sed -i \"s/system@scm\.trinitydesktop\.org/$gituser@scm\.trinitydesktop\.org/g\" \`git rev-parse --git-dir\`/config"
git submodule foreach "git pull && git push origin master" git submodule foreach "git pull &&\
[[ \"\`git rev-parse HEAD\`\" == \"\`git rev-parse origin/$branch\`\" ]] ||\
git push origin HEAD"
RETCODE=$? RETCODE=$?
if [[ $RETCODE != 0 ]]; then if [[ $RETCODE != 0 ]]; then
echo "Something went wrong" echo "Something went wrong"
@ -28,5 +42,7 @@ if [[ $RETCODE != 0 ]]; then
fi fi
git commit -a -m "$commitmessage" || true git commit -a -m "$commitmessage" || true
sed -i "s/system@scm\.trinitydesktop\.org/$gituser@scm\.trinitydesktop\.org/g" .git/config sed -i "s/system@scm\.trinitydesktop\.org/$gituser@scm\.trinitydesktop\.org/g" `git rev-parse --git-dir`/config
git pull && git push origin master || true git pull &&\
[[ "`git rev-parse HEAD`" == "`git rev-parse origin/$branch`" ]] ||\
git push origin HEAD || true

@ -1,17 +1,29 @@
#!/bin/bash #!/bin/bash
if [[ ! -d .git ]]; then if [[ ! -e .git ]] ||
[[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
echo "This script can only be run from a top level git directory. Exiting..." echo "This script can only be run from a top level git directory. Exiting..."
exit 1 exit 1
fi 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
echo "Preparing $PWD for development use" echo "Preparing $PWD for development use"
if [[ $1 == "" ]]; then if [[ $1 == "" ]]; then
read -p "Enter your TDE GIT username []: " -e gituser gituser=`sed -n "/^\[remote \"origin\"\]/,/url/s/\turl = http:\/\/\([^@]*\)@.*/\1/p" <\`git rev-parse --git-dir\`/config | grep -v "\(anonymous\|system\)"`
else else
gituser=$1 gituser=$1
fi fi
if [[ $gituser == "" ]]; then
read -p "Enter your TDE GIT username []: " -e gituser
fi
if [[ $gituser == "" ]]; then if [[ $gituser == "" ]]; then
gituser="anonymous" gituser="anonymous"
fi fi
@ -23,11 +35,15 @@ if [[ ! -e "$THISSCRIPT" ]]; then
exit 1 exit 1
fi fi
if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
git reset --hard HEAD git reset --hard HEAD
git clean -dxf git clean -dxff
fi
git pull git pull
if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
git reset --hard HEAD git reset --hard HEAD
git clean -dxf git clean -dxff
fi
if [[ -e .gitmodules ]]; then if [[ -e .gitmodules ]]; then
if [[ $gituser == "anonymous" ]]; then if [[ $gituser == "anonymous" ]]; then
@ -38,9 +54,7 @@ if [[ -e .gitmodules ]]; then
git submodule init git submodule init
git submodule update git submodule update
git submodule foreach "git checkout master" git submodule foreach "git checkout $branch && $THISSCRIPT $gituser"
git submodule foreach "git pull"
git submodule foreach "$THISSCRIPT $gituser"
git checkout -- .gitmodules git checkout -- .gitmodules
fi fi

@ -6,17 +6,28 @@ if [[ -e /var/lock/update-tde-git-submodules ]]; then
exit 0 exit 0
fi 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 touch /var/lock/update-tde-git-submodules
PARENTDIR=$PWD PARENTDIR=$PWD
echo "Working in $PARENTDIR" echo "Working in $PARENTDIR"
if [[ ! -d .git ]]; then
echo "Current directory does not contain a .git folder. Exiting..."
exit 1
fi
git pull git pull
if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
git reset --hard HEAD git reset --hard HEAD
git clean -d -x -f git clean -dxff
fi
exec 3< submodules exec 3< submodules
while read <&3 while read <&3
@ -26,25 +37,29 @@ do
if [[ $DIR2UPDATE != "" ]]; then if [[ $DIR2UPDATE != "" ]]; then
echo "Attempting to reset submodule $DIR2UPDATE" echo "Attempting to reset submodule $DIR2UPDATE"
cd $PARENTDIR/$DIR2UPDATE/.. cd $PARENTDIR/$DIR2UPDATE/..
while [[ ! -d .git ]]; do cd `git rev-parse --show-toplevel`
cd ../ if [[ -z "`grep \"^Updated: $PWD$\" /var/lock/update-tde-git-submodules`" ]]; then
done echo "Updated: $PWD" >>/var/lock/update-tde-git-submodules
git submodule init git submodule init
git submodule update git submodule update
fi
cd $PARENTDIR/$DIR2UPDATE cd $PARENTDIR/$DIR2UPDATE
if [[ ! -z "`git status --porcelain --ignore-submodules`" ]]; then
git reset --hard HEAD git reset --hard HEAD
git clean -d -x -f git clean -dxff
git checkout master fi
git checkout $branch
git pull git pull
cd .. cd ..
while [[ ! -d .git ]]; do cd `git rev-parse --show-toplevel`
cd ../
done
echo "Committing changes to $PWD" echo "Committing changes to $PWD"
# git commit -a -m "Reset submodule to latest HEAD" if [[ ! -z "`git status --porcelain $PARENTDIR/$DIR2UPDATE`" ]]; then
git add $PARENTDIR/$DIR2UPDATE git add $PARENTDIR/$DIR2UPDATE
git commit $PARENTDIR/$DIR2UPDATE -m "Reset submodule $DIR2UPDATE to latest HEAD" git commit $PARENTDIR/$DIR2UPDATE -m "Reset submodule $DIR2UPDATE to latest HEAD"
git push origin master fi
if [[ "`git rev-parse HEAD`" != "`git rev-parse origin/$branch`" ]]; then
git push origin HEAD
fi
fi fi
done done
exec 3>&- exec 3>&-

Loading…
Cancel
Save