From cbd19115a4d8639ed2058352619893a30fd4bccb Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 20 Nov 2017 15:53:05 -0800 Subject: [PATCH] mail.sh: allow working without an shlib.sh Allow the mail.sh script to be run without needing to have a fully configured and installed shlib.sh file. Since mail.sh is originally derived from the post-receive-email hook script it was initially intended to work without any shlib.sh in the first place. With only the very tiniest of adaptations, it can do so again. Having the ability to run mail.sh without needing an installed and configured shlib.sh greatly facilitates the testing of various ref change scenarios. Signed-off-by: Kyle J. McKay --- taskd/mail.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/taskd/mail.sh b/taskd/mail.sh index b7ae6ca..738a648 100755 --- a/taskd/mail.sh +++ b/taskd/mail.sh @@ -360,8 +360,8 @@ generate_email_footer() cat <<-EOF - $cfg_name automatic notification. Contact project admin $projectowner - if you want to unsubscribe, or site admin $cfg_admin if you receive + ${cfg_name:-mail.sh} automatic notification. Contact project admin $projectowner + if you want to unsubscribe, or site admin ${cfg_admin:+$cfg_admin }if you receive no reply. --${SPACE} $projectboth @@ -947,7 +947,7 @@ LOGBEGIN="- Log ---------------------------------------------------------------- LOGEND="-----------------------------------------------------------------------" # --- Config -. @basedir@/shlib.sh +! [ -f @basedir@/shlib.sh ] || ! [ -r @basedir@/shlib.sh ] || . @basedir@/shlib.sh # Git formatting to use datefmt=rfc2822 @@ -964,7 +964,8 @@ pfmt1m='Merge: %p%n' pfmt2='Author: %an <%ae>%nDate: %ad%nURL: <' pfmt3='>%n%n%w(0,4,4)%s%n%n%b' -git_add_config core.abbrev=$habbr +GIT_CONFIG_PARAMETERS="${GIT_CONFIG_PARAMETERS:+$GIT_CONFIG_PARAMETERS }'core.abbrev=$habbr'" +export GIT_CONFIG_PARAMETERS # Set GIT_DIR either from the working directory, or from the environment # variable. @@ -1000,9 +1001,11 @@ fi projectname="${4%.git}" if [ -n "$projectname" ]; then projectname="$projectname.git" - projectowner="$(config_get owner)" || : + projectowner="$(git config gitweb.owner 2>/dev/null)" || : else - projectname="$(basename "$PWD")" + projectname="$(cd "$GIT_DIR" && pwd)" + projectname="${projectname%/.git}" + projectname="$(basename "$projectname")" fi projectboth="$projectname (\"$projectdesc\")" projurl="$cfg_gitweburl/$projectname" @@ -1017,7 +1020,7 @@ reverseopt= [ "$(git config --bool hooks.reverseorder 2>/dev/null || :)" != "true" ] || reverseopt=--reverse announcerecipients="$(git config hooks.announcelist)" || : envelopesender="$(git config hooks.envelopesender)" || : -emailprefix="$(git config hooks.emailprefix || echol "[$cfg_name] ")" || : +emailprefix="$(git config hooks.emailprefix || echol "[${cfg_name:-mail.sh}] ")" || : custom_showrev="$(git config hooks.showrev)" || : # --- Main loop -- 2.11.4.GIT