8911946e84486d8d28dd278b5dd090024ec73488
[stgit] / contrib / stg-dispatch
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
9 # usage: stg-dispatch <topatch> [-#<n>[-<n>][,<n>]...] <file-pattern>
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
20 TOPATCH="$1"
21 shift
22
23 stg applied | grep "^$TOPATCH\$" >/dev/null ||
24 die "cannot dispatch to unapplied patch '$TOPATCH'"
25
26 CURRENTPATCH=$(stg top)
27
28 [ "x$TOPATCH" != "x$CURRENTPATCH" ] ||
29 die "dispatching to current patch ($CURRENTPATCH) makes no sense"
30
31 stg goto "$TOPATCH"
32 stg-fold-files-from "$CURRENTPATCH" "$@"
33 stg refresh
34 stg goto "$CURRENTPATCH"