3 # Copyright (c) 2007 Andy Parkins
5 # An example hook script to mail out commit update information. This hook
6 # sends emails listing new revisions to the repository introduced by the
7 # change being reported. The rule is that (for branch updates) each commit
8 # will appear on one email and one email only.
11 # This is Girocco-customized version. No matter what is said below, it has
13 # * Calling with arguments is same as giving them on stdin.
14 # * Optional fourth parameter is project name, used at most places instead
16 # * Optional fifth parameter is email sender.
17 # * Optional sixth parameter is extra e-mail header to add.
18 # * If MAIL_SH_OTHER_BRANCHES is set it is taken as branch tips of already seen
19 # revisions when running show_new_revisions and mail.sh skips its own
20 # computation. If it starts with '@' the rest is the hash of a blob that
21 # contains the information (one tip per line).
22 # guess at what those are -- it's ignored if updates are piped in via stdin.
24 # * Default subject prefix is site name.
25 # * Unsubscribe instructions in email footer.
26 # * Default showrev includes gitweb link and show -C.
27 # * Nicer subject line.
28 # * Limit mail size to 256kb.
31 # This hook is stored in the contrib/hooks directory. Your distribution
32 # will have put this somewhere standard. You should make this script
33 # executable then link to it in the repository you would like to use it in.
34 # For example, on debian the hook is stored in
35 # /usr/share/git-core/contrib/hooks/post-receive-email:
37 # chmod a+x post-receive-email
38 # cd /path/to/your/repository.git
39 # ln -sf /usr/share/git-core/contrib/hooks/post-receive-email hooks/post-receive
41 # This hook script assumes it is enabled on the central repository of a
42 # project, with all users pushing only to it and not between each other. It
43 # will still work if you don't operate in that style, but it would become
44 # possible for the email to be from someone other than the person doing the
50 # This is the list that all pushes will go to; leave it blank to not send
51 # emails for every ref update.
53 # If true do not include the actual diff when showing new commits (the
54 # summary information will still be shown). Default is false.
56 # This is the list that all pushes of annotated tags will go to. Leave it
57 # blank to default to the mailinglist field. The announce emails lists
58 # the short log summary of the changes since the last annotated tag.
59 # hooks.envelopesender
60 # If set then the -f option is passed to sendmail to allow the envelope
61 # sender address to be set
63 # All emails have their subjects prefixed with this prefix, or "[SCM]"
64 # if emailprefix is unset, to aid filtering
66 # The shell command used to format each revision in the email, with
67 # "%s" replaced with the commit id. Defaults to "git rev-list -1
68 # --pretty %s", displaying the commit id, author, date and log
69 # message. To list full patches separated by a blank line, you
70 # could set this to "git show -C %s; echo".
71 # To list a gitweb/cgit URL *and* a full patch for each change set, use this:
72 # "t=%s; printf 'http://.../?id=%%s' \$t; echo;echo; git show -C \$t; echo"
73 # Be careful if "..." contains things that will be expanded by shell "eval"
78 # All emails include the headers "X-Git-Refname", "X-Git-Oldrev",
79 # "X-Git-Newrev", and "X-Git-Reftype" to enable fine tuned filtering and
80 # give information for debugging.
83 # ---------------------------- Functions
86 # Function to output arguments without interpretation followed by \n
94 # Function to read a tag's (the single argument) header fields into
95 # tagobject the "object" value
96 # tagtype the "type" value
97 # tagtag the "tag" value
98 # taggername from "tagger" value before first '<'
99 # taggerdate from "tagger" value after '>' but formatted into a date string
100 # taggeremail from "tagger" value between '<' and '>'
101 # On return all fields will be set (to empty if failure) and the three tagger
102 # fields will only be set to non-empty if a "tagger" header field is present.
103 # If the object does not exist or is not a tag the function returns failure.
112 if _tagfields
="$(git cat-file tag "$1" | LC_ALL=C awk -F '[ ]' '
113 function quotesh(sv) {
114 gsub(/'\''/, "'\'\\\\\'\''", sv)
115 return "'\''" sv "'\''"
118 sub(/^[ \t]+/, "", sv)
119 sub(/[ \t]+$/, "", sv)
123 sub(/^[^ ]* /, "", sv)
127 if ($1 == "object
") to=hval($0)
128 if ($1 == "type") ty=hval($0)
129 if ($1 == "tag
") tt=hval($0)
130 if ($1 == "tagger
") tr=hval($0)
133 if (tt == "" || to == "" || ty == "") exit 1
134 print "tagobject
=" quotesh(to)
135 print "tagtype
=" quotesh(ty)
136 print "tagtag
=" quotesh(tt)
137 if (match(tr, /^[ \t]*[^ \t<][^<]*/)) {
138 tn=substr(tr, RSTART, RLENGTH)
139 tr=substr(tr, RSTART + RLENGTH)
142 print "taggername
=" quotesh(tn)
143 if (match(tr, /^<.*>/)) {
145 te=substr(tr, RSTART+1, RLENGTH-2)
146 tr=substr(tr, RSTART + RLENGTH)
149 print "taggeremail
=" quotesh(te)
150 if (match(tr, /^[ \t]*[0-9]+([ \t]+[-+]?[0-9][0-9]([0-9][0-9]([0-9][0-9])?)?)[ \t]*$/))
153 print "taggerdate
=" quotesh(td)
159 [ -z "$taggerdate" ] || taggerdate
="$(strftime "$sdatefmt" $taggerdate)"
166 # Function to prepare for email generation. This decides what type
167 # of update this is and whether an email should even be generated.
172 oldrev
=$
(git rev-parse
--revs-only "$1" --)
173 newrev
=$
(git rev-parse
--revs-only "$2" --)
174 [ "$oldrev" != "$newrev" ] ||
return 1
175 scratch
="${newrev#????????????????}"
176 newrev16
="${newrev%$scratch}"
180 # 0000->1234 (create)
181 # 1234->2345 (update)
182 # 2345->0000 (delete)
183 if LC_ALL
=C
expr "$oldrev" : '0*$' >/dev
/null
187 if LC_ALL
=C
expr "$newrev" : '0*$' >/dev
/null
195 # --- Get the revision types
196 newrev_type
=$
(git cat-file
-t $newrev 2> /dev
/null
)
197 oldrev_type
=$
(git cat-file
-t "$oldrev" 2> /dev
/null
)
198 case "$change_type" in
201 rev_type
="$newrev_type"
205 rev_type
="$oldrev_type"
209 # The revision type tells us what type the commit is, combined with
210 # the location of the ref we can decide between
215 case "$refname","$rev_type" in
219 short_refname
=${refname##refs/tags/}
223 refname_type
="annotated tag"
224 short_refname
=${refname##refs/tags/}
226 if [ -n "$announcerecipients" ]; then
227 recipients
="$announcerecipients"
230 refs
/heads
/*,commit|refs
/heads
/*,tag
)
232 refname_type
="branch"
233 short_refname
=${refname##refs/heads/}
235 refs
/remotes
/*,commit
)
237 refname_type
="tracking branch"
238 short_refname
=${refname##refs/remotes/}
239 echol
>&2 "*** Push-update of tracking branch, $refname"
240 echol
>&2 "*** - no email generated."
243 refs
/mob
/*,commit|refs
/mob
/*,tag
)
245 refname_type
="personal mob ref"
246 short_refname
=${refname##refs/mob/}
247 echol
>&2 "*** Push-update of personal mob ref, $refname"
248 echol
>&2 "*** - no email generated."
252 # Anything else (is there anything else?)
253 echol
>&2 "*** Unknown type of update to $refname ($rev_type)"
254 echol
>&2 "*** - no email generated"
259 # Check if we've got anyone to send to
260 if [ -z "$recipients" ]; then
261 case "$refname_type" in
263 config_name
="hooks.announcelist"
266 config_name
="hooks.mailinglist"
269 echol
>&2 "*** $config_name is not set so no email will be sent"
270 echol
>&2 "*** for $refname update $oldrev->$newrev"
278 # Top level email generation function. This calls the appropriate
279 # body-generation routine after outputting the common header.
281 # Note this function doesn't actually generate any email output, that is
282 # taken care of by the functions it calls:
283 # - generate_email_header
284 # - generate_create_XXXX_email
285 # - generate_update_XXXX_email
286 # - generate_delete_XXXX_email
287 # - generate_email_footer
289 # Note also that this function cannot 'exit' from the script; when this
290 # function is running (in hook script mode), the send_mail() function
291 # is already executing in another process, connected via a pipe, and
292 # if this function exits without, whatever has been generated to that
293 # point will be sent as an email... even if nothing has been generated.
298 # The email subject will contain the best description of the ref
299 # that we can build from the parameters
300 describe
=$
(git describe
$rev 2>/dev
/null
)
301 if [ -z "$describe" ]; then
305 generate_email_header
307 # Call the correct body generation function
309 case "$refname_type" in
310 "tracking branch"|branch
)
317 generate_
${change_type}_
${fn_name}_email
319 generate_email_footer
322 generate_email_header
()
324 # --- Email (all stdout will be the email)
326 if [ -n "$emailsender" ]; then
327 echol
"From: $emailsender"
331 Subject: ${emailprefix}$projectname $refname_type $short_refname ${change_type}d: $describe
333 Content-Type: text/plain; charset=utf-8
334 Content-Transfer-Encoding: 8bit
336 [ -n "$cfg_suppress_x_girocco" ] || echol
"X-Girocco: $cfg_gitweburl"
337 [ -z "$emailextraheader" ] || echol
"$emailextraheader"
339 X-Git-Refname: $refname
340 X-Git-Reftype: $refname_type
341 X-Git-Oldrev: $oldrev
342 X-Git-Newrev: $newrev
343 Auto-Submitted: auto-generated
345 This is an automated email from the git hooks/post-receive script. It was
346 generated because a ref change was pushed to the repository containing
347 the project $projectname.
349 The $refname_type, $short_refname has been ${change_type}d
353 generate_email_footer
()
359 $cfg_name automatic notification. Contact project admin $projectowner
360 if you want to unsubscribe, or site admin $cfg_admin if you receive
367 # --------------- Branches
370 # Called for the creation of a branch
372 generate_create_branch_email
()
374 # This is a new branch and so oldrev is not valid
375 echol
" at $newrev ($newrev_type)"
378 echol
"Those revisions in this branch that are new to this repository"
379 echol
"have not appeared on any other notification email; so we list"
380 echol
"those revisions in full, below."
387 # The diffstat is shown from an empty tree to the new revision.
388 # This is to show the truth of what happened in this change.
389 # Note that since Git 1.5.5 the empty tree object is ALWAYS available
390 # whether or not it's actually present in the repository.
392 echol
"Summary of changes:"
393 git diff-tree
--no-color --stat=72 --summary -B --find-copies-harder 4b825dc642cb6eb9a060e54bf8d69288fbee4904
$newrev
397 # Called for the change of a pre-existing branch
399 generate_update_branch_email
()
402 # 1 --- 2 --- O --- X --- 3 --- 4 --- N
404 # O is $oldrev for $refname
405 # N is $newrev for $refname
406 # X is a revision pointed to by some other ref, for which we may
407 # assume that an email has already been generated.
408 # In this case we want to issue an email containing only revisions
409 # 3, 4, and N. Given (almost) by
411 # git rev-list N ^O --not --all
413 # The reason for the "almost", is that the "--not --all" will take
414 # precedence over the "N", and effectively will translate to
416 # git rev-list N ^O ^X ^N
418 # So, we need to build up the list more carefully. git rev-parse
419 # will generate a list of revs that may be fed into git rev-list.
420 # We can get it to make the "--not --all" part and then filter out
423 # git rev-parse --not --all | grep -v N
425 # Then, using the --stdin switch to git rev-list we have effectively
428 # git rev-list N ^O ^X
430 # This leaves a problem when someone else updates the repository
431 # while this script is running. Their new value of the ref we're
432 # working on would be included in the "--not --all" output; and as
433 # our $newrev would be an ancestor of that commit, it would exclude
434 # all of our commits. What we really want is to exclude the current
435 # value of $refname from the --not list, rather than N itself. So:
437 # git rev-parse --not --all | grep -v $(git rev-parse $refname)
439 # Get's us to something pretty safe (apart from the small time
440 # between refname being read, and git rev-parse running - for that,
444 # Next problem, consider this:
445 # * --- B --- * --- O ($oldrev)
447 # * --- X --- * --- N ($newrev)
449 # That is to say, there is no guarantee that oldrev is a strict
450 # subset of newrev (it would have required a --force, but that's
451 # allowed). So, we can't simply say rev-list $oldrev..$newrev.
452 # Instead we find the common base of the two revs and list from
455 # As above, we need to take into account the presence of X; if
456 # another branch is already in the repository and points at some of
457 # the revisions that we are about to output - we don't want them.
458 # The solution is as before: git rev-parse output filtered.
460 # Finally, tags: 1 --- 2 --- O --- T --- 3 --- 4 --- N
462 # Tags pushed into the repository generate nice shortlog emails that
463 # summarise the commits between them and the previous tag. However,
464 # those emails don't include the full commit messages that we output
465 # for a branch update. Therefore we still want to output revisions
466 # that have been output on a tag email.
468 # Luckily, git rev-parse includes just the tool. Instead of using
469 # "--all" we use "--branches"; this has the added benefit that
470 # "remotes/" will be ignored as well.
472 # List all of the revisions that were removed by this update, in a
473 # fast-forward update, this list will be empty, because rev-list O
474 # ^N is empty. For a non-fast-forward, O ^N is the list of removed
478 for rev in $
(git rev-list
$newrev..
$oldrev)
480 revtype
=$
(git cat-file
-t "$rev")
481 echol
" discards $rev ($revtype)"
483 if [ -z "$rev" ]; then
487 # List all the revisions from baserev to newrev in a kind of
488 # "table-of-contents"; note this list can include revisions that
489 # have already had notification emails and is present to show the
490 # full detail of the change from rolling back the old revision to
491 # the base revision and then forward to the new revision
492 for rev in $
(git rev-list
$oldrev..
$newrev)
494 revtype
=$
(git cat-file
-t "$rev")
495 echol
" via $rev ($revtype)"
498 if [ "$fast_forward" ]; then
499 echol
" from $oldrev ($oldrev_type)"
501 # 1. Existing revisions were removed. In this case newrev
502 # is a subset of oldrev - this is the reverse of a
503 # fast-forward, a rewind
504 # 2. New revisions were added on top of an old revision,
505 # this is a rewind and addition.
507 # (1) certainly happened, (2) possibly. When (2) hasn't
508 # happened, we set a flag to indicate that no log printout
513 # Find the common ancestor of the old and new revisions and
514 # compare it with newrev
515 baserev
=$
(git merge-base
$oldrev $newrev)
517 if [ "$baserev" = "$newrev" ]; then
518 echol
"This update discarded existing revisions and left the branch pointing at"
519 echol
"a previous point in the repository history."
521 echol
" * -- * -- N ($newrev)"
523 echol
" O -- O -- O ($oldrev)"
525 echol
"The removed revisions are not necessarily gone - if another reference"
526 echol
"still refers to them they will stay in the repository."
529 echol
"This update added new revisions after undoing existing revisions. That is"
530 echol
"to say, the old revision is not a strict subset of the new revision. This"
531 echol
"situation occurs when you --force push a change and generate a repository"
532 echol
"containing something like this:"
534 echol
" * -- * -- B -- O -- O -- O ($oldrev)"
536 echol
" N -- N -- N ($newrev)"
538 echol
"When this happens we assume that you've already had alert emails for all"
539 echol
"of the O revisions, and so we here report only the revisions in the N"
540 echol
"branch from the common base, B."
545 if [ -z "$rewind_only" ]; then
546 echol
"Those revisions listed above that are new to this repository have"
547 echol
"not appeared on any other notification email; so we list those"
548 echol
"revisions in full, below."
554 # XXX: Need a way of detecting whether git rev-list actually
555 # outputted anything, so that we can issue a "no new
556 # revisions added by this update" message
560 echol
"No new revisions were added by this update."
563 # The diffstat is shown from the old revision to the new revision.
564 # This is to show the truth of what happened in this change.
565 # There's no point showing the stat from the base to the new
566 # revision because the base is effectively a random revision at this
567 # point - the user will be interested in what this revision changed
568 # - including the undoing of previous revisions in the case of
569 # non-fast-forward updates.
571 echol
"Summary of changes:"
572 git diff-tree
--no-color --stat=72 --summary -B --find-copies-harder $oldrev..
$newrev
576 # Called for the deletion of a branch
578 generate_delete_branch_email
()
583 git diff-tree
--no-color --date=$datefmt -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8
--pretty=oneline
$oldrev
587 # --------------- Annotated tags
590 # Called for the creation of an annotated tag
592 generate_create_atag_email
()
594 echol
" at $newrev ($newrev_type)"
600 # Called for the update of an annotated tag (this is probably a rare event
601 # and may not even be allowed)
603 generate_update_atag_email
()
605 echol
" to $newrev ($newrev_type)"
606 echol
" from $oldrev (which is now obsolete)"
612 # Called when an annotated tag is created or changed
614 generate_atag_email
()
616 # Use read_tag_fields to pull out the individual fields from the
617 # tag and git cat-file --batch-check to fully peel the tag if needed
620 read_tag_fields
"$tagrev"
621 if [ "$tagtype" = "tag" ]; then
625 info
="$(echo "$tagrev^
{}" | git cat-file --batch-check='
626 peeledobject=%(objectname)
627 peeledtype=%(objecttype)'
629 case "$info" in *type=*) eval "$info";; *)
633 peeledobject
="$tagobject"
634 peeledtype
="$tagtype"
637 echol
" tagging $peeledobject ($peeledtype)"
638 case "$peeledtype" in
641 # If the tagged object is a commit, then we assume this is a
642 # release, and so we calculate which tag this tag is
644 prevtag
=$
(git describe
--abbrev=0 "$peeledobject^" 2>/dev
/null
)
646 if [ -n "$prevtag" ]; then
647 echol
" replaces $prevtag"
651 echol
" length $(git cat-file -s "$peeledobject" 2>/dev/null) bytes"
654 echol
" tagged by $taggername"
655 echol
" on $taggerdate"
663 echol
"Object: $tagobject ($tagtype)"
664 [ -z "$taggername" ] || \
665 echol
"Tagger: $taggername"
666 [ -z "$taggerdate" ] || \
667 echol
"Date: $taggerdate"
668 echol
"URL: <$projurl/$tagrev16>"
671 # Show the content of the tag message; this might contain a change
672 # log or release notes so is worth displaying.
673 git cat-file tag
"$tagrev" | LC_ALL
=C
sed -e '1,/^$/d;s/^/ /;'
675 [ "$tagtype" = "tag" ]
678 scratch
="${tagrev#????????????????}"
679 tagrev16
="${tagrev%$scratch}"
680 read_tag_fields
"$tagrev" ||
break
683 case "$peeledtype" in
685 # Only commit tags make sense to have rev-list operations
687 if [ -n "$prevtag" ]; then
688 # Show changes since the previous release
689 git shortlog
"$prevtag..$newrev"
691 # No previous tag, show all the changes since time
697 # XXX: Is there anything useful we can do for non-commit
706 # Called for the deletion of an annotated tag
708 generate_delete_atag_email
()
713 git diff-tree
--no-color --date=$datefmt -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8
--pretty=oneline
$oldrev
717 # --------------- General references
720 # Called when any other type of reference is created (most likely a
723 generate_create_general_email
()
725 echol
" at $newrev ($newrev_type)"
727 generate_general_email
731 # Called when any other type of reference is updated (most likely a
734 generate_update_general_email
()
736 echol
" to $newrev ($newrev_type)"
737 echol
" from $oldrev"
739 generate_general_email
743 # Called for creation or update of any other type of reference
745 generate_general_email
()
747 # Unannotated tags are more about marking a point than releasing a
748 # version; therefore we don't do the shortlog summary that we do for
749 # annotated tags above - we simply show that the point has been
750 # marked, and print the log message for the marked point for
753 # Note this section also catches any other reference type (although
754 # there aren't any) and deals with them in the same way.
757 if [ "$newrev_type" = "commit" ]; then
759 git diff-tree
--no-color --date=$datefmt --root -s --always --encoding=UTF-8
--format="$pfmt1$projurlesc/$newrev16$pfmt2" $newrev
762 # What can we do here? The tag marks an object that is not
763 # a commit, so there is no log for us to display. It's
764 # probably not wise to output git cat-file as it could be a
765 # binary blob. We'll just say how big it is
766 echol
"$newrev is a $newrev_type, and is $(git cat-file -s $newrev) bytes long."
771 # Called for the deletion of any other type of reference
773 generate_delete_general_email
()
778 git diff-tree
--no-color --date=$datefmt -s --abbrev-commit --abbrev=$habbr --always --encoding=UTF-8
--pretty=oneline
$oldrev
783 # --------------- Miscellaneous utilities
786 # Show new revisions as the user would like to see them in the email.
790 # This shows all log entries that are not already covered by
791 # another ref - i.e. commits that are now accessible from this
792 # ref that were previously not accessible
793 # (see generate_update_branch_email for the explanation of this
796 # Revision range passed to rev-list differs for new vs. updated
798 if [ "$change_type" = create
]
800 # Show all revisions exclusive to this (new) branch.
803 # Branch update; show revisions not part of $oldrev.
804 revspec
=$oldrev..
$newrev
807 if [ "${MAIL_SH_OTHER_BRANCHES+set}" = "set" ]; then
808 case "$MAIL_SH_OTHER_BRANCHES" in
810 othertips
="git cat-file blob '${MAIL_SH_OTHER_BRANCHES#@}' 2>/dev/null"
813 othertips
='printf "%s\n" $MAIL_SH_OTHER_BRANCHES'
817 othertips
='git for-each-ref --format="%(refname)" refs/heads |
818 LC_ALL=C awk -v "refname=$refname" "\$1 != refname"'
821 git cat-file
--batch-check='^%(objectname)' |
822 LC_ALL
=C
sed -e '/ missing$/d' |
823 # if [ -z "$custom_showrev" ]
825 # git rev-list --pretty --stdin $revspec
827 git
--no-pager log
--stdin --no-color --format=tformat
:"%H %p" $revspec |
828 LC_ALL
=C
awk '{print $1 " " NF-1}' |
829 while read onerev pcnt
831 if [ -n "$custom_showrev" ]; then
832 eval $
(printf "$custom_showrev" $onerev)
834 if [ ${summaryonly:-false} = false
]; then
835 if [ ${pcnt:-1} -gt 1 ]; then
838 opts
="-p --stat=72 --summary"
841 if [ ${pcnt:-1} -gt 1 ]; then
844 opts
="--stat=72 --summary"
847 scratch
="${onerev#????????????????}"
848 onerev16
="${onerev%$scratch}"
849 git diff-tree
--no-color --date=$datefmt $opts --always --encoding=UTF-8
--format="$pfmt1$projurlesc/$onerev16$pfmt2" --abbrev=$habbr -B -C --root $onerev
860 while IFS
= read -r line
; do
861 # Include size of RFC 822 trailing CR+LF on each line
862 size
=$
(($size+${#line}+2))
863 if [ $size -gt $1 ]; then
864 echol
"...e-mail trimmed, has been too large."
880 if [ -n "$cfg_sender" ]; then
881 "${cfg_sendmail_bin:-/usr/sbin/sendmail}" -i -t -f "$cfg_sender"
883 "${cfg_sendmail_bin:-/usr/sbin/sendmail}" -i -t
887 # ---------------------------- main()
890 LOGBEGIN
="- Log -----------------------------------------------------------------"
891 LOGEND
="-----------------------------------------------------------------------"
896 # Git formatting to use
900 # strftime formatting to use (empty is default rfc2822 format)
903 # This is --pretty=medium in two parts with a URL: line added
904 pfmt1
='format:commit %H%nAuthor: %an <%ae>%nDate: %ad%nURL: <'
905 pfmt2
='>%n%n%w(0,4,4)%s%n%n%b'
907 git_add_config core.abbrev
=$habbr
909 # Set GIT_DIR either from the working directory, or from the environment
911 GIT_DIR
=$
(git rev-parse
--git-dir 2>/dev
/null
)
912 if [ -z "$GIT_DIR" ]; then
913 echol
>&2 "fatal: post-receive: GIT_DIR not set"
918 ! [ -s "$GIT_DIR/description" ] || projectdesc
=$
(LC_ALL
=C
sed -ne '1p' "$GIT_DIR/description")
919 # Check if the description is unchanged from it's default, and shorten it to
920 # a more manageable length if it is
921 if [ -z "$projectdesc" ] || LC_ALL
=C
expr "$projectdesc" : "Unnamed repository.*$" >/dev
/null
923 projectdesc
="UNNAMED PROJECT"
926 # If --stdout is first argument send all output there instead of mailing
927 if [ "$1" = "--stdout" ]; then
929 cfg_sendmail_bin
="sendmail_to_stdout"
932 projectname
="${4%.git}"
933 if [ -n "$projectname" ]; then
934 projectname
="$projectname.git"
935 projectowner
="$(config_get owner)"
937 projectname
="$(basename "$PWD")"
939 projectboth
="$projectname (\"$projectdesc\")"
940 projurl
="$cfg_gitweburl/$projectname"
941 projurlesc
="$(printf '%s\n' "$projurl" | sed -e 's/%/%%/g')"
944 emailextraheader
="$6"
946 recipients
=$
(git config hooks.mailinglist
)
947 summaryonly
=$
(git config
--bool hooks.summaryonly
2>/dev
/null ||
:)
948 announcerecipients
=$
(git config hooks.announcelist
)
949 envelopesender
=$
(git config hooks.envelopesender
)
950 emailprefix
=$
(git config hooks.emailprefix || echol
"[$cfg_name] ")
951 custom_showrev
=$
(git config hooks.showrev
)
954 # Allow dual mode: run from the command line just like the update hook, or
955 # if no arguments are given then run as a hook script
956 # If --stdout is first argument send all output there instead (handled above)
957 # Optional 4th (projectname), 5th (sender) and 6th (extra header) arguments
958 if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
959 # Handle a single update rather than a batch on stdin
960 # Output will still be sent to sendmail unless --stdout is used
961 # Same 3 args as update hook (<refname> <old> <new>)
962 if prep_for_email
$2 $3 $1; then
963 PAGER
= generate_email | size_limit $
((256*1024)) | send_mail
966 # MAIL_SH_OTHER_BRANCHES cannot possibly be valid for multiple updates
967 unset MAIL_SH_OTHER_BRANCHES
968 # Same input as pre-receive hook (each line is <old> <new> <refname>)
969 while read oldrev newrev refname
971 prep_for_email
$oldrev $newrev $refname ||
continue
972 PAGER
= generate_email | size_limit $
((256*1024)) | send_mail