X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=tg-mail.sh;h=17ce02c9f4a904724d802a825e42a22c2aa61a62;hb=refs%2Fheads%2Ffixes%2Fensure-worktree;hp=f3abd2c0285493e748fd9809e0cb921b985dccc9;hpb=2986273479a7303a5b21c238182e1df51be2b3eb;p=topgit.git diff --git a/tg-mail.sh b/tg-mail.sh index f3abd2c..17ce02c 100644 --- a/tg-mail.sh +++ b/tg-mail.sh @@ -3,6 +3,9 @@ # GPLv2 name= +head_from= +send_email_args= +in_reply_to= ## Parse options @@ -10,8 +13,15 @@ name= while [ -n "$1" ]; do arg="$1"; shift case "$arg" in + -i|-w) + [ -z "$head_from" ] || die "-i and -w are mutually exclusive" + head_from="$arg";; + -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] [-i | -w] [NAME]" >&2 exit 1;; *) [ -z "$name" ] || die "name already specified ($name)" @@ -19,18 +29,22 @@ while [ -n "$1" ]; do esac done -# TODO refactor me into something common? -[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')" +head="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')" +[ -n "$name" ] || name="$head" 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" +patchfile="$(get_temp tg-mail)" -hlines=$(grep -n -m 1 '^---' "$patchfile" | sed 's/:---//') -header=$(head -$(($hlines - 1)) "$patchfile") +# let tg patch sort out whether $head_from makes sense for $name +$tg patch "$name" $head_from >"$patchfile" + +header="$(sed -e '/^$/,$d' -e "s,','\\\\'',g" "$patchfile")" @@ -38,16 +52,12 @@ from="$(echo "$header" | grep '^From:' | sed 's/From:\s*//')" 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" +# vim:noet