tg.sh: make "tg help st" work
[topgit/pro.git] / tg-mail.sh
blob195156fcf187e40a3dfed3aa07f609b021b441e3
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # GPLv2
5 name=
6 head_from=
7 send_email_args=
8 in_reply_to=
11 ## Parse options
13 while [ -n "$1" ]; do
14 arg="$1"; shift
15 case "$arg" in
16 -i|-w)
17 [ -z "$head_from" ] || die "-i and -w are mutually exclusive"
18 head_from="$arg";;
19 -s)
20 send_email_args="$1"; shift;;
21 -r)
22 in_reply_to="$1"; shift;;
23 -*)
24 echo "Usage: ${tgname:-tg} [...] mail [-s <send-email-args>] [-r <reference-msgid>] [-i | -w] [<name>]" >&2
25 exit 1;;
27 [ -z "$name" ] || die "name already specified ($name)"
28 name="$arg";;
29 esac
30 done
32 name="$(verify_topgit_branch "${name:-HEAD}")"
33 base_rev="$(git rev-parse --short --verify "refs/$topbases/$name^0" -- 2>/dev/null)" ||
34 die "not a TopGit-controlled branch"
36 if [ -n "$in_reply_to" ]; then
37 send_email_args="$send_email_args --in-reply-to='$in_reply_to'"
41 patchfile="$(get_temp tg-mail)"
43 [ -z "$head_from" ] || ensure_work_tree
45 # let tg patch sort out whether $head_from makes sense for $name
46 tg patch "$name" $head_from >"$patchfile"
48 header="$(sed -e '/^$/,$d' -e "s,','\\\\'',g" "$patchfile")"
51 from="$(echol "$header" | grep '^From:' | sed 's/From:\s*//')"
52 to="$(echol "$header" | grep '^To:' | sed 's/To:\s*//')"
55 people=
56 [ -n "$from" ] && people="$people --from '$from'"
57 # FIXME: there could be multiple To
58 [ -n "$to" ] && people="$people --to '$to'"
60 # NOTE: git-send-email handles cc itself
61 eval git send-email $send_email_args "$people" "$patchfile"
63 # vim:noet