]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - purge-packages.sh
adapter: subst libappstream-glib, python-xlib
[packages/rpm-build-tools.git] / purge-packages.sh
index 520ae3b0b6c9ab173131b20051fa1924dd25e81a..d59bb803888df9ea7a6aa0b4f8b6aa70defc107a 100755 (executable)
@@ -4,10 +4,16 @@
 # - otherwise git gc is called
 set -e
 
-topdir=$(rpm -E %_topdir)
+CALL_GC=${CALL_GC:-'no'}
+
+topdir="${1:-$(rpm -E %_topdir)}"
+topdir=$(readlink -f "$topdir")
 purgedir=$topdir/purged
 cd "$topdir"
 
+echo "Purging in $topdir, press ENTER to continue"
+read a
+
 if [ -d "$purgedir" ]; then
        echo >&2 "Previous pruge dir exists: $purgedir, remove it to resume"
        exit 1
@@ -17,24 +23,43 @@ install -d $purgedir
 for pkg in */.git; do
        pkg=${pkg%/.git}
        cd "$pkg"
+       purge='yes'
+
        status=$(git status --porcelain)
        stash=$(git stash list)
 
        # FIXME: does not currently handle if some pushes are not made!
        if [ -n "$status" ] || [ -n "$stash" ]; then
                cat <<-EOF
-               * Package $pkg - Untracked files or stash not empty. Invoke gc
-
+               * Package $pkg - Untracked files or stash not empty.
                $status
                EOF
-               git gc
-       else
+               purge='no'
+               [ "$CALL_GC" != 'no' ] && git gc
+       fi
+       git show-ref --heads |\
+       { while read sha1 branch; do
+               short_branch=${branch#refs/heads/}
+               if ! upstream=$(git rev-parse -q --verify $short_branch@{u}) 2>/dev/null; then
+                       echo "* Package $pkg - Branch $short_branch has not defined upstream"
+                       purge='no'
+                       continue
+               fi
+               if [ -n "$(git rev-list "$upstream..$branch")" ]; then
+                       echo "* Package $pkg - Branch $short_branch is not fully merged to its upstream"
+                       purge='no'
+                       continue
+               fi
+       done
+       if [ "$purge" = 'yes' ]; then
                cat <<-EOF
                * Package $pkg - State clean. Removing
                EOF
                mv ../$pkg $purgedir
-       fi
+       fi }
        cd ..
 done
 
 rmdir --ignore-fail-on-non-empty $purgedir
+
+# vi:syntax=sh:ts=4:sw=4:noet
This page took 0.120216 seconds and 4 git commands to generate.