]>
Commit | Line | Data |
---|---|---|
053ce154 ER |
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 | ||
7a68fdcd | 7 | CALL_GC=${CALL_GC:-'no'} |
25e20df5 | 8 | |
053ce154 ER |
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" | |
f2961643 KK |
22 | purge='yes' |
23 | ||
7bf3bf31 | 24 | status=$(git status --porcelain) |
2bfd8fcc | 25 | stash=$(git stash list) |
053ce154 ER |
26 | |
27 | # FIXME: does not currently handle if some pushes are not made! | |
2bfd8fcc | 28 | if [ -n "$status" ] || [ -n "$stash" ]; then |
053ce154 | 29 | cat <<-EOF |
25e20df5 | 30 | * Package $pkg - Untracked files or stash not empty. |
053ce154 ER |
31 | $status |
32 | EOF | |
f2961643 | 33 | purge='no' |
7a68fdcd | 34 | [ "$CALL_GC" != 'no' ] && git gc |
f2961643 KK |
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 | |
053ce154 ER |
51 | cat <<-EOF |
52 | * Package $pkg - State clean. Removing | |
53 | EOF | |
54 | mv ../$pkg $purgedir | |
f2961643 | 55 | fi } |
053ce154 ER |
56 | cd .. |
57 | done | |
a2ade87c ER |
58 | |
59 | rmdir --ignore-fail-on-non-empty $purgedir | |
2f3a7f8c KK |
60 | |
61 | # vi:syntax=sh:ts=4:sw=4:noet |