2 # Purges packages/ checkouts
4 # - if package has clean state, the dir is cleaned up (moved to purge dir)
5 # - otherwise git gc is called if CALL_GC=yes
6 # Stashes aside packages/ that do not have .git dir
7 # - these dirs are usually created by rpmbuild if Name does not match .spec file
11 CALL_GC=${CALL_GC:-no}
13 topdir="${1:-$(rpm -E %_topdir)}"
14 topdir=$(readlink -f "$topdir")
15 purgedir=$topdir/purged
16 stashdir=$topdir/stashed
19 echo "Purging in $topdir, press ENTER to continue"
22 if [ -d "$purgedir" ]; then
23 echo >&2 "Previous pruge dir exists: $purgedir, remove it to continue"
34 status=$(git status --porcelain)
35 stash=$(git stash list)
37 # FIXME: does not currently handle if some pushes are not made!
38 if [ -n "$status" ] || [ -n "$stash" ]; then
40 * Package $pkg - Untracked files or stash not empty.
44 [ "$CALL_GC" != 'no' ] && git gc
46 git show-ref --heads |\
47 { while read sha1 branch; do
48 short_branch=${branch#refs/heads/}
49 if ! upstream=$(git rev-parse -q --verify $short_branch@{u}) 2>/dev/null; then
50 echo "* Package $pkg - Branch $short_branch has not defined upstream"
54 if [ -n "$(git rev-list "$upstream..$branch")" ]; then
55 echo "* Package $pkg - Branch $short_branch is not fully merged to its upstream"
60 if [ "$purge" = 'yes' ]; then
62 * Package $pkg - State clean. Purging
69 rmdir --ignore-fail-on-non-empty $purgedir
71 # go over packages that do not have .git
72 if [ -d "$stashdir" ]; then
73 echo >&2 "Previous stash dir exists: $stashdir, remove it to continue"
77 stashdir=$(readlink -f $stashdir)
80 test -L "${pkg%/}" && continue
81 # skip packages which do have .git
82 test -d "$pkg/.git" && continue
83 # skip if it's the stash dir itself
84 pkg=$(readlink -f $pkg)
85 test "$pkg" = "$stashdir" && continue
87 echo "* Package $pkg does not have .git, stashing"
90 rmdir --ignore-fail-on-non-empty $stashdir
92 # vi:syntax=sh:ts=4:sw=4:noet