From 3a895e0268537da731f5efe914ece5e7eac35ef3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 8 Jul 2006 01:50:02 -0700 Subject: templates/hooks--update: replace diffstat calls with git diff --stat Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- templates/hooks--update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index d7a8f0a849..76d5ac2477 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -60,7 +60,7 @@ then echo "Changes since $prev:" git rev-list --pretty $prev..$3 | $short echo --- - git diff $prev..$3 | diffstat -p1 + git diff --stat $prev..$3 echo --- fi ;; @@ -75,7 +75,7 @@ else base=$(git-merge-base "$2" "$3") case "$base" in "$2") - git diff "$3" "^$base" | diffstat -p1 + git diff --stat "$3" "^$base" echo echo "New commits:" ;; -- cgit v1.2.3 From b81ba571242a1b64b4fbda215ea38dd062f2b05f Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 28 Dec 2006 16:05:02 +0100 Subject: update hook: redirect _both_ diagnostic lines to stderr upon tag failure Otherwise, sending the diagnostic to stdout would provoke a protocol failure. Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- templates/hooks--update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 76d5ac2477..9863a800c8 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -19,7 +19,7 @@ ref_type=$(git cat-file -t "$3") case "$1","$ref_type" in refs/tags/*,commit) echo "*** Un-annotated tags are not allowed in this repo" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 exit 1;; refs/tags/*,tag) echo "### Pushing version '${1##refs/tags/}' to the masses" >&2 -- cgit v1.2.3 From a69aba6af3e96f8021c194691a851e78febd70bf Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Fri, 26 Jan 2007 08:58:48 +0000 Subject: UNIX reference time of 1970-01-01 00:00 is UTC timezone, not local time zone I got bitten because in the UK (where one would expect 1970-01-01 00:00 to be UTC 0) some politicians decided to mess around with daylight savings time from 1968 to 1971; it was permanently BST (+0100). That means that on my computer the following is true: $ date --date="1970-01-01 00:00" +"%F %T %z (%Z)" 1970-01-01 00:00:00 +0100 (BST) This of course means that the --date argument to date is specified in local time, not UTC. So when the hooks--update script does this: date=$(date --date="1970-01-01 00:00:00 $ts seconds") It's actually saying (in my timezone) "1970-01-01 01:00:00 UTC" + $ts. Clearly this is wrong. The UNIX epoch started at midnight UTC not 1am UTC. This leads to the tagged time in hooks--update being shown as one hour earlier than the true tagged time (in my timezone). The problem would be worse for other timezones. For a +1300 timezone on 1970-01-01, the tagged time would be 13 hours earlier. Oops. The solution is to force the reference time to UTC, which is what this patch does. In my timezone: $ date --date="1970-01-01 00:00 +0000" +"%F %T %z (%Z)" 1970-01-01 01:00:00 +0100 (BST) Much better. Signed-off-by: Andy Parkins --- templates/hooks--update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 9863a800c8..81f706fb0d 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -46,7 +46,7 @@ then if [ "$ref_type" = tag ]; then eval $(git cat-file tag $3 | \ sed -n '4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p') - date=$(date --date="1970-01-01 00:00:00 $ts seconds" +"$date_format") + date=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds" +"$date_format") echo "Tag '$tag' created by $tagger at $date" git cat-file tag $3 | sed -n '5,$p' echo -- cgit v1.2.3 From 829a686f1b50ba96cac2d88494fa339efe0c0862 Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Fri, 26 Jan 2007 09:01:04 +0000 Subject: Heavily expanded update hook to send more useful emails than the old hook I know it's only an example, but having this might save someone else the trouble of writing an enhanced version for themselves. It basically does the same job as the old update hook, but with these differences: * The recipients list is read from the repository config file from hooks.mailinglist * Updating unannotated tags can be allowed by setting hooks.allowunannotated * Announcement emails (via annotated tag creation) can be sent to a different mailing list by setting hooks.announcelist * Output email is more verbose and generates specific content depending on whether the ref is a tag, an annotated tag, a branch, or a tracking branch * The email is easier to filter; the subject line is prefixed with [SCM] and a project description pulled from the "description" file * It catches (and displays differently) branch updates that are performed with a --force Obviously, it's nothing that clever - it's the update hook I use on my repositories but I've tried to keep it general, and tried to make the output always relevant to the type of update. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- templates/hooks--update | 340 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 268 insertions(+), 72 deletions(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 81f706fb0d..4bd9d96ff9 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -1,89 +1,285 @@ #!/bin/sh # # An example hook script to mail out commit update information. -# It also blocks tags that aren't annotated. +# It can also blocks tags that aren't annotated. # Called by git-receive-pack with arguments: refname sha1-old sha1-new # -# To enable this hook: -# (1) change the recipient e-mail address -# (2) make this file executable by "chmod +x update". +# To enable this hook, make this file executable by "chmod +x update". # +# Config +# ------ +# hooks.mailinglist +# This is the list that all pushes will go to; leave it blank to not send +# emails frequently. The log email will list every log entry in full between +# the old ref value and the new ref value. +# hooks.announcelist +# This is the list that all pushes of annotated tags will go to. Leave it +# blank to just use the mailinglist field. The announce emails list the +# short log summary of the changes since the last annotated tag +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# +# Notes +# ----- +# All emails have their subjects prefixed with "[SCM]" to aid filtering. +# All emails include the headers "X-Git-Refname", "X-Git-Oldrev", +# "X-Git-Newrev", and "X-Git-Reftype" to enable fine tuned filtering and info. -project=$(cat $GIT_DIR/description) -recipients="commit-list@somewhere.com commit-list@somewhereelse.com" - -ref_type=$(git cat-file -t "$3") - -# Only allow annotated tags in a shared repo -# Remove this code to treat dumb tags the same as everything else -case "$1","$ref_type" in -refs/tags/*,commit) - echo "*** Un-annotated tags are not allowed in this repo" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1;; -refs/tags/*,tag) - echo "### Pushing version '${1##refs/tags/}' to the masses" >&2 - # recipients="release-announce@somwehere.com announce@somewhereelse.com" - ;; -esac +# --- Constants +EMAILPREFIX="[SCM] " +LOGBEGIN="- Log -----------------------------------------------------------------" +LOGEND="-----------------------------------------------------------------------" +DATEFORMAT="%F %R %z" + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +# --- Config +projectdesc=$(cat $GIT_DIR/description) +recipients=$(git-repo-config hooks.mailinglist) +announcerecipients=$(git-repo-config hooks.announcelist) +allowunannotated=$(git-repo-config --bool hooks.allowunannotated) -# set this to 'cat' to get a very detailed listing. -# short only kicks in when an annotated tag is added -short='git shortlog' - -# see 'date --help' for info on how to write this -# The default is a human-readable iso8601-like format with minute -# precision ('2006-01-25 15:58 +0100' for example) -date_format="%F %R %z" - -(if expr "$2" : '0*$' >/dev/null -then - # new ref - case "$1" in - refs/tags/*) - # a pushed and annotated tag (usually) means a new version - tag="${1##refs/tags/}" - if [ "$ref_type" = tag ]; then - eval $(git cat-file tag $3 | \ - sed -n '4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p') - date=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds" +"$date_format") - echo "Tag '$tag' created by $tagger at $date" - git cat-file tag $3 | sed -n '5,$p' - echo +# --- Check types +newrev_type=$(git-cat-file -t "$newrev") + +case "$refname","$newrev_type" in + refs/tags/*,commit) + # un-annoted tag + refname_type="tag" + short_refname=${refname##refs/tags/} + if [ $allowunannotated != "true" ]; then + echo "*** The un-annotated tag, $short_refname is not allowed in this repository" >&2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 fi - prev=$(git describe "$3^" | sed 's/-g.*//') - # the first tag in a repo will yield no $prev - if [ -z "$prev" ]; then - echo "Changes since the dawn of time:" - git rev-list --pretty $3 | $short - else - echo "Changes since $prev:" - git rev-list --pretty $prev..$3 | $short - echo --- - git diff --stat $prev..$3 - echo --- + ;; + refs/tags/*,tag) + # annotated tag + refname_type="annotated tag" + short_refname=${refname##refs/tags/} + # change recipients + if [ -n "$announcerecipients" ]; then + recipients="$announcerecipients" fi ;; + refs/heads/*,commit) + # branch + refname_type="branch" + short_refname=${refname##refs/heads/} + ;; + refs/remotes/*,commit) + # tracking branch + refname_type="tracking branch" + short_refname=${refname##refs/remotes/} + # Should this even be allowed? + echo "*** Push-update of tracking branch, $refname. No email generated." >&2 + exit 0 + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update, \"$newrev_type\", to ref $refname" >&2 + exit 1 + ;; +esac + +# Check if we've got anyone to send to +if [ -z "$recipients" ]; then + # If the email isn't sent, then at least give the user some idea of what command + # would generate the email at a later date + echo "*** No recipients found - no email will be sent, but the push will continue" >&2 + echo "*** for $0 $1 $2 $3" >&2 + exit 0 +fi + +# --- Email parameters +committer=$(git show --pretty=full -s $newrev | grep "^Commit: " | sed -e "s/^Commit: //") +describe=$(git describe $newrev 2>/dev/null) +if [ -z "$describe" ]; then + describe=$newrev +fi - refs/heads/*) - branch="${1##refs/heads/}" - echo "New branch '$branch' available with the following commits:" - git-rev-list --pretty "$3" $(git-rev-parse --not --all) +# --- Email (all stdout will be the email) +( +# Generate header +cat <<-EOF +From: $committer +To: $recipients +Subject: ${EMAILPREFIX}$projectdesc $refname_type, $short_refname now at $describe +X-Git-Refname: $refname +X-Git-Reftype: $refname_type +X-Git-Oldrev: $oldrev +X-Git-Newrev: $newrev + +Hello, + +This is an automated email from the git hooks/update script, it was +generated because a ref change was pushed to the repository. + +Updating $refname_type, $short_refname, +EOF + +case "$refname_type" in + "tracking branch"|branch) + if expr "$oldrev" : '0*$' >/dev/null + then + # If the old reference is "0000..0000" then this is a new branch + # and so oldrev is not valid + echo " as a new $refname_type" + echo " to $newrev ($newrev_type)" + echo "" + echo $LOGBEGIN + # This shows all log entries that are not already covered by + # another ref - i.e. commits that are now accessible from this + # ref that were previously not accessible + git-rev-list --pretty $newref $(git-rev-parse --not --all) + echo $LOGEND + else + # oldrev is valid + oldrev_type=$(git-cat-file -t "$oldrev") + + # Now the problem is for cases like this: + # * --- * --- * --- * (oldrev) + # \ + # * --- * --- * (newrev) + # i.e. there is no guarantee that newrev is a strict subset + # of oldrev - (would have required a force, but that's allowed). + # So, we can't simply say rev-list $oldrev..$newrev. Instead + # we find the common base of the two revs and list from there + baserev=$(git-merge-base $oldrev $newrev) + + # Commit with a parent + for rev in $(git-rev-list $newrev ^$baserev) + do + revtype=$(git-cat-file -t "$rev") + echo " via $rev ($revtype)" + done + if [ "$baserev" = "$oldrev" ]; then + echo " from $oldrev ($oldrev_type)" + else + echo " based on $baserev" + echo " from $oldrev ($oldrev_type)" + echo "" + echo "This ref update crossed a branch point; i.e. the old rev is not a strict subset" + echo "of the new rev. This occurs, when you --force push a change in a situation" + echo "like this:" + echo "" + echo " * -- * -- B -- O -- O -- O ($oldrev)" + echo " \\" + echo " N -- N -- N ($newrev)" + echo "" + echo "Therefore, we assume that you've already had alert emails for all of the O" + echo "revisions, and now give you all the revisions in the N branch from the common" + echo "base, B ($baserev), up to the new revision." + fi + echo "" + echo $LOGBEGIN + git-rev-list --pretty $newrev ^$baserev + echo $LOGEND + echo "" + echo "Diffstat:" + git-diff-tree --no-color --stat -M -C --find-copies-harder $newrev ^$baserev + fi ;; - esac -else - base=$(git-merge-base "$2" "$3") - case "$base" in - "$2") - git diff --stat "$3" "^$base" - echo - echo "New commits:" + "annotated tag") + # Should we allow changes to annotated tags? + if expr "$oldrev" : '0*$' >/dev/null + then + # If the old reference is "0000..0000" then this is a new atag + # and so oldrev is not valid + echo " to $newrev ($newrev_type)" + else + echo " to $newrev ($newrev_type)" + echo " from $oldrev" + fi + + # If this tag succeeds another, then show which tag it replaces + prevtag=$(git describe $newrev^ 2>/dev/null | sed 's/-g.*//') + if [ -n "$prevtag" ]; then + echo " replaces $prevtag" + fi + + # Read the tag details + eval $(git cat-file tag $newrev | \ + sed -n '4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p') + tagged=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds" +"$DATEFORMAT") + + echo " tagged by $tagger" + echo " on $tagged" + + echo "" + echo $LOGBEGIN + echo "" + + if [ -n "$prevtag" ]; then + git rev-list --pretty=short "$prevtag..$newrev" | git shortlog + else + git rev-list --pretty=short $newrev | git shortlog + fi + + echo $LOGEND + echo "" ;; *) - echo "Rebased ref, commits from common ancestor:" + # By default, unannotated tags aren't allowed in; if + # they are though, it's debatable whether we would even want an + # email to be generated; however, I don't want to add another config + # option just for that. + # + # Unannotated tags are more about marking a point than releasing + # a version; therefore we don't do the shortlog summary that we + # do for annotated tags above - we simply show that the point has + # been marked, and print the log message for the marked point for + # reference purposes + # + # Note this section also catches any other reference type (although + # there aren't any) and deals with them in the same way. + if expr "$oldrev" : '0*$' >/dev/null + then + # If the old reference is "0000..0000" then this is a new tag + # and so oldrev is not valid + echo " as a new $refname_type" + echo " to $newrev ($newrev_type)" + else + echo " to $newrev ($newrev_type)" + echo " from $oldrev" + fi + echo "" + echo $LOGBEGIN + git-show --no-color --root -s $newrev + echo $LOGEND + echo "" ;; - esac - git-rev-list --pretty "$3" "^$base" -fi) | -mail -s "$project: Changes to '${1##refs/heads/}'" $recipients +esac + +# Footer +cat <<-EOF + +hooks/update +--- +Git Source Code Management System +$0 $1 \\ + $2 \\ + $3 +EOF +#) | cat >&2 +) | /usr/sbin/sendmail -t + +# --- Finished exit 0 -- cgit v1.2.3 From 3dff5379bf1e3fda5e5a84ca5813b0c0cfd51be7 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sat, 3 Feb 2007 23:49:16 -0500 Subject: Assorted typo fixes Signed-off-by: Junio C Hamano --- templates/hooks--update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 4bd9d96ff9..d4253cbcfb 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -61,7 +61,7 @@ newrev_type=$(git-cat-file -t "$newrev") case "$refname","$newrev_type" in refs/tags/*,commit) - # un-annoted tag + # un-annotated tag refname_type="tag" short_refname=${refname##refs/tags/} if [ $allowunannotated != "true" ]; then -- cgit v1.2.3 From 72f627d2bc860c560e4ea4ee172982b1d38ceca8 Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Tue, 13 Feb 2007 14:23:58 +0000 Subject: Fix potential command line overflow in hooks--update In a repository with a large number of refs, the following command line could easily overflow the command line size limitations git-rev-list $newref $(git-rev-parse --not --all) Fortunately, git-rev-list already has the means to cope with this situation with the --stdin switch git-rev-parse --not --all | git-rev-list --stdin $newref Which is exactly what this patch does. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- templates/hooks--update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index d4253cbcfb..e8c536fb61 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -148,7 +148,7 @@ case "$refname_type" in # This shows all log entries that are not already covered by # another ref - i.e. commits that are now accessible from this # ref that were previously not accessible - git-rev-list --pretty $newref $(git-rev-parse --not --all) + git-rev-parse --not --all | git-rev-list --stdin --pretty $newref echo $LOGEND else # oldrev is valid -- cgit v1.2.3 From 44478d99ee0b2c219a733545efe0cb422658bf60 Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Tue, 13 Feb 2007 14:24:06 +0000 Subject: Only show log entries for new revisions in hooks--update If you were issuing emails for two branches, and one merged the other, you would get the same log messages appearing in two separate emails. e.g. A working repository, where the last push to central was done at the revision marked "B", after which two branches were developed further. * -- B -- 1 -- 1 -- M (branch1) \ / 2 -- 2 -- 2 (branch2) Now imagine that branch2 is pushed to the email-generating repository; an email containing all the "2" revisions would be sent. Now, let's say branch1 is pushed, the old update hook would run git-rev-list $newrev ^$baserev Where $newrev would be "M" and $baserev would be "B". This list includes all the "2" revisions as well as all the "1" revisions. This patch addresses this problem by using git-rev-parse --not --all | git-rev-list --stdin $newrev ^$baserev To inhibit the display of all revisions that are already in the repository. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- templates/hooks--update | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index e8c536fb61..a7cf604dd0 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -190,7 +190,8 @@ case "$refname_type" in fi echo "" echo $LOGBEGIN - git-rev-list --pretty $newrev ^$baserev + git-rev-parse --not --all | + git-rev-list --stdin --pretty $newrev ^$baserev echo $LOGEND echo "" echo "Diffstat:" -- cgit v1.2.3 From 9a894e8e7c85794d39745eb83462a2001816ac3b Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Wed, 14 Feb 2007 11:20:32 +0000 Subject: The "table-of-contents" in the update hook script should match the body 44478d99ee0 introduced a filter using "git-rev-parse --not --all" to the log display to prevent the display of revisions already in the repository. However, the table of contents generation didn't get that same update. This patch fixes that. The table of contents before the log and the log now both display the same list of revisions. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- templates/hooks--update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index a7cf604dd0..fd1f73d6aa 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -57,7 +57,7 @@ announcerecipients=$(git-repo-config hooks.announcelist) allowunannotated=$(git-repo-config --bool hooks.allowunannotated) # --- Check types -newrev_type=$(git-cat-file -t "$newrev") +newrev_type=$(git-cat-file -t $newrev) case "$refname","$newrev_type" in refs/tags/*,commit) @@ -165,7 +165,7 @@ case "$refname_type" in baserev=$(git-merge-base $oldrev $newrev) # Commit with a parent - for rev in $(git-rev-list $newrev ^$baserev) + for rev in $(git-rev-parse --not --all | git-rev-list --stdin $newrev ^$baserev) do revtype=$(git-cat-file -t "$rev") echo " via $rev ($revtype)" -- cgit v1.2.3 From 3d84df43e134d01cb790ddd47a14963ecd110152 Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Fri, 2 Mar 2007 19:29:20 +0000 Subject: Sample update hook: typofix and modernization to use "git log" Instead of using antiquated "git-rev-parse | git-rev-list" pipeline, it is easier to use "git-rev-list" or "git-log" these days, as Linus points out. While we are at it, fix the typo on variable name $newref that should be $newrev. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- templates/hooks--update | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index fd1f73d6aa..4af2fe8d95 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -148,7 +148,7 @@ case "$refname_type" in # This shows all log entries that are not already covered by # another ref - i.e. commits that are now accessible from this # ref that were previously not accessible - git-rev-parse --not --all | git-rev-list --stdin --pretty $newref + git log $newrev --not --all echo $LOGEND else # oldrev is valid @@ -165,7 +165,7 @@ case "$refname_type" in baserev=$(git-merge-base $oldrev $newrev) # Commit with a parent - for rev in $(git-rev-parse --not --all | git-rev-list --stdin $newrev ^$baserev) + for rev in $(git-rev-list $newrev --not $baserev --all) do revtype=$(git-cat-file -t "$rev") echo " via $rev ($revtype)" @@ -190,12 +190,11 @@ case "$refname_type" in fi echo "" echo $LOGBEGIN - git-rev-parse --not --all | - git-rev-list --stdin --pretty $newrev ^$baserev + git log $newrev --not $baserev --all echo $LOGEND echo "" echo "Diffstat:" - git-diff-tree --no-color --stat -M -C --find-copies-harder $newrev ^$baserev + git-diff-tree --no-color --stat -M -C --find-copies-harder $baserev..$newrev fi ;; "annotated tag") -- cgit v1.2.3 From b8ac23bcf82e67ccc56b90217c68d7a46b4b2bbc Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Fri, 2 Mar 2007 12:20:10 +0000 Subject: Fix quoting in update hook template By default allowunannotated is unset in the repo config, hence $allowunannotated is empty, and must be quoted to not break the syntax. Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- templates/hooks--update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index e8c536fb61..555bd5f532 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -64,7 +64,7 @@ case "$refname","$newrev_type" in # un-annotated tag refname_type="tag" short_refname=${refname##refs/tags/} - if [ $allowunannotated != "true" ]; then + if [ "$allowunannotated" != "true" ]; then echo "*** The un-annotated tag, $short_refname is not allowed in this repository" >&2 echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 exit 1 -- cgit v1.2.3 From c47e6a43d30c8a1fd4b8e9234883f01fe3bac805 Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Wed, 14 Mar 2007 14:25:52 +0000 Subject: update-hook: fix incorrect use of git-describe and sed for finding previous tag Previously git-describe would output lines of the form v1.1.1-gf509d56 The update hook found the dash and stripped it off using sed 's/-g.*//' The remainder was then used as the previous tag name. However, git-describe has changed format. The output is now of the form v1.1.1-23-gf509d56 The above sed fragment doesn't strip the middle "-23", and so the previous tag name used would be "v1.1.1-23". This is incorrect. Since the hook script was written, git-describe now gained support for "--abbrev=0", which it uses as a special flag to tell it not to output anything other than the nearest tag name. This patch fixes the problem, and prevents any future recurrence by using this new flag rather than sed to find the previous tag. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- templates/hooks--update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 5b82b68e93..8f6c4fea24 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -210,7 +210,7 @@ case "$refname_type" in fi # If this tag succeeds another, then show which tag it replaces - prevtag=$(git describe $newrev^ 2>/dev/null | sed 's/-g.*//') + prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null) if [ -n "$prevtag" ]; then echo " replaces $prevtag" fi -- cgit v1.2.3 From 0a0d080bdc68d2bd4a1824b08123690c8065badb Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Tue, 20 Mar 2007 10:58:32 +0000 Subject: update-hook: abort early if the project description is unset It was annoying to always have the first email from a project be from the "Unnamed repository; edit this file to name it for gitweb project"; just because it's so easy to forget to set it. This patch checks to see if the description file is still default (or empty) and aborts if so - allowing you to fix the problem before sending out silly looking emails to every developer. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- templates/hooks--update | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 8f6c4fea24..1a60773890 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -56,6 +56,12 @@ recipients=$(git-repo-config hooks.mailinglist) announcerecipients=$(git-repo-config hooks.announcelist) allowunannotated=$(git-repo-config --bool hooks.allowunannotated) +# check for no description +if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb" ]; then + echo "*** Project description file hasn't been set" >&2 + exit 1 +fi + # --- Check types newrev_type=$(git-cat-file -t $newrev) -- cgit v1.2.3 From 46d409d0bf25b361f812eec4888c46509c203a6d Mon Sep 17 00:00:00 2001 From: Andy Parkins Date: Fri, 23 Mar 2007 10:21:59 +0000 Subject: update-hook: remove e-mail sending hook. The update hook's only job is to decide is a particular update is allowed or not. It was not the right place to send out update notification e-mails from to begin with, as the final stage of updating refs can fail after this hook runs. Signed-off-by: Andy Parkins Signed-off-by: Junio C Hamano --- templates/hooks--update | 225 +----------------------------------------------- 1 file changed, 3 insertions(+), 222 deletions(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 1a60773890..0ff03309e6 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -1,36 +1,16 @@ #!/bin/sh # -# An example hook script to mail out commit update information. -# It can also blocks tags that aren't annotated. +# An example hook script to blocks unannotated tags from entering. # Called by git-receive-pack with arguments: refname sha1-old sha1-new # # To enable this hook, make this file executable by "chmod +x update". # # Config # ------ -# hooks.mailinglist -# This is the list that all pushes will go to; leave it blank to not send -# emails frequently. The log email will list every log entry in full between -# the old ref value and the new ref value. -# hooks.announcelist -# This is the list that all pushes of annotated tags will go to. Leave it -# blank to just use the mailinglist field. The announce emails list the -# short log summary of the changes since the last annotated tag # hooks.allowunannotated # This boolean sets whether unannotated tags will be allowed into the # repository. By default they won't be. # -# Notes -# ----- -# All emails have their subjects prefixed with "[SCM]" to aid filtering. -# All emails include the headers "X-Git-Refname", "X-Git-Oldrev", -# "X-Git-Newrev", and "X-Git-Reftype" to enable fine tuned filtering and info. - -# --- Constants -EMAILPREFIX="[SCM] " -LOGBEGIN="- Log -----------------------------------------------------------------" -LOGEND="-----------------------------------------------------------------------" -DATEFORMAT="%F %R %z" # --- Command line refname="$1" @@ -51,9 +31,6 @@ if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then fi # --- Config -projectdesc=$(cat $GIT_DIR/description) -recipients=$(git-repo-config hooks.mailinglist) -announcerecipients=$(git-repo-config hooks.announcelist) allowunannotated=$(git-repo-config --bool hooks.allowunannotated) # check for no description @@ -68,224 +45,28 @@ newrev_type=$(git-cat-file -t $newrev) case "$refname","$newrev_type" in refs/tags/*,commit) # un-annotated tag - refname_type="tag" short_refname=${refname##refs/tags/} if [ "$allowunannotated" != "true" ]; then - echo "*** The un-annotated tag, $short_refname is not allowed in this repository" >&2 + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 exit 1 fi ;; refs/tags/*,tag) # annotated tag - refname_type="annotated tag" - short_refname=${refname##refs/tags/} - # change recipients - if [ -n "$announcerecipients" ]; then - recipients="$announcerecipients" - fi ;; refs/heads/*,commit) # branch - refname_type="branch" - short_refname=${refname##refs/heads/} ;; refs/remotes/*,commit) # tracking branch - refname_type="tracking branch" - short_refname=${refname##refs/remotes/} - # Should this even be allowed? - echo "*** Push-update of tracking branch, $refname. No email generated." >&2 - exit 0 ;; *) # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update, \"$newrev_type\", to ref $refname" >&2 + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 exit 1 ;; esac -# Check if we've got anyone to send to -if [ -z "$recipients" ]; then - # If the email isn't sent, then at least give the user some idea of what command - # would generate the email at a later date - echo "*** No recipients found - no email will be sent, but the push will continue" >&2 - echo "*** for $0 $1 $2 $3" >&2 - exit 0 -fi - -# --- Email parameters -committer=$(git show --pretty=full -s $newrev | grep "^Commit: " | sed -e "s/^Commit: //") -describe=$(git describe $newrev 2>/dev/null) -if [ -z "$describe" ]; then - describe=$newrev -fi - -# --- Email (all stdout will be the email) -( -# Generate header -cat <<-EOF -From: $committer -To: $recipients -Subject: ${EMAILPREFIX}$projectdesc $refname_type, $short_refname now at $describe -X-Git-Refname: $refname -X-Git-Reftype: $refname_type -X-Git-Oldrev: $oldrev -X-Git-Newrev: $newrev - -Hello, - -This is an automated email from the git hooks/update script, it was -generated because a ref change was pushed to the repository. - -Updating $refname_type, $short_refname, -EOF - -case "$refname_type" in - "tracking branch"|branch) - if expr "$oldrev" : '0*$' >/dev/null - then - # If the old reference is "0000..0000" then this is a new branch - # and so oldrev is not valid - echo " as a new $refname_type" - echo " to $newrev ($newrev_type)" - echo "" - echo $LOGBEGIN - # This shows all log entries that are not already covered by - # another ref - i.e. commits that are now accessible from this - # ref that were previously not accessible - git log $newrev --not --all - echo $LOGEND - else - # oldrev is valid - oldrev_type=$(git-cat-file -t "$oldrev") - - # Now the problem is for cases like this: - # * --- * --- * --- * (oldrev) - # \ - # * --- * --- * (newrev) - # i.e. there is no guarantee that newrev is a strict subset - # of oldrev - (would have required a force, but that's allowed). - # So, we can't simply say rev-list $oldrev..$newrev. Instead - # we find the common base of the two revs and list from there - baserev=$(git-merge-base $oldrev $newrev) - - # Commit with a parent - for rev in $(git-rev-list $newrev --not $baserev --all) - do - revtype=$(git-cat-file -t "$rev") - echo " via $rev ($revtype)" - done - if [ "$baserev" = "$oldrev" ]; then - echo " from $oldrev ($oldrev_type)" - else - echo " based on $baserev" - echo " from $oldrev ($oldrev_type)" - echo "" - echo "This ref update crossed a branch point; i.e. the old rev is not a strict subset" - echo "of the new rev. This occurs, when you --force push a change in a situation" - echo "like this:" - echo "" - echo " * -- * -- B -- O -- O -- O ($oldrev)" - echo " \\" - echo " N -- N -- N ($newrev)" - echo "" - echo "Therefore, we assume that you've already had alert emails for all of the O" - echo "revisions, and now give you all the revisions in the N branch from the common" - echo "base, B ($baserev), up to the new revision." - fi - echo "" - echo $LOGBEGIN - git log $newrev --not $baserev --all - echo $LOGEND - echo "" - echo "Diffstat:" - git-diff-tree --no-color --stat -M -C --find-copies-harder $baserev..$newrev - fi - ;; - "annotated tag") - # Should we allow changes to annotated tags? - if expr "$oldrev" : '0*$' >/dev/null - then - # If the old reference is "0000..0000" then this is a new atag - # and so oldrev is not valid - echo " to $newrev ($newrev_type)" - else - echo " to $newrev ($newrev_type)" - echo " from $oldrev" - fi - - # If this tag succeeds another, then show which tag it replaces - prevtag=$(git describe --abbrev=0 $newrev^ 2>/dev/null) - if [ -n "$prevtag" ]; then - echo " replaces $prevtag" - fi - - # Read the tag details - eval $(git cat-file tag $newrev | \ - sed -n '4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p') - tagged=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds" +"$DATEFORMAT") - - echo " tagged by $tagger" - echo " on $tagged" - - echo "" - echo $LOGBEGIN - echo "" - - if [ -n "$prevtag" ]; then - git rev-list --pretty=short "$prevtag..$newrev" | git shortlog - else - git rev-list --pretty=short $newrev | git shortlog - fi - - echo $LOGEND - echo "" - ;; - *) - # By default, unannotated tags aren't allowed in; if - # they are though, it's debatable whether we would even want an - # email to be generated; however, I don't want to add another config - # option just for that. - # - # Unannotated tags are more about marking a point than releasing - # a version; therefore we don't do the shortlog summary that we - # do for annotated tags above - we simply show that the point has - # been marked, and print the log message for the marked point for - # reference purposes - # - # Note this section also catches any other reference type (although - # there aren't any) and deals with them in the same way. - if expr "$oldrev" : '0*$' >/dev/null - then - # If the old reference is "0000..0000" then this is a new tag - # and so oldrev is not valid - echo " as a new $refname_type" - echo " to $newrev ($newrev_type)" - else - echo " to $newrev ($newrev_type)" - echo " from $oldrev" - fi - echo "" - echo $LOGBEGIN - git-show --no-color --root -s $newrev - echo $LOGEND - echo "" - ;; -esac - -# Footer -cat <<-EOF - -hooks/update ---- -Git Source Code Management System -$0 $1 \\ - $2 \\ - $3 -EOF -#) | cat >&2 -) | /usr/sbin/sendmail -t - # --- Finished exit 0 -- cgit v1.2.3 From 5946d88a349407f2830b4d186201076b80a7cce4 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Mon, 16 Apr 2007 08:30:42 +0000 Subject: variable $projectdesc needs to be set before checking against unchanged default. Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- templates/hooks--update | 1 + 1 file changed, 1 insertion(+) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 0ff03309e6..0dcb1adb13 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -34,6 +34,7 @@ fi allowunannotated=$(git-repo-config --bool hooks.allowunannotated) # check for no description +projectdesc=$(sed -e '1p' "$GIT_DIR/description") if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb" ]; then echo "*** Project description file hasn't been set" >&2 exit 1 -- cgit v1.2.3 From 91776491da19f1b72e1cd192c9ea42bb1aae4415 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Mon, 16 Apr 2007 08:31:35 +0000 Subject: Have sample update hook not refuse deleting a branch through push. source ref might be 0000...0000 to delete a branch through git-push, 'git push :'. The update hook should not decline this. Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- templates/hooks--update | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 0dcb1adb13..9d3795c6d0 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -41,7 +41,12 @@ if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file t fi # --- Check types -newrev_type=$(git-cat-file -t $newrev) +# if $newrev is 0000...0000, it's a commit to delete a branch +if [ -z "${newrev##0*}" ]; then + newrev_type=commit +else + newrev_type=$(git-cat-file -t $newrev) +fi case "$refname","$newrev_type" in refs/tags/*,commit) -- cgit v1.2.3 From c32da692de332d3c9a0b283066e3786af00f4931 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 12 Sep 2007 23:36:03 +0200 Subject: hooks--update: Explicitly check for all zeros for a deleted ref. The previous check caused the hook to reject as unannotated any tag whose SHA1 starts with a zero. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- templates/hooks--update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 9d3795c6d0..d8c76264be 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -42,7 +42,7 @@ fi # --- Check types # if $newrev is 0000...0000, it's a commit to delete a branch -if [ -z "${newrev##0*}" ]; then +if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then newrev_type=commit else newrev_type=$(git-cat-file -t $newrev) -- cgit v1.2.3 From 1756fed9ee849c687f92cac30d86d2955d8c94c4 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Thu, 8 Nov 2007 14:02:00 +0000 Subject: hooks--update: fix test for properly set up project description file The update hook template intends to abort if the project description file hasn't been adjusted or is empty. This patch fixes the check for 'being adjusted'. Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- templates/hooks--update | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index d8c76264be..7e4d6270a8 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -34,8 +34,8 @@ fi allowunannotated=$(git-repo-config --bool hooks.allowunannotated) # check for no description -projectdesc=$(sed -e '1p' "$GIT_DIR/description") -if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb" ]; then +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb." ]; then echo "*** Project description file hasn't been set" >&2 exit 1 fi -- cgit v1.2.3 From ad7638b2edbad05d5f5581ec76d49094d8ba9237 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Thu, 8 Nov 2007 09:47:39 +0000 Subject: hooks--update: decline deleting tags or branches by default, add config options Decline deleting tags or branches through git push : by default, support config options hooks.allowdeletetag, hooks.allowdeletebranch to override this per repository. Before this patch the update hook interpreted deleting a tag, no matter if annotated or not, through git push : as unannotated tag, and declined it by default, but with an unappropriate error message: $ git push origin :atag deleting 'refs/tags/atag' *** The un-annotated tag, atag, is not allowed in this repository *** Use 'git tag [ -a | -s ]' for tags you want to propagate. ng refs/tags/atag hook declined error: hooks/update exited with error code 1 error: hook declined to update refs/tags/atag error: failed to push to 'monolith:/git/qm/test-repo' Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- templates/hooks--update | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index 7e4d6270a8..bd93dd1977 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -10,6 +10,12 @@ # hooks.allowunannotated # This boolean sets whether unannotated tags will be allowed into the # repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. # # --- Command line @@ -32,6 +38,8 @@ fi # --- Config allowunannotated=$(git-repo-config --bool hooks.allowunannotated) +allowdeletebranch=$(git-repo-config --bool hooks.allowdeletebranch) +allowdeletetag=$(git-repo-config --bool hooks.allowdeletetag) # check for no description projectdesc=$(sed -e '1q' "$GIT_DIR/description") @@ -41,9 +49,9 @@ if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file t fi # --- Check types -# if $newrev is 0000...0000, it's a commit to delete a branch +# if $newrev is 0000...0000, it's a commit to delete a ref. if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then - newrev_type=commit + newrev_type=delete else newrev_type=$(git-cat-file -t $newrev) fi @@ -58,15 +66,36 @@ case "$refname","$newrev_type" in exit 1 fi ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; refs/tags/*,tag) # annotated tag ;; refs/heads/*,commit) # branch ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; refs/remotes/*,commit) # tracking branch ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; *) # Anything else (is there anything else?) echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 -- cgit v1.2.3 From 5c66d0d4580196094e80c552f141525759a8e249 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 17 Jan 2008 22:52:40 -0800 Subject: Officially deprecate repo-config. Signed-off-by: Junio C Hamano --- templates/hooks--update | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update index bd93dd1977..4b69268fd0 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -37,9 +37,9 @@ if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then fi # --- Config -allowunannotated=$(git-repo-config --bool hooks.allowunannotated) -allowdeletebranch=$(git-repo-config --bool hooks.allowdeletebranch) -allowdeletetag=$(git-repo-config --bool hooks.allowdeletetag) +allowunannotated=$(git config --bool hooks.allowunannotated) +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +allowdeletetag=$(git config --bool hooks.allowdeletetag) # check for no description projectdesc=$(sed -e '1q' "$GIT_DIR/description") -- cgit v1.2.3 From f98f8cbac01e0d5dbb30660d7ea70af6a1439dfd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 24 Jun 2008 18:45:21 -0700 Subject: Ship sample hooks with .sample suffix We used to mark hooks we ship as samples by making them unexecutable, but some filesystems cannot tell what is executable and what is not. This makes it much more explicit. The hooks are suffixed with .sample (but now are made executable), so enabling it is still one step operation (instead of "chmod +x $hook", you would do "mv $hook.sample $hook") but now they won't get accidentally enabled on systems without executable bit. Signed-off-by: Junio C Hamano --- templates/hooks--update | 107 ------------------------------------------------ 1 file changed, 107 deletions(-) delete mode 100644 templates/hooks--update (limited to 'templates/hooks--update') diff --git a/templates/hooks--update b/templates/hooks--update deleted file mode 100644 index 4b69268fd0..0000000000 --- a/templates/hooks--update +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/sh -# -# An example hook script to blocks unannotated tags from entering. -# Called by git-receive-pack with arguments: refname sha1-old sha1-new -# -# To enable this hook, make this file executable by "chmod +x update". -# -# Config -# ------ -# hooks.allowunannotated -# This boolean sets whether unannotated tags will be allowed into the -# repository. By default they won't be. -# hooks.allowdeletetag -# This boolean sets whether deleting tags will be allowed in the -# repository. By default they won't be. -# hooks.allowdeletebranch -# This boolean sets whether deleting branches will be allowed in the -# repository. By default they won't be. -# - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "Usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --bool hooks.allowunannotated) -allowdeletebranch=$(git config --bool hooks.allowdeletebranch) -allowdeletetag=$(git config --bool hooks.allowdeletetag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb." ]; then - echo "*** Project description file hasn't been set" >&2 - exit 1 -fi - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then - newrev_type=delete -else - newrev_type=$(git-cat-file -t $newrev) -fi - -case "$refname","$newrev_type" in - refs/tags/*,commit) - # un-annotated tag - short_refname=${refname##refs/tags/} - if [ "$allowunannotated" != "true" ]; then - echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - ;; - refs/heads/*,commit) - # branch - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 -- cgit v1.2.3