]>
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 | |
60f5d754 ER |
9 | topdir="${1:-$(rpm -E %_topdir)}" |
10 | topdir=$(readlink -f "$topdir") | |
053ce154 ER |
11 | purgedir=$topdir/purged |
12 | cd "$topdir" | |
13 | ||
8ccb0f4c ER |
14 | echo "Purging in $topdir, press ENTER to continue" |
15 | read a | |
16 | ||
053ce154 ER |
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" | |
f2961643 KK |
26 | purge='yes' |
27 | ||
7bf3bf31 | 28 | status=$(git status --porcelain) |
2bfd8fcc | 29 | stash=$(git stash list) |
053ce154 ER |
30 | |
31 | # FIXME: does not currently handle if some pushes are not made! | |
2bfd8fcc | 32 | if [ -n "$status" ] || [ -n "$stash" ]; then |
053ce154 | 33 | cat <<-EOF |
25e20df5 | 34 | * Package $pkg - Untracked files or stash not empty. |
053ce154 ER |
35 | $status |
36 | EOF | |
f2961643 | 37 | purge='no' |
7a68fdcd | 38 | [ "$CALL_GC" != 'no' ] && git gc |
f2961643 KK |
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 | |
053ce154 ER |
55 | cat <<-EOF |
56 | * Package $pkg - State clean. Removing | |
57 | EOF | |
58 | mv ../$pkg $purgedir | |
f2961643 | 59 | fi } |
053ce154 ER |
60 | cd .. |
61 | done | |
a2ade87c ER |
62 | |
63 | rmdir --ignore-fail-on-non-empty $purgedir | |
2f3a7f8c KK |
64 | |
65 | # vi:syntax=sh:ts=4:sw=4:noet |