2 # Purges packages/ checkouts
3 # - if package has clean state, the dir is cleaned up (moved to purge dir)
4 # - otherwise git gc is called if CALL_GC=yes
9 topdir="${1:-$(rpm -E %_topdir)}"
10 topdir=$(readlink -f "$topdir")
11 purgedir=$topdir/purged
14 echo "Purging in $topdir, press ENTER to continue"
17 if [ -d "$purgedir" ]; then
18 echo >&2 "Previous pruge dir exists: $purgedir, remove it to resume"
28 status=$(git status --porcelain)
29 stash=$(git stash list)
31 # FIXME: does not currently handle if some pushes are not made!
32 if [ -n "$status" ] || [ -n "$stash" ]; then
34 * Package $pkg - Untracked files or stash not empty.
38 [ "$CALL_GC" != 'no' ] && git gc
40 git show-ref --heads |\
41 { while read sha1 branch; do
42 short_branch=${branch#refs/heads/}
43 if ! upstream=$(git rev-parse -q --verify $short_branch@{u}) 2>/dev/null; then
44 echo "* Package $pkg - Branch $short_branch has not defined upstream"
48 if [ -n "$(git rev-list "$upstream..$branch")" ]; then
49 echo "* Package $pkg - Branch $short_branch is not fully merged to its upstream"
54 if [ "$purge" = 'yes' ]; then
56 * Package $pkg - State clean. Purging
63 rmdir --ignore-fail-on-non-empty $purgedir
65 # vi:syntax=sh:ts=4:sw=4:noet