chiark / gitweb /
new upstream release topgit-0.7
[topgit.git] / tg-mail.sh
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # GPLv2
4
5 name=
6 send_email_args=
7 in_reply_to=
8
9
10 ## Parse options
11
12 while [ -n "$1" ]; do
13         arg="$1"; shift
14         case "$arg" in
15         -s)
16                 send_email_args="$1"; shift;;
17         -r)
18                 in_reply_to="$1"; shift;;
19         -*)
20                 echo "Usage: tg [...] mail [-s SEND_EMAIL_ARGS] [-r REFERENCE_MSGID] [NAME]" >&2
21                 exit 1;;
22         *)
23                 [ -z "$name" ] || die "name already specified ($name)"
24                 name="$arg";;
25         esac
26 done
27
28 [ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
29 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
30         die "not a TopGit-controlled branch"
31
32 if ! git send-email --help >/dev/null 2>&1; then
33         die "git send-email command not available"
34 fi
35
36 if [ -n "$in_reply_to" ]; then
37         send_email_args="$send_email_args --in-reply-to=$in_reply_to"
38 fi
39
40
41 patchfile="$(mktemp -t tg-mail.XXXXXX)"
42
43 $tg patch "$name" >"$patchfile"
44
45 header="$(sed -e '/^$/,$d' "$patchfile")"
46
47
48
49 from="$(echo "$header" | grep '^From:' | sed 's/From:\s*//')"
50 to="$(echo "$header" | grep '^To:' | sed 's/To:\s*//')"
51
52
53 people=
54 [ -n "$from" ] && people="$people --from '$from'"
55 # FIXME: there could be multimple To
56 [ -n "$to" ] && people="$people --to '$to'"
57
58 # NOTE: git-send-email handles cc itself
59 eval git send-email $send_email_args "$people" "$patchfile"
60
61 rm "$patchfile"
62
63 # vim:noet