]>
Commit | Line | Data |
---|---|---|
053ce154 ER |
1 | #!/bin/sh |
2 | # Purges packages/ checkouts | |
8089559c | 3 | # |
de844fbf ER |
4 | # - if package has clean state, the dir is cleaned up (moved to purge dir) |
5 | # - otherwise git gc is called if CALL_GC=yes | |
8089559c ER |
6 | # Stashes aside packages/ that do not have .git dir |
7 | # - these dirs are usually created by rpmbuild if Name does not match .spec file | |
8 | ||
053ce154 ER |
9 | set -e |
10 | ||
de844fbf | 11 | CALL_GC=${CALL_GC:-no} |
25e20df5 | 12 | |
60f5d754 ER |
13 | topdir="${1:-$(rpm -E %_topdir)}" |
14 | topdir=$(readlink -f "$topdir") | |
053ce154 | 15 | purgedir=$topdir/purged |
8089559c | 16 | stashdir=$topdir/stashed |
053ce154 ER |
17 | cd "$topdir" |
18 | ||
8ccb0f4c ER |
19 | echo "Purging in $topdir, press ENTER to continue" |
20 | read a | |
21 | ||
053ce154 | 22 | if [ -d "$purgedir" ]; then |
8089559c | 23 | echo >&2 "Previous pruge dir exists: $purgedir, remove it to continue" |
053ce154 ER |
24 | exit 1 |
25 | fi | |
26 | ||
27 | install -d $purgedir | |
28 | for pkg in */.git; do | |
8089559c | 29 | continue |
053ce154 ER |
30 | pkg=${pkg%/.git} |
31 | cd "$pkg" | |
f2961643 KK |
32 | purge='yes' |
33 | ||
7bf3bf31 | 34 | status=$(git status --porcelain) |
2bfd8fcc | 35 | stash=$(git stash list) |
053ce154 ER |
36 | |
37 | # FIXME: does not currently handle if some pushes are not made! | |
2bfd8fcc | 38 | if [ -n "$status" ] || [ -n "$stash" ]; then |
053ce154 | 39 | cat <<-EOF |
25e20df5 | 40 | * Package $pkg - Untracked files or stash not empty. |
053ce154 ER |
41 | $status |
42 | EOF | |
f2961643 | 43 | purge='no' |
7a68fdcd | 44 | [ "$CALL_GC" != 'no' ] && git gc |
f2961643 KK |
45 | fi |
46 | git show-ref --heads |\ | |
47 | { while read sha1 branch; do | |
48 | short_branch=${branch#refs/heads/} | |
49 | if ! upstream=$(git rev-parse -q --verify $short_branch@{u}) 2>/dev/null; then | |
50 | echo "* Package $pkg - Branch $short_branch has not defined upstream" | |
51 | purge='no' | |
52 | continue | |
53 | fi | |
54 | if [ -n "$(git rev-list "$upstream..$branch")" ]; then | |
55 | echo "* Package $pkg - Branch $short_branch is not fully merged to its upstream" | |
56 | purge='no' | |
57 | continue | |
58 | fi | |
59 | done | |
60 | if [ "$purge" = 'yes' ]; then | |
053ce154 | 61 | cat <<-EOF |
de844fbf | 62 | * Package $pkg - State clean. Purging |
053ce154 ER |
63 | EOF |
64 | mv ../$pkg $purgedir | |
f2961643 | 65 | fi } |
053ce154 ER |
66 | cd .. |
67 | done | |
a2ade87c ER |
68 | |
69 | rmdir --ignore-fail-on-non-empty $purgedir | |
2f3a7f8c | 70 | |
8089559c ER |
71 | # go over packages that do not have .git |
72 | if [ -d "$stashdir" ]; then | |
73 | echo >&2 "Previous stash dir exists: $stashdir, remove it to continue" | |
74 | exit 1 | |
75 | fi | |
76 | install -d $stashdir | |
77 | stashdir=$(readlink -f $stashdir) | |
78 | for pkg in */; do | |
79 | # skip symlinks | |
80 | test -L "${pkg%/}" && continue | |
81 | # skip packages which do have .git | |
82 | test -d "$pkg/.git" && continue | |
83 | # skip if it's the stash dir itself | |
84 | pkg=$(readlink -f $pkg) | |
85 | test "$pkg" = "$stashdir" && continue | |
86 | ||
87 | echo "* Package $pkg does not have .git, stashing" | |
88 | mv $pkg $stashdir | |
89 | done | |
90 | rmdir --ignore-fail-on-non-empty $stashdir | |
91 | ||
2f3a7f8c | 92 | # vi:syntax=sh:ts=4:sw=4:noet |