···11-#!/bin/sh
22-#
33-# An example hook script to check the commit log message taken by
44-# applypatch from an e-mail message.
55-#
66-# The hook should exit with non-zero status after issuing an
77-# appropriate message if it wants to stop the commit. The hook is
88-# allowed to edit the commit message file.
99-#
1010-# To enable this hook, rename this file to "applypatch-msg".
1111-1212-. git-sh-setup
1313-commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
1414-test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
1515-:
···11-#!/bin/sh
22-#
33-# An example hook script to check the commit log message.
44-# Called by "git commit" with one argument, the name of the file
55-# that has the commit message. The hook should exit with non-zero
66-# status after issuing an appropriate message if it wants to stop the
77-# commit. The hook is allowed to edit the commit message file.
88-#
99-# To enable this hook, rename this file to "commit-msg".
1010-1111-# Uncomment the below to add a Signed-off-by line to the message.
1212-# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
1313-# hook is more suited to it.
1414-#
1515-# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
1616-# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
1717-1818-# This example catches duplicate Signed-off-by lines.
1919-2020-test "" = "$(grep '^Signed-off-by: ' "$1" |
2121- sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
2222- echo >&2 Duplicate Signed-off-by lines.
2323- exit 1
2424-}
···11-#!/usr/bin/perl
22-33-use strict;
44-use warnings;
55-use IPC::Open2;
66-77-# An example hook script to integrate Watchman
88-# (https://facebook.github.io/watchman/) with git to speed up detecting
99-# new and modified files.
1010-#
1111-# The hook is passed a version (currently 2) and last update token
1212-# formatted as a string and outputs to stdout a new update token and
1313-# all files that have been modified since the update token. Paths must
1414-# be relative to the root of the working tree and separated by a single NUL.
1515-#
1616-# To enable this hook, rename this file to "query-watchman" and set
1717-# 'git config core.fsmonitor .git/hooks/query-watchman'
1818-#
1919-my ($version, $last_update_token) = @ARGV;
2020-2121-# Uncomment for debugging
2222-# print STDERR "$0 $version $last_update_token\n";
2323-2424-# Check the hook interface version
2525-if ($version ne 2) {
2626- die "Unsupported query-fsmonitor hook version '$version'.\n" .
2727- "Falling back to scanning...\n";
2828-}
2929-3030-my $git_work_tree = get_working_dir();
3131-3232-my $retry = 1;
3333-3434-my $json_pkg;
3535-eval {
3636- require JSON::XS;
3737- $json_pkg = "JSON::XS";
3838- 1;
3939-} or do {
4040- require JSON::PP;
4141- $json_pkg = "JSON::PP";
4242-};
4343-4444-launch_watchman();
4545-4646-sub launch_watchman {
4747- my $o = watchman_query();
4848- if (is_work_tree_watched($o)) {
4949- output_result($o->{clock}, @{$o->{files}});
5050- }
5151-}
5252-5353-sub output_result {
5454- my ($clockid, @files) = @_;
5555-5656- # Uncomment for debugging watchman output
5757- # open (my $fh, ">", ".git/watchman-output.out");
5858- # binmode $fh, ":utf8";
5959- # print $fh "$clockid\n@files\n";
6060- # close $fh;
6161-6262- binmode STDOUT, ":utf8";
6363- print $clockid;
6464- print "\0";
6565- local $, = "\0";
6666- print @files;
6767-}
6868-6969-sub watchman_clock {
7070- my $response = qx/watchman clock "$git_work_tree"/;
7171- die "Failed to get clock id on '$git_work_tree'.\n" .
7272- "Falling back to scanning...\n" if $? != 0;
7373-7474- return $json_pkg->new->utf8->decode($response);
7575-}
7676-7777-sub watchman_query {
7878- my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
7979- or die "open2() failed: $!\n" .
8080- "Falling back to scanning...\n";
8181-8282- # In the query expression below we're asking for names of files that
8383- # changed since $last_update_token but not from the .git folder.
8484- #
8585- # To accomplish this, we're using the "since" generator to use the
8686- # recency index to select candidate nodes and "fields" to limit the
8787- # output to file names only. Then we're using the "expression" term to
8888- # further constrain the results.
8989- my $last_update_line = "";
9090- if (substr($last_update_token, 0, 1) eq "c") {
9191- $last_update_token = "\"$last_update_token\"";
9292- $last_update_line = qq[\n"since": $last_update_token,];
9393- }
9494- my $query = <<" END";
9595- ["query", "$git_work_tree", {$last_update_line
9696- "fields": ["name"],
9797- "expression": ["not", ["dirname", ".git"]]
9898- }]
9999- END
100100-101101- # Uncomment for debugging the watchman query
102102- # open (my $fh, ">", ".git/watchman-query.json");
103103- # print $fh $query;
104104- # close $fh;
105105-106106- print CHLD_IN $query;
107107- close CHLD_IN;
108108- my $response = do {local $/; <CHLD_OUT>};
109109-110110- # Uncomment for debugging the watch response
111111- # open ($fh, ">", ".git/watchman-response.json");
112112- # print $fh $response;
113113- # close $fh;
114114-115115- die "Watchman: command returned no output.\n" .
116116- "Falling back to scanning...\n" if $response eq "";
117117- die "Watchman: command returned invalid output: $response\n" .
118118- "Falling back to scanning...\n" unless $response =~ /^\{/;
119119-120120- return $json_pkg->new->utf8->decode($response);
121121-}
122122-123123-sub is_work_tree_watched {
124124- my ($output) = @_;
125125- my $error = $output->{error};
126126- if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) {
127127- $retry--;
128128- my $response = qx/watchman watch "$git_work_tree"/;
129129- die "Failed to make watchman watch '$git_work_tree'.\n" .
130130- "Falling back to scanning...\n" if $? != 0;
131131- $output = $json_pkg->new->utf8->decode($response);
132132- $error = $output->{error};
133133- die "Watchman: $error.\n" .
134134- "Falling back to scanning...\n" if $error;
135135-136136- # Uncomment for debugging watchman output
137137- # open (my $fh, ">", ".git/watchman-output.out");
138138- # close $fh;
139139-140140- # Watchman will always return all files on the first query so
141141- # return the fast "everything is dirty" flag to git and do the
142142- # Watchman query just to get it over with now so we won't pay
143143- # the cost in git to look up each individual file.
144144- my $o = watchman_clock();
145145- $error = $output->{error};
146146-147147- die "Watchman: $error.\n" .
148148- "Falling back to scanning...\n" if $error;
149149-150150- output_result($o->{clock}, ("/"));
151151- $last_update_token = $o->{clock};
152152-153153- eval { launch_watchman() };
154154- return 0;
155155- }
156156-157157- die "Watchman: $error.\n" .
158158- "Falling back to scanning...\n" if $error;
159159-160160- return 1;
161161-}
162162-163163-sub get_working_dir {
164164- my $working_dir;
165165- if ($^O =~ 'msys' || $^O =~ 'cygwin') {
166166- $working_dir = Win32::GetCwd();
167167- $working_dir =~ tr/\\/\//;
168168- } else {
169169- require Cwd;
170170- $working_dir = Cwd::cwd();
171171- }
172172-173173- return $working_dir;
174174-}
···11-#!/bin/sh
22-#
33-# An example hook script to prepare a packed repository for use over
44-# dumb transports.
55-#
66-# To enable this hook, rename this file to "post-update".
77-88-exec git update-server-info
···11-#!/bin/sh
22-#
33-# An example hook script to verify what is about to be committed
44-# by applypatch from an e-mail message.
55-#
66-# The hook should exit with non-zero status after issuing an
77-# appropriate message if it wants to stop the commit.
88-#
99-# To enable this hook, rename this file to "pre-applypatch".
1010-1111-. git-sh-setup
1212-precommit="$(git rev-parse --git-path hooks/pre-commit)"
1313-test -x "$precommit" && exec "$precommit" ${1+"$@"}
1414-:
···11-#!/bin/sh
22-#
33-# An example hook script to verify what is about to be committed.
44-# Called by "git commit" with no arguments. The hook should
55-# exit with non-zero status after issuing an appropriate message if
66-# it wants to stop the commit.
77-#
88-# To enable this hook, rename this file to "pre-commit".
99-1010-if git rev-parse --verify HEAD >/dev/null 2>&1
1111-then
1212- against=HEAD
1313-else
1414- # Initial commit: diff against an empty tree object
1515- against=$(git hash-object -t tree /dev/null)
1616-fi
1717-1818-# If you want to allow non-ASCII filenames set this variable to true.
1919-allownonascii=$(git config --type=bool hooks.allownonascii)
2020-2121-# Redirect output to stderr.
2222-exec 1>&2
2323-2424-# Cross platform projects tend to avoid non-ASCII filenames; prevent
2525-# them from being added to the repository. We exploit the fact that the
2626-# printable range starts at the space character and ends with tilde.
2727-if [ "$allownonascii" != "true" ] &&
2828- # Note that the use of brackets around a tr range is ok here, (it's
2929- # even required, for portability to Solaris 10's /usr/bin/tr), since
3030- # the square bracket bytes happen to fall in the designated range.
3131- test $(git diff --cached --name-only --diff-filter=A -z $against |
3232- LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
3333-then
3434- cat <<\EOF
3535-Error: Attempt to add a non-ASCII file name.
3636-3737-This can cause problems if you want to work with people on other platforms.
3838-3939-To be portable it is advisable to rename the file.
4040-4141-If you know what you are doing you can disable this check using:
4242-4343- git config hooks.allownonascii true
4444-EOF
4545- exit 1
4646-fi
4747-4848-# If there are whitespace errors, print the offending file names and fail.
4949-exec git diff-index --check --cached $against --
···11-#!/bin/sh
22-#
33-# An example hook script to verify what is about to be committed.
44-# Called by "git merge" with no arguments. The hook should
55-# exit with non-zero status after issuing an appropriate message to
66-# stderr if it wants to stop the merge commit.
77-#
88-# To enable this hook, rename this file to "pre-merge-commit".
99-1010-. git-sh-setup
1111-test -x "$GIT_DIR/hooks/pre-commit" &&
1212- exec "$GIT_DIR/hooks/pre-commit"
1313-:
···11-#!/bin/sh
22-33-# An example hook script to verify what is about to be pushed. Called by "git
44-# push" after it has checked the remote status, but before anything has been
55-# pushed. If this script exits with a non-zero status nothing will be pushed.
66-#
77-# This hook is called with the following parameters:
88-#
99-# $1 -- Name of the remote to which the push is being done
1010-# $2 -- URL to which the push is being done
1111-#
1212-# If pushing without using a named remote those arguments will be equal.
1313-#
1414-# Information about the commits which are being pushed is supplied as lines to
1515-# the standard input in the form:
1616-#
1717-# <local ref> <local oid> <remote ref> <remote oid>
1818-#
1919-# This sample shows how to prevent push of commits where the log message starts
2020-# with "WIP" (work in progress).
2121-2222-remote="$1"
2323-url="$2"
2424-2525-zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
2626-2727-while read local_ref local_oid remote_ref remote_oid
2828-do
2929- if test "$local_oid" = "$zero"
3030- then
3131- # Handle delete
3232- :
3333- else
3434- if test "$remote_oid" = "$zero"
3535- then
3636- # New branch, examine all commits
3737- range="$local_oid"
3838- else
3939- # Update to existing branch, examine new commits
4040- range="$remote_oid..$local_oid"
4141- fi
4242-4343- # Check for WIP commit
4444- commit=$(git rev-list -n 1 --grep '^WIP' "$range")
4545- if test -n "$commit"
4646- then
4747- echo >&2 "Found WIP commit in $local_ref, not pushing"
4848- exit 1
4949- fi
5050- fi
5151-done
5252-5353-exit 0
···11-#!/bin/sh
22-#
33-# Copyright (c) 2006, 2008 Junio C Hamano
44-#
55-# The "pre-rebase" hook is run just before "git rebase" starts doing
66-# its job, and can prevent the command from running by exiting with
77-# non-zero status.
88-#
99-# The hook is called with the following parameters:
1010-#
1111-# $1 -- the upstream the series was forked from.
1212-# $2 -- the branch being rebased (or empty when rebasing the current branch).
1313-#
1414-# This sample shows how to prevent topic branches that are already
1515-# merged to 'next' branch from getting rebased, because allowing it
1616-# would result in rebasing already published history.
1717-1818-publish=next
1919-basebranch="$1"
2020-if test "$#" = 2
2121-then
2222- topic="refs/heads/$2"
2323-else
2424- topic=`git symbolic-ref HEAD` ||
2525- exit 0 ;# we do not interrupt rebasing detached HEAD
2626-fi
2727-2828-case "$topic" in
2929-refs/heads/??/*)
3030- ;;
3131-*)
3232- exit 0 ;# we do not interrupt others.
3333- ;;
3434-esac
3535-3636-# Now we are dealing with a topic branch being rebased
3737-# on top of master. Is it OK to rebase it?
3838-3939-# Does the topic really exist?
4040-git show-ref -q "$topic" || {
4141- echo >&2 "No such branch $topic"
4242- exit 1
4343-}
4444-4545-# Is topic fully merged to master?
4646-not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
4747-if test -z "$not_in_master"
4848-then
4949- echo >&2 "$topic is fully merged to master; better remove it."
5050- exit 1 ;# we could allow it, but there is no point.
5151-fi
5252-5353-# Is topic ever merged to next? If so you should not be rebasing it.
5454-only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
5555-only_next_2=`git rev-list ^master ${publish} | sort`
5656-if test "$only_next_1" = "$only_next_2"
5757-then
5858- not_in_topic=`git rev-list "^$topic" master`
5959- if test -z "$not_in_topic"
6060- then
6161- echo >&2 "$topic is already up to date with master"
6262- exit 1 ;# we could allow it, but there is no point.
6363- else
6464- exit 0
6565- fi
6666-else
6767- not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
6868- /usr/bin/perl -e '
6969- my $topic = $ARGV[0];
7070- my $msg = "* $topic has commits already merged to public branch:\n";
7171- my (%not_in_next) = map {
7272- /^([0-9a-f]+) /;
7373- ($1 => 1);
7474- } split(/\n/, $ARGV[1]);
7575- for my $elem (map {
7676- /^([0-9a-f]+) (.*)$/;
7777- [$1 => $2];
7878- } split(/\n/, $ARGV[2])) {
7979- if (!exists $not_in_next{$elem->[0]}) {
8080- if ($msg) {
8181- print STDERR $msg;
8282- undef $msg;
8383- }
8484- print STDERR " $elem->[1]\n";
8585- }
8686- }
8787- ' "$topic" "$not_in_next" "$not_in_master"
8888- exit 1
8989-fi
9090-9191-<<\DOC_END
9292-9393-This sample hook safeguards topic branches that have been
9494-published from being rewound.
9595-9696-The workflow assumed here is:
9797-9898- * Once a topic branch forks from "master", "master" is never
9999- merged into it again (either directly or indirectly).
100100-101101- * Once a topic branch is fully cooked and merged into "master",
102102- it is deleted. If you need to build on top of it to correct
103103- earlier mistakes, a new topic branch is created by forking at
104104- the tip of the "master". This is not strictly necessary, but
105105- it makes it easier to keep your history simple.
106106-107107- * Whenever you need to test or publish your changes to topic
108108- branches, merge them into "next" branch.
109109-110110-The script, being an example, hardcodes the publish branch name
111111-to be "next", but it is trivial to make it configurable via
112112-$GIT_DIR/config mechanism.
113113-114114-With this workflow, you would want to know:
115115-116116-(1) ... if a topic branch has ever been merged to "next". Young
117117- topic branches can have stupid mistakes you would rather
118118- clean up before publishing, and things that have not been
119119- merged into other branches can be easily rebased without
120120- affecting other people. But once it is published, you would
121121- not want to rewind it.
122122-123123-(2) ... if a topic branch has been fully merged to "master".
124124- Then you can delete it. More importantly, you should not
125125- build on top of it -- other people may already want to
126126- change things related to the topic as patches against your
127127- "master", so if you need further changes, it is better to
128128- fork the topic (perhaps with the same name) afresh from the
129129- tip of "master".
130130-131131-Let's look at this example:
132132-133133- o---o---o---o---o---o---o---o---o---o "next"
134134- / / / /
135135- / a---a---b A / /
136136- / / / /
137137- / / c---c---c---c B /
138138- / / / \ /
139139- / / / b---b C \ /
140140- / / / / \ /
141141- ---o---o---o---o---o---o---o---o---o---o---o "master"
142142-143143-144144-A, B and C are topic branches.
145145-146146- * A has one fix since it was merged up to "next".
147147-148148- * B has finished. It has been fully merged up to "master" and "next",
149149- and is ready to be deleted.
150150-151151- * C has not merged to "next" at all.
152152-153153-We would want to allow C to be rebased, refuse A, and encourage
154154-B to be deleted.
155155-156156-To compute (1):
157157-158158- git rev-list ^master ^topic next
159159- git rev-list ^master next
160160-161161- if these match, topic has not merged in next at all.
162162-163163-To compute (2):
164164-165165- git rev-list master..topic
166166-167167- if this is empty, it is fully merged to "master".
168168-169169-DOC_END
···11-#!/bin/sh
22-#
33-# An example hook script to make use of push options.
44-# The example simply echoes all push options that start with 'echoback='
55-# and rejects all pushes when the "reject" push option is used.
66-#
77-# To enable this hook, rename this file to "pre-receive".
88-99-if test -n "$GIT_PUSH_OPTION_COUNT"
1010-then
1111- i=0
1212- while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"
1313- do
1414- eval "value=\$GIT_PUSH_OPTION_$i"
1515- case "$value" in
1616- echoback=*)
1717- echo "echo from the pre-receive-hook: ${value#*=}" >&2
1818- ;;
1919- reject)
2020- exit 1
2121- esac
2222- i=$((i + 1))
2323- done
2424-fi
···11-#!/bin/sh
22-#
33-# An example hook script to prepare the commit log message.
44-# Called by "git commit" with the name of the file that has the
55-# commit message, followed by the description of the commit
66-# message's source. The hook's purpose is to edit the commit
77-# message file. If the hook fails with a non-zero status,
88-# the commit is aborted.
99-#
1010-# To enable this hook, rename this file to "prepare-commit-msg".
1111-1212-# This hook includes three examples. The first one removes the
1313-# "# Please enter the commit message..." help message.
1414-#
1515-# The second includes the output of "git diff --name-status -r"
1616-# into the message, just before the "git status" output. It is
1717-# commented because it doesn't cope with --amend or with squashed
1818-# commits.
1919-#
2020-# The third example adds a Signed-off-by line to the message, that can
2121-# still be edited. This is rarely a good idea.
2222-2323-COMMIT_MSG_FILE=$1
2424-COMMIT_SOURCE=$2
2525-SHA1=$3
2626-2727-/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
2828-2929-# case "$COMMIT_SOURCE,$SHA1" in
3030-# ,|template,)
3131-# /usr/bin/perl -i.bak -pe '
3232-# print "\n" . `git diff --cached --name-status -r`
3333-# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
3434-# *) ;;
3535-# esac
3636-3737-# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
3838-# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
3939-# if test -z "$COMMIT_SOURCE"
4040-# then
4141-# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
4242-# fi
···11-#!/bin/sh
22-33-# An example hook script to update a checked-out tree on a git push.
44-#
55-# This hook is invoked by git-receive-pack(1) when it reacts to git
66-# push and updates reference(s) in its repository, and when the push
77-# tries to update the branch that is currently checked out and the
88-# receive.denyCurrentBranch configuration variable is set to
99-# updateInstead.
1010-#
1111-# By default, such a push is refused if the working tree and the index
1212-# of the remote repository has any difference from the currently
1313-# checked out commit; when both the working tree and the index match
1414-# the current commit, they are updated to match the newly pushed tip
1515-# of the branch. This hook is to be used to override the default
1616-# behaviour; however the code below reimplements the default behaviour
1717-# as a starting point for convenient modification.
1818-#
1919-# The hook receives the commit with which the tip of the current
2020-# branch is going to be updated:
2121-commit=$1
2222-2323-# It can exit with a non-zero status to refuse the push (when it does
2424-# so, it must not modify the index or the working tree).
2525-die () {
2626- echo >&2 "$*"
2727- exit 1
2828-}
2929-3030-# Or it can make any necessary changes to the working tree and to the
3131-# index to bring them to the desired state when the tip of the current
3232-# branch is updated to the new commit, and exit with a zero status.
3333-#
3434-# For example, the hook can simply run git read-tree -u -m HEAD "$1"
3535-# in order to emulate git fetch that is run in the reverse direction
3636-# with git push, as the two-tree form of git read-tree -u -m is
3737-# essentially the same as git switch or git checkout that switches
3838-# branches while keeping the local changes in the working tree that do
3939-# not interfere with the difference between the branches.
4040-4141-# The below is a more-or-less exact translation to shell of the C code
4242-# for the default behaviour for git's push-to-checkout hook defined in
4343-# the push_to_deploy() function in builtin/receive-pack.c.
4444-#
4545-# Note that the hook will be executed from the repository directory,
4646-# not from the working tree, so if you want to perform operations on
4747-# the working tree, you will have to adapt your code accordingly, e.g.
4848-# by adding "cd .." or using relative paths.
4949-5050-if ! git update-index -q --ignore-submodules --refresh
5151-then
5252- die "Up-to-date check failed"
5353-fi
5454-5555-if ! git diff-files --quiet --ignore-submodules --
5656-then
5757- die "Working directory has unstaged changes"
5858-fi
5959-6060-# This is a rough translation of:
6161-#
6262-# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX
6363-if git cat-file -e HEAD 2>/dev/null
6464-then
6565- head=HEAD
6666-else
6767- head=$(git hash-object -t tree --stdin </dev/null)
6868-fi
6969-7070-if ! git diff-index --quiet --cached --ignore-submodules $head --
7171-then
7272- die "Working directory has staged changes"
7373-fi
7474-7575-if ! git read-tree -u -m "$commit"
7676-then
7777- die "Could not update working tree to new HEAD"
7878-fi
···11-#!/bin/sh
22-#
33-# An example hook script to block unannotated tags from entering.
44-# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
55-#
66-# To enable this hook, rename this file to "update".
77-#
88-# Config
99-# ------
1010-# hooks.allowunannotated
1111-# This boolean sets whether unannotated tags will be allowed into the
1212-# repository. By default they won't be.
1313-# hooks.allowdeletetag
1414-# This boolean sets whether deleting tags will be allowed in the
1515-# repository. By default they won't be.
1616-# hooks.allowmodifytag
1717-# This boolean sets whether a tag may be modified after creation. By default
1818-# it won't be.
1919-# hooks.allowdeletebranch
2020-# This boolean sets whether deleting branches will be allowed in the
2121-# repository. By default they won't be.
2222-# hooks.denycreatebranch
2323-# This boolean sets whether remotely creating branches will be denied
2424-# in the repository. By default this is allowed.
2525-#
2626-2727-# --- Command line
2828-refname="$1"
2929-oldrev="$2"
3030-newrev="$3"
3131-3232-# --- Safety check
3333-if [ -z "$GIT_DIR" ]; then
3434- echo "Don't run this script from the command line." >&2
3535- echo " (if you want, you could supply GIT_DIR then run" >&2
3636- echo " $0 <ref> <oldrev> <newrev>)" >&2
3737- exit 1
3838-fi
3939-4040-if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
4141- echo "usage: $0 <ref> <oldrev> <newrev>" >&2
4242- exit 1
4343-fi
4444-4545-# --- Config
4646-allowunannotated=$(git config --type=bool hooks.allowunannotated)
4747-allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch)
4848-denycreatebranch=$(git config --type=bool hooks.denycreatebranch)
4949-allowdeletetag=$(git config --type=bool hooks.allowdeletetag)
5050-allowmodifytag=$(git config --type=bool hooks.allowmodifytag)
5151-5252-# check for no description
5353-projectdesc=$(sed -e '1q' "$GIT_DIR/description")
5454-case "$projectdesc" in
5555-"Unnamed repository"* | "")
5656- echo "*** Project description file hasn't been set" >&2
5757- exit 1
5858- ;;
5959-esac
6060-6161-# --- Check types
6262-# if $newrev is 0000...0000, it's a commit to delete a ref.
6363-zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
6464-if [ "$newrev" = "$zero" ]; then
6565- newrev_type=delete
6666-else
6767- newrev_type=$(git cat-file -t $newrev)
6868-fi
6969-7070-case "$refname","$newrev_type" in
7171- refs/tags/*,commit)
7272- # un-annotated tag
7373- short_refname=${refname##refs/tags/}
7474- if [ "$allowunannotated" != "true" ]; then
7575- echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
7676- echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
7777- exit 1
7878- fi
7979- ;;
8080- refs/tags/*,delete)
8181- # delete tag
8282- if [ "$allowdeletetag" != "true" ]; then
8383- echo "*** Deleting a tag is not allowed in this repository" >&2
8484- exit 1
8585- fi
8686- ;;
8787- refs/tags/*,tag)
8888- # annotated tag
8989- if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
9090- then
9191- echo "*** Tag '$refname' already exists." >&2
9292- echo "*** Modifying a tag is not allowed in this repository." >&2
9393- exit 1
9494- fi
9595- ;;
9696- refs/heads/*,commit)
9797- # branch
9898- if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
9999- echo "*** Creating a branch is not allowed in this repository" >&2
100100- exit 1
101101- fi
102102- ;;
103103- refs/heads/*,delete)
104104- # delete branch
105105- if [ "$allowdeletebranch" != "true" ]; then
106106- echo "*** Deleting a branch is not allowed in this repository" >&2
107107- exit 1
108108- fi
109109- ;;
110110- refs/remotes/*,commit)
111111- # tracking branch
112112- ;;
113113- refs/remotes/*,delete)
114114- # delete tracking branch
115115- if [ "$allowdeletebranch" != "true" ]; then
116116- echo "*** Deleting a tracking branch is not allowed in this repository" >&2
117117- exit 1
118118- fi
119119- ;;
120120- *)
121121- # Anything else (is there anything else?)
122122- echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
123123- exit 1
124124- ;;
125125-esac
126126-127127-# --- Finished
128128-exit 0