]>
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 | ||
8ccb0f4c ER |
13 | echo "Purging in $topdir, press ENTER to continue" |
14 | read a | |
15 | ||
053ce154 ER |
16 | if [ -d "$purgedir" ]; then |
17 | echo >&2 "Previous pruge dir exists: $purgedir, remove it to resume" | |
18 | exit 1 | |
19 | fi | |
20 | ||
21 | install -d $purgedir | |
22 | for pkg in */.git; do | |
23 | pkg=${pkg%/.git} | |
24 | cd "$pkg" | |
f2961643 KK |
25 | purge='yes' |
26 | ||
7bf3bf31 | 27 | status=$(git status --porcelain) |
2bfd8fcc | 28 | stash=$(git stash list) |
053ce154 ER |
29 | |
30 | # FIXME: does not currently handle if some pushes are not made! | |
2bfd8fcc | 31 | if [ -n "$status" ] || [ -n "$stash" ]; then |
053ce154 | 32 | cat <<-EOF |
25e20df5 | 33 | * Package $pkg - Untracked files or stash not empty. |
053ce154 ER |
34 | $status |
35 | EOF | |
f2961643 | 36 | purge='no' |
7a68fdcd | 37 | [ "$CALL_GC" != 'no' ] && git gc |
f2961643 KK |
38 | fi |
39 | git show-ref --heads |\ | |
40 | { while read sha1 branch; do | |
41 | short_branch=${branch#refs/heads/} | |
42 | if ! upstream=$(git rev-parse -q --verify $short_branch@{u}) 2>/dev/null; then | |
43 | echo "* Package $pkg - Branch $short_branch has not defined upstream" | |
44 | purge='no' | |
45 | continue | |
46 | fi | |
47 | if [ -n "$(git rev-list "$upstream..$branch")" ]; then | |
48 | echo "* Package $pkg - Branch $short_branch is not fully merged to its upstream" | |
49 | purge='no' | |
50 | continue | |
51 | fi | |
52 | done | |
53 | if [ "$purge" = 'yes' ]; then | |
053ce154 ER |
54 | cat <<-EOF |
55 | * Package $pkg - State clean. Removing | |
56 | EOF | |
57 | mv ../$pkg $purgedir | |
f2961643 | 58 | fi } |
053ce154 ER |
59 | cd .. |
60 | done | |
a2ade87c ER |
61 | |
62 | rmdir --ignore-fail-on-non-empty $purgedir | |
2f3a7f8c KK |
63 | |
64 | # vi:syntax=sh:ts=4:sw=4:noet |