Commit | Line | Data |
---|---|---|
5a30e78c YD |
1 | #!/bin/sh |
2 | set -e | |
3 | ||
4 | # stg-dispatch - percollates files matching a pattern down to another patch. | |
5 | # It does the same job as stg-fold-files-from (and makes use of it to | |
6 | # do so), but from the patch containing the changes to migrate, | |
7 | # instead of doing so from the target patch. | |
8 | ||
cbb3c553 | 9 | # usage: stg-dispatch [-n] <topatch> [-#<n>[-<n>][,<n>]...] <file-pattern> |
5a30e78c YD |
10 | |
11 | # Copyright (c) 2007 Yann Dirson <ydirson@altern.org> | |
12 | # Subject to the GNU GPL, version 2. | |
13 | ||
14 | die() | |
15 | { | |
16 | echo >&2 "$(basename $0) error: $*" | |
17 | exit 1 | |
18 | } | |
19 | ||
cbb3c553 YD |
20 | noact=0 |
21 | if [ "x$1" = "x-n" ]; then | |
22 | noact=1 | |
23 | shift | |
24 | fi | |
25 | ||
5a30e78c YD |
26 | TOPATCH="$1" |
27 | shift | |
28 | ||
29 | stg applied | grep "^$TOPATCH\$" >/dev/null || | |
30 | die "cannot dispatch to unapplied patch '$TOPATCH'" | |
31 | ||
32 | CURRENTPATCH=$(stg top) | |
33 | ||
34 | [ "x$TOPATCH" != "x$CURRENTPATCH" ] || | |
35 | die "dispatching to current patch ($CURRENTPATCH) makes no sense" | |
36 | ||
cbb3c553 YD |
37 | if [ $noact = 1 ]; then |
38 | stg-fold-files-from "$CURRENTPATCH" -n "$@" | |
39 | else | |
40 | stg goto "$TOPATCH" | |
41 | stg-fold-files-from "$CURRENTPATCH" "$@" | |
42 | stg refresh | |
43 | stg goto "$CURRENTPATCH" | |
44 | fi |