2 # Purges packages/ checkouts
3 # - if package has clean state, the dir is removed
4 # - otherwise git gc is called
7 CALL_GC=${CALL_GC:-'no'}
9 topdir=$(rpm -E %_topdir)
10 purgedir=$topdir/purged
13 echo "Purging in $topdir, press ENTER to continue"
16 if [ -d "$purgedir" ]; then
17 echo >&2 "Previous pruge dir exists: $purgedir, remove it to resume"
27 status=$(git status --porcelain)
28 stash=$(git stash list)
30 # FIXME: does not currently handle if some pushes are not made!
31 if [ -n "$status" ] || [ -n "$stash" ]; then
33 * Package $pkg - Untracked files or stash not empty.
37 [ "$CALL_GC" != 'no' ] && git gc
39 git show-ref --heads |\
40 { while read sha1 branch; do
41 short_branch=${branch#refs/heads/}
42 if ! upstream=$(git rev-parse -q --verify $short_branch@{u}) 2>/dev/null; then
43 echo "* Package $pkg - Branch $short_branch has not defined upstream"
47 if [ -n "$(git rev-list "$upstream..$branch")" ]; then
48 echo "* Package $pkg - Branch $short_branch is not fully merged to its upstream"
53 if [ "$purge" = 'yes' ]; then
55 * Package $pkg - State clean. Removing
62 rmdir --ignore-fail-on-non-empty $purgedir
64 # vi:syntax=sh:ts=4:sw=4:noet