hooks/pre-commit: check for deps repetitions
[topgit/greenrd.git] / tg-mail.sh
blob8167adecb7421d6750205bd9304243f587a2e4d4
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # GPLv2
5 name=
6 send_email_args=
7 in_reply_to=
10 ## Parse options
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;;
23 [ -z "$name" ] || die "name already specified ($name)"
24 name="$arg";;
25 esac
26 done
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"
32 if [ -n "$in_reply_to" ]; then
33 send_email_args="$send_email_args --in-reply-to='$in_reply_to'"
37 patchfile="$(mktemp -t tg-mail.XXXXXX)"
39 $tg patch "$name" >"$patchfile"
41 header="$(sed -e '/^$/,$d' -e "s,','\\\\'',g" "$patchfile")"
45 from="$(echo "$header" | grep '^From:' | sed 's/From:\s*//')"
46 to="$(echo "$header" | grep '^To:' | sed 's/To:\s*//')"
49 people=
50 [ -n "$from" ] && people="$people --from '$from'"
51 # FIXME: there could be multimple To
52 [ -n "$to" ] && people="$people --to '$to'"
54 # NOTE: git-send-email handles cc itself
55 eval git send-email $send_email_args "$people" "$patchfile"
57 rm "$patchfile"
59 # vim:noet