purge-stale-projects.sh: Implemented support for git in checking status

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2016-09-22 09:24:15 +00:00
commit 1b071fbe8e

View file

@ -13,7 +13,32 @@ fatal()
goodbye() goodbye()
{ {
rm -f $cvs_status rm -f $scm_status
}
check_scm()
{
local p=$1
if [ -d $p/.git ]; then
log + checking git
git -C $p pull --no-edit || fatal "git pull failed, giving up"
git -C $p status --porcelain | grep -v '^??' | grep -q . && {
git -C $p status
fatal "git in project \"$p\" has locally modified files, giving up"
}
else
log + checking cvs
cvs update -dP $p
cvs status $p > $scm_status 2>&1
if [ $? != 0 ]; then
cat $scm_status
fatal "\n======== cvs status failed in project \"$p\", giving up."
fi
grep -qi "locally modified" $scm_status && \
fatal "cvs copy in project \"$p\" has locally modified files, giving up"
grep -qi "needs" $scm_status && \
fatal "+ cvs copy in project \"$p\" is out-of-date, giving up"
fi
} }
local_cvs_proj=`ls -d */CVS 2>/dev/null | sed 's%/[^/]*%%'` local_cvs_proj=`ls -d */CVS 2>/dev/null | sed 's%/[^/]*%%'`
@ -25,7 +50,7 @@ date=`date +'%Y%m%d'`
myname=`basename $0` myname=`basename $0`
trap goodbye EXIT INT QUIT KILL trap goodbye EXIT INT QUIT KILL
cvs_status=`mktemp /tmp/$myname""_XXXXXX` scm_status=`mktemp /tmp/$myname""_XXXXXX`
for p in $local_cvs_proj; do for p in $local_cvs_proj; do
[ -L $p ] && continue [ -L $p ] && continue
@ -52,16 +77,10 @@ for p in $local_git_proj; do
[ -L $p ] && continue [ -L $p ] && continue
[ -d $p ] || continue [ -d $p ] || continue
echo $remote_git_proj | grep -q "\(^\| \)$p\($\| \)" && continue echo $remote_git_proj | grep -q "\(^\| \)$p\($\| \)" && continue
cvs status $p > $cvs_status 2>&1 check_scm $p
if [ $? != 0 ]; then
cat $cvs_status
fatal "\n======== cvs status failed in project $p, giving up."
fi
grep -qi "project $p has locally modified" $cvs_status && \
fatal "cvs copy has locally modified files, giving up"
n=purged/git/$date/$p n=purged/git/$date/$p
mkdir -p `dirname $n` mkdir -p `dirname $n`
mv $p $n mv $p $n
log "moving stale CVS project \"$p\" to \"$n\"" log "moving stale project \"$p\" to \"$n\""
done done