]>
Commit | Line | Data |
---|---|---|
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="${1:-$(rpm -E %_topdir)}" | |
10 | topdir=$(readlink -f "$topdir") | |
11 | purgedir=$topdir/purged | |
12 | cd "$topdir" | |
13 | ||
14 | echo "Purging in $topdir, press ENTER to continue" | |
15 | read a | |
16 | ||
17 | if [ -d "$purgedir" ]; then | |
18 | echo >&2 "Previous pruge dir exists: $purgedir, remove it to resume" | |
19 | exit 1 | |
20 | fi | |
21 | ||
22 | install -d $purgedir | |
23 | for pkg in */.git; do | |
24 | pkg=${pkg%/.git} | |
25 | cd "$pkg" | |
26 | purge='yes' | |
27 | ||
28 | status=$(git status --porcelain) | |
29 | stash=$(git stash list) | |
30 | ||
31 | # FIXME: does not currently handle if some pushes are not made! | |
32 | if [ -n "$status" ] || [ -n "$stash" ]; then | |
33 | cat <<-EOF | |
34 | * Package $pkg - Untracked files or stash not empty. | |
35 | $status | |
36 | EOF | |
37 | purge='no' | |
38 | [ "$CALL_GC" != 'no' ] && git gc | |
39 | fi | |
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" | |
45 | purge='no' | |
46 | continue | |
47 | fi | |
48 | if [ -n "$(git rev-list "$upstream..$branch")" ]; then | |
49 | echo "* Package $pkg - Branch $short_branch is not fully merged to its upstream" | |
50 | purge='no' | |
51 | continue | |
52 | fi | |
53 | done | |
54 | if [ "$purge" = 'yes' ]; then | |
55 | cat <<-EOF | |
56 | * Package $pkg - State clean. Removing | |
57 | EOF | |
58 | mv ../$pkg $purgedir | |
59 | fi } | |
60 | cd .. | |
61 | done | |
62 | ||
63 | rmdir --ignore-fail-on-non-empty $purgedir | |
64 | ||
65 | # vi:syntax=sh:ts=4:sw=4:noet |