diff options
Diffstat (limited to 'templates')
-rw-r--r-- | templates/.gitignore | 2 | ||||
-rw-r--r-- | templates/Makefile | 46 | ||||
-rw-r--r-- | templates/branches-- | 1 | ||||
-rw-r--r-- | templates/hooks--applypatch-msg | 15 | ||||
-rw-r--r-- | templates/hooks--commit-msg | 22 | ||||
-rw-r--r-- | templates/hooks--post-commit | 8 | ||||
-rw-r--r-- | templates/hooks--post-update | 8 | ||||
-rw-r--r-- | templates/hooks--pre-applypatch | 15 | ||||
-rw-r--r-- | templates/hooks--pre-commit | 71 | ||||
-rw-r--r-- | templates/hooks--pre-rebase | 150 | ||||
-rw-r--r-- | templates/hooks--update | 285 | ||||
-rw-r--r-- | templates/info--exclude | 6 | ||||
-rw-r--r-- | templates/this--description | 1 |
13 files changed, 630 insertions, 0 deletions
diff --git a/templates/.gitignore b/templates/.gitignore new file mode 100644 index 0000000000..6759ecbf98 --- /dev/null +++ b/templates/.gitignore @@ -0,0 +1,2 @@ +blt +boilerplates.made diff --git a/templates/Makefile b/templates/Makefile new file mode 100644 index 0000000000..0eeee43feb --- /dev/null +++ b/templates/Makefile @@ -0,0 +1,46 @@ +# make and install sample templates + +INSTALL ?= install +TAR ?= tar +prefix ?= $(HOME) +template_dir ?= $(prefix)/share/git-core/templates/ +# DESTDIR= + +# Shell quote (do not use $(call) to accommodate ancient setups); +DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) +template_dir_SQ = $(subst ','\'',$(template_dir)) + +all: boilerplates.made custom + +# Put templates that can be copied straight from the source +# in a file direc--tory--file in the source. They will be +# just copied to the destination. + +bpsrc = $(filter-out %~,$(wildcard *--*)) +boilerplates.made : $(bpsrc) + ls *--* 2>/dev/null | \ + while read boilerplate; \ + do \ + case "$$boilerplate" in *~) continue ;; esac && \ + dst=`echo "$$boilerplate" | sed -e 's|^this|.|;s|--|/|g'` && \ + dir=`expr "$$dst" : '\(.*\)/'` && \ + mkdir -p blt/$$dir && \ + case "$$boilerplate" in \ + *--) ;; \ + *) cp $$boilerplate blt/$$dst ;; \ + esac || exit; \ + done || exit + date >$@ + +# If you need build-tailored templates, build them into blt/ +# directory yourself here. +custom: + : no custom templates yet + +clean: + rm -rf blt boilerplates.made + +install: all + $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(template_dir_SQ)' + (cd blt && $(TAR) cf - .) | \ + (cd '$(DESTDIR_SQ)$(template_dir_SQ)' && $(TAR) xf -) diff --git a/templates/branches-- b/templates/branches-- new file mode 100644 index 0000000000..fae88709a6 --- /dev/null +++ b/templates/branches-- @@ -0,0 +1 @@ +: this is just to ensure the directory exists. diff --git a/templates/hooks--applypatch-msg b/templates/hooks--applypatch-msg new file mode 100644 index 0000000000..02de1ef84c --- /dev/null +++ b/templates/hooks--applypatch-msg @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, make this file executable. + +. git-sh-setup +test -x "$GIT_DIR/hooks/commit-msg" && + exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"} +: diff --git a/templates/hooks--commit-msg b/templates/hooks--commit-msg new file mode 100644 index 0000000000..9b04f2d69c --- /dev/null +++ b/templates/hooks--commit-msg @@ -0,0 +1,22 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by git-commit with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, make this file executable. + +# Uncomment the below to add a Signed-off-by line to the message. +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} + diff --git a/templates/hooks--post-commit b/templates/hooks--post-commit new file mode 100644 index 0000000000..8be6f34ad9 --- /dev/null +++ b/templates/hooks--post-commit @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script that is called after a successful +# commit is made. +# +# To enable this hook, make this file executable. + +: Nothing diff --git a/templates/hooks--post-update b/templates/hooks--post-update new file mode 100644 index 0000000000..bcba8937bb --- /dev/null +++ b/templates/hooks--post-update @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, make this file executable by "chmod +x post-update". + +exec git-update-server-info diff --git a/templates/hooks--pre-applypatch b/templates/hooks--pre-applypatch new file mode 100644 index 0000000000..5f56ce8053 --- /dev/null +++ b/templates/hooks--pre-applypatch @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, make this file executable. + +. git-sh-setup +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"} +: + diff --git a/templates/hooks--pre-commit b/templates/hooks--pre-commit new file mode 100644 index 0000000000..723a9ef210 --- /dev/null +++ b/templates/hooks--pre-commit @@ -0,0 +1,71 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by git-commit with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, make this file executable. + +# This is slightly modified from Andrew Morton's Perfect Patch. +# Lines you introduce should not have trailing whitespace. +# Also check for an indentation that has SP before a TAB. + +if git-rev-parse --verify HEAD 2>/dev/null +then + git-diff-index -p -M --cached HEAD +else + # NEEDSWORK: we should produce a diff with an empty tree here + # if we want to do the same verification for the initial import. + : +fi | +perl -e ' + my $found_bad = 0; + my $filename; + my $reported_filename = ""; + my $lineno; + sub bad_line { + my ($why, $line) = @_; + if (!$found_bad) { + print STDERR "*\n"; + print STDERR "* You have some suspicious patch lines:\n"; + print STDERR "*\n"; + $found_bad = 1; + } + if ($reported_filename ne $filename) { + print STDERR "* In $filename\n"; + $reported_filename = $filename; + } + print STDERR "* $why (line $lineno)\n"; + print STDERR "$filename:$lineno:$line\n"; + } + while (<>) { + if (m|^diff --git a/(.*) b/\1$|) { + $filename = $1; + next; + } + if (/^@@ -\S+ \+(\d+)/) { + $lineno = $1 - 1; + next; + } + if (/^ /) { + $lineno++; + next; + } + if (s/^\+//) { + $lineno++; + chomp; + if (/\s$/) { + bad_line("trailing whitespace", $_); + } + if (/^\s* /) { + bad_line("indent SP followed by a TAB", $_); + } + if (/^(?:[<>=]){7}/) { + bad_line("unresolved merge conflict", $_); + } + } + } + exit($found_bad); +' + diff --git a/templates/hooks--pre-rebase b/templates/hooks--pre-rebase new file mode 100644 index 0000000000..981c454cda --- /dev/null +++ b/templates/hooks--pre-rebase @@ -0,0 +1,150 @@ +#!/bin/sh +# +# Copyright (c) 2006 Junio C Hamano +# + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` +fi + +case "$basebranch,$topic" in +master,refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Is topic fully merged to master? +not_in_master=`git-rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git-rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git-rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git-rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up-to-date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git-rev-list --pretty=oneline ^${publish} "$topic"` + perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +exit 0 + +################################################################ + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git-rev-list ^master ^topic next + git-rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git-rev-list master..topic + + if this is empty, it is fully merged to "master". diff --git a/templates/hooks--update b/templates/hooks--update new file mode 100644 index 0000000000..555bd5f532 --- /dev/null +++ b/templates/hooks--update @@ -0,0 +1,285 @@ +#!/bin/sh +# +# An example hook script to mail out commit update information. +# 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, 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" +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 <ref> <oldrev> <newrev>)" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "Usage: $0 <ref> <oldrev> <newrev>" >&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) + +# --- Check types +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 "*** 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 + 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-rev-parse --not --all | git-rev-list --stdin --pretty $newref + 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 + ;; + "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 "" + ;; + *) + # 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 diff --git a/templates/info--exclude b/templates/info--exclude new file mode 100644 index 0000000000..2c87b72dff --- /dev/null +++ b/templates/info--exclude @@ -0,0 +1,6 @@ +# git-ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/templates/this--description b/templates/this--description new file mode 100644 index 0000000000..c6f25e80b8 --- /dev/null +++ b/templates/this--description @@ -0,0 +1 @@ +Unnamed repository; edit this file to name it for gitweb. |