# GPLv2
name=
+send_email_args=
+in_reply_to=
## Parse options
while [ -n "$1" ]; do
arg="$1"; shift
case "$arg" in
+ -s)
+ send_email_args="$1"; shift;;
+ -r)
+ in_reply_to="$1"; shift;;
-*)
- echo "Usage: tg [...] mail [NAME]" >&2
+ echo "Usage: tg [...] mail [-s SEND_EMAIL_ARGS] [-r REFERENCE_MSGID] [NAME]" >&2
exit 1;;
*)
[ -z "$name" ] || die "name already specified ($name)"
base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
die "not a TopGit-controlled branch"
+if [ -n "$in_reply_to" ]; then
+ send_email_args="$send_email_args --in-reply-to=$in_reply_to"
+fi
+
patchfile="$(mktemp -t tg-mail.XXXXXX)"
-$tg patch $name >"$patchfile"
+$tg patch "$name" >"$patchfile"
-hlines=$(grep -n -m 1 '^---' "$patchfile" | sed 's/:---//')
-header=$(head -n $(($hlines - 1)) "$patchfile")
+header="$(sed -e '/^$/,$d' "$patchfile")"
to="$(echo "$header" | grep '^To:' | sed 's/To:\s*//')"
-# XXX I can't get quoting right without arrays
-[ -n "$from" ] && from=(--from "$from")
-[ -n "$to" ] && to=(--to "$to") # FIXME there could be multimple To
-
-people=()
-[ -n "$from" ] && people=("${people[@]}" "${from[@]}")
-[ -n "$to" ] && people=("${people[@]}" "${to[@]}")
-
+people=
+[ -n "$from" ] && people="$people --from '$from'"
+# FIXME: there could be multimple To
+[ -n "$to" ] && people="$people --to '$to'"
-# NOTE git-send-email handles cc itself
-git send-email "${people[@]}" "$patchfile"
+# NOTE: git-send-email handles cc itself
+eval git send-email $send_email_args "$people" "$patchfile"
rm "$patchfile"