]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - purge-packages.sh
Merge changes in purge-packages.sh
[packages/rpm-build-tools.git] / purge-packages.sh
1 #!/bin/sh
2 # Purges packages/ checkouts
3 # - if package has clean state, the dir is removed
4 # - otherwise git gc is called
5 set -e
6
7 CALL_GC=${CALL_GC:-'no'}
8
9 topdir=$(rpm -E %_topdir)
10 purgedir=$topdir/purged
11 cd "$topdir"
12
13 if [ -d "$purgedir" ]; then
14         echo >&2 "Previous pruge dir exists: $purgedir, remove it to resume"
15         exit 1
16 fi
17
18 install -d $purgedir
19 for pkg in */.git; do
20         pkg=${pkg%/.git}
21         cd "$pkg"
22         purge='yes'
23
24         status=$(git status --porcelain)
25         stash=$(git stash list)
26
27         # FIXME: does not currently handle if some pushes are not made!
28         if [ -n "$status" ] || [ -n "$stash" ]; then
29                 cat <<-EOF
30                 * Package $pkg - Untracked files or stash not empty.
31                 $status
32                 EOF
33                 purge='no'
34                 [ "$CALL_GC" != 'no' ] && git gc
35         fi
36         git show-ref --heads |\
37         { while read sha1 branch; do
38                 short_branch=${branch#refs/heads/}
39                 if ! upstream=$(git rev-parse -q --verify $short_branch@{u}) 2>/dev/null; then
40                         echo "* Package $pkg - Branch $short_branch has not defined upstream"
41                         purge='no'
42                         continue
43                 fi
44                 if [ -n "$(git rev-list "$upstream..$branch")" ]; then
45                         echo "* Package $pkg - Branch $short_branch is not fully merged to its upstream"
46                         purge='no'
47                         continue
48                 fi
49         done
50         if [ "$purge" = 'yes' ]; then
51                 cat <<-EOF
52                 * Package $pkg - State clean. Removing
53                 EOF
54                 mv ../$pkg $purgedir
55         fi }
56         cd ..
57 done
58
59 rmdir --ignore-fail-on-non-empty $purgedir
60
61 # vi:syntax=sh:ts=4:sw=4:noet
This page took 0.035836 seconds and 4 git commands to generate.