pgit.sh: Add iteration counter to logging

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2018-10-23 11:45:10 +00:00
commit fb7df55e6f

View file

@ -18,12 +18,12 @@ fatal()
marker() marker()
{ {
log "# ------------- $@" log "# ------------- [$cur/$n_projects] $@"
} }
fat_marker() fat_marker()
{ {
log "# ==================================================== $@" log "# ==================================================== [$cur/$n_projects] $@"
} }
config() config()
@ -40,6 +40,7 @@ config()
[ "$pdirs" ] || { [ "$pdirs" ] || {
pdirs=`(cd $pdir; ls -d */.git 2>/dev/null | sed 's%/.git%%')` pdirs=`(cd $pdir; ls -d */.git 2>/dev/null | sed 's%/.git%%')`
} }
n_projects=`echo $pdirs | wc -w`
} }
run_git() run_git()
@ -69,6 +70,7 @@ run()
if [ "$PGIT_KEEP_GOING" != y ]; then set -e; fi if [ "$PGIT_KEEP_GOING" != y ]; then set -e; fi
for d in $pdirs; do for d in $pdirs; do
cur=`expr $cur + 1`
run_git -C $d $cmd "$@" run_git -C $d $cmd "$@"
done done
)} )}
@ -87,6 +89,7 @@ commit()
if [ "$PGIT_KEEP_GOING" != y ]; then set -e; fi if [ "$PGIT_KEEP_GOING" != y ]; then set -e; fi
for d in $pdirs; do for d in $pdirs; do
cur=`expr $cur + 1`
if run_git -C $d diff --quiet; then if run_git -C $d diff --quiet; then
log "Nothing to commit" log "Nothing to commit"
continue continue
@ -109,21 +112,23 @@ clone()
local projects="$PGIT_CLONE_PROJECTS" local projects="$PGIT_CLONE_PROJECTS"
[ "$login" ] || login=`whoami` [ "$login" ] || login=`whoami`
[ "$fromuser" ] || fromuser=`whoami` [ "$fromuser" ] || fromuser=`whoami`
local git_srv_admin="$SSH $login@git.jannet.de /opt/jw-build/bin/git-srv-admin.sh" local git_srv_admin="$SSH $login@git.janware.com /opt/jw-build/bin/git-srv-admin.sh"
if [ -z "$projects" ]; then if [ -z "$projects" ]; then
projects=`$git_srv_admin -u $fromuser -j list-personal-projects` projects=`$git_srv_admin -u $fromuser -j list-personal-projects`
[ "$?" != 0 ] && exit 1 [ "$?" != 0 ] && exit 1
fi fi
n_projects=`echo $projects | wc -w`
set -e set -e
for p in $projects; do for p in $projects; do
local pullurl=ssh://$login@git.jannet.de/srv/git/$fromuser/proj/$p cur=`expr $cur + 1`
local pushurl=ssh://$login@git.jannet.de/srv/git/$login/proj/$p local pullurl=ssh://$login@git.janware.com/srv/git/$fromuser/proj/$p
local pushurl=ssh://$login@git.janware.com/srv/git/$login/proj/$p
fat_marker "Fetching project $p from user $fromuser" fat_marker "Fetching project $p from user $fromuser"
if [ "$fromuser" = "$login" ]; then if [ "$fromuser" = "$login" ]; then
if [ -d $p ]; then if [ -d $p ]; then
run_git -C $p pull run_git -C $p pull
else else
run_git clone ssh://$login@git.jannet.de/srv/git/$fromuser/proj/$p run_git clone ssh://$login@git.janware.com/srv/git/$fromuser/proj/$p
fi fi
run_git -C $p submodule init || fatal git submodule init failed in $p run_git -C $p submodule init || fatal git submodule init failed in $p
run_git -C $p submodule update || fatal git submodule update failed in $p run_git -C $p submodule update || fatal git submodule update failed in $p
@ -137,7 +142,7 @@ clone()
run_git -C $p pull $remotename master run_git -C $p pull $remotename master
else else
# set -x # set -x
run_git clone ssh://$login@git.jannet.de/srv/git/$fromuser/proj/$p run_git clone ssh://$login@git.janware.com/srv/git/$fromuser/proj/$p
run_git -C $p remote rename origin $remotename || fatal failed to rename remote in $p run_git -C $p remote rename origin $remotename || fatal failed to rename remote in $p
run_git -C $p remote set-url --push $remotename no_push run_git -C $p remote set-url --push $remotename no_push
$git_srv_admin -u $login -j create-personal-project $p $git_srv_admin -u $login -j create-personal-project $p
@ -158,15 +163,19 @@ diff()
config config
cd $pdir cd $pdir
for d in $pdirs; do for d in $pdirs; do
cur=`expr $cur + 1`
# marker $d # marker $d
run_git -C $d diff --src-prefix=$d/ --dst-prefix=$d/ "$@" run_git -C $d diff --src-prefix=$d/ --dst-prefix=$d/ "$@"
done done
)} )}
echo "running $0 $@ GIT_SSH=$GIT_SSH" >&2
SSH=ssh SSH=ssh
[ "$GIT_SSH" ] && SSH=$GIT_SSH [ "$GIT_SSH" ] && SSH=$GIT_SSH
cmd=$1 cmd=$1
cur=0
shift shift
case $cmd in case $cmd in
clone|diff|commit) clone|diff|commit)
@ -176,4 +185,3 @@ case $cmd in
run $cmd "$@" run $cmd "$@"
;; ;;
esac esac