]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame_incremental - purge-packages.sh
on -j define __jobs instead of _smp_mflags
[packages/rpm-build-tools.git] / purge-packages.sh
... / ...
CommitLineData
1#!/bin/sh
2# Purges packages/ checkouts
3#
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
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
9set -e
10
11CALL_GC=${CALL_GC:-no}
12
13topdir="${1:-$(rpm -E %_topdir)}"
14topdir=$(readlink -f "$topdir")
15purgedir=$topdir/purged
16stashdir=$topdir/stashed
17cd "$topdir"
18
19echo "Purging in $topdir, press ENTER to continue"
20read a
21
22if [ -d "$purgedir" ]; then
23 echo >&2 "Previous pruge dir exists: $purgedir, remove it to continue"
24 exit 1
25fi
26
27install -d $purgedir
28for pkg in */.git; do
29 continue
30 pkg=${pkg%/.git}
31 cd "$pkg"
32 purge='yes'
33
34 status=$(git status --porcelain)
35 stash=$(git stash list)
36
37 # FIXME: does not currently handle if some pushes are not made!
38 if [ -n "$status" ] || [ -n "$stash" ]; then
39 cat <<-EOF
40 * Package $pkg - Untracked files or stash not empty.
41 $status
42 EOF
43 purge='no'
44 [ "$CALL_GC" != 'no' ] && git gc
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
61 cat <<-EOF
62 * Package $pkg - State clean. Purging
63 EOF
64 mv ../$pkg $purgedir
65 fi }
66 cd ..
67done
68
69rmdir --ignore-fail-on-non-empty $purgedir
70
71# go over packages that do not have .git
72if [ -d "$stashdir" ]; then
73 echo >&2 "Previous stash dir exists: $stashdir, remove it to continue"
74 exit 1
75fi
76install -d $stashdir
77stashdir=$(readlink -f $stashdir)
78for 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
89done
90rmdir --ignore-fail-on-non-empty $stashdir
91
92# vi:syntax=sh:ts=4:sw=4:noet
This page took 0.025406 seconds and 4 git commands to generate.