jw-pkg/scripts/pgit.sh
Jan Lindemann 6b1efdafa3 pgit.sh: Error out in more for-projects loops on error
Signed-off-by: Jan Lindemann <jan@janware.com>
2016-09-30 11:25:39 +00:00

100 lines
1.4 KiB
Bash

#!/bin/sh
log()
{
echo $@
}
err()
{
log $@
}
fatal()
{
err $@
exit 1
}
marker()
{
log "# ============= $@"
}
config()
{
# guess pdir
pdir=`pwd`
while [ `cat $pdir/CVS/Repository 2>/dev/null` != proj ]; do
[ "$pdir" = / ] && fatal "didn't find \"proj\" in directory components"
pdir=`dirname $pdir`
done
pdirs=`(cd $pdir; ls -d */.git | sed 's%/.git%%')`
}
# ------------- commands
run()
{(
local d
local cmd=$1
shift
config
cd $pdir
set -e
for d in $pdirs; do
marker $d
git -C $d $cmd "$@"
done
)}
clone()
{(
local p
config
cd $pdir
local id=$PGIT_CLONE_FROM_USER
local projects="$PGIT_CLONE_PROJECTS"
[ "$id" ] || id=`whoami`
if [ -z "$projects" ]; then
projects=`$SSH git.jannet.de /opt/ytools/bin/git-srv-admin.sh -u $id -j list-personal-projects`
[ "$?" != 0 ] && exit 1
fi
set -e
for p in $projects; do
[ -d $p ] && {
marker "skipping existing $p"
continue
}
marker "cloning $p"
git clone ssh://$id@git.jannet.de/srv/git/$id/proj/$p
git -C $p submodule init || fatal git submodule init failed in `pwd`
git -C $p submodule update || fatal git submodule update failed in `pwd`
done
)}
diff()
{(
local d
config
cd $pdir
for d in $pdirs; do
marker $d
git -C $d diff --src-prefix=a/$d/ --dst-prefix=b/$d/ "$@"
done
)}
SSH=ssh
[ "$GIT_SSH" ] && SSH=$GIT_SSH
cmd=$1
shift
case $cmd in
clone|diff)
$cmd "$@"
;;
*)
run $cmd "$@"
;;
esac