.git/hooks/update.sample
author Pascal Volk <user@localhost.localdomain.org>
Sun, 21 Nov 2021 22:04:40 +0000
changeset 762 0147c0a9ce2b
permissions -rwxr-xr-x
Added a README and the files of the empty vmm.git Simply `git pull` it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
762
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     1
#!/bin/sh
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     2
#
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     3
# An example hook script to block unannotated tags from entering.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     4
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     5
#
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     6
# To enable this hook, rename this file to "update".
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     7
#
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     8
# Config
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
     9
# ------
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    10
# hooks.allowunannotated
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    11
#   This boolean sets whether unannotated tags will be allowed into the
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    12
#   repository.  By default they won't be.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    13
# hooks.allowdeletetag
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    14
#   This boolean sets whether deleting tags will be allowed in the
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    15
#   repository.  By default they won't be.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    16
# hooks.allowmodifytag
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    17
#   This boolean sets whether a tag may be modified after creation. By default
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    18
#   it won't be.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    19
# hooks.allowdeletebranch
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    20
#   This boolean sets whether deleting branches will be allowed in the
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    21
#   repository.  By default they won't be.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    22
# hooks.denycreatebranch
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    23
#   This boolean sets whether remotely creating branches will be denied
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    24
#   in the repository.  By default this is allowed.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    25
#
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    26
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    27
# --- Command line
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    28
refname="$1"
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    29
oldrev="$2"
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    30
newrev="$3"
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    31
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    32
# --- Safety check
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    33
if [ -z "$GIT_DIR" ]; then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    34
	echo "Don't run this script from the command line." >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    35
	echo " (if you want, you could supply GIT_DIR then run" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    36
	echo "  $0 <ref> <oldrev> <newrev>)" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    37
	exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    38
fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    39
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    40
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    41
	echo "usage: $0 <ref> <oldrev> <newrev>" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    42
	exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    43
fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    44
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    45
# --- Config
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    46
allowunannotated=$(git config --type=bool hooks.allowunannotated)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    47
allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    48
denycreatebranch=$(git config --type=bool hooks.denycreatebranch)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    49
allowdeletetag=$(git config --type=bool hooks.allowdeletetag)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    50
allowmodifytag=$(git config --type=bool hooks.allowmodifytag)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    51
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    52
# check for no description
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    53
projectdesc=$(sed -e '1q' "$GIT_DIR/description")
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    54
case "$projectdesc" in
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    55
"Unnamed repository"* | "")
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    56
	echo "*** Project description file hasn't been set" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    57
	exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    58
	;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    59
esac
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    60
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    61
# --- Check types
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    62
# if $newrev is 0000...0000, it's a commit to delete a ref.
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    63
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    64
if [ "$newrev" = "$zero" ]; then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    65
	newrev_type=delete
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    66
else
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    67
	newrev_type=$(git cat-file -t $newrev)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    68
fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    69
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    70
case "$refname","$newrev_type" in
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    71
	refs/tags/*,commit)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    72
		# un-annotated tag
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    73
		short_refname=${refname##refs/tags/}
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    74
		if [ "$allowunannotated" != "true" ]; then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    75
			echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    76
			echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    77
			exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    78
		fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    79
		;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    80
	refs/tags/*,delete)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    81
		# delete tag
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    82
		if [ "$allowdeletetag" != "true" ]; then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    83
			echo "*** Deleting a tag is not allowed in this repository" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    84
			exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    85
		fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    86
		;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    87
	refs/tags/*,tag)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    88
		# annotated tag
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    89
		if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    90
		then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    91
			echo "*** Tag '$refname' already exists." >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    92
			echo "*** Modifying a tag is not allowed in this repository." >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    93
			exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    94
		fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    95
		;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    96
	refs/heads/*,commit)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    97
		# branch
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    98
		if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
    99
			echo "*** Creating a branch is not allowed in this repository" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   100
			exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   101
		fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   102
		;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   103
	refs/heads/*,delete)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   104
		# delete branch
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   105
		if [ "$allowdeletebranch" != "true" ]; then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   106
			echo "*** Deleting a branch is not allowed in this repository" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   107
			exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   108
		fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   109
		;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   110
	refs/remotes/*,commit)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   111
		# tracking branch
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   112
		;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   113
	refs/remotes/*,delete)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   114
		# delete tracking branch
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   115
		if [ "$allowdeletebranch" != "true" ]; then
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   116
			echo "*** Deleting a tracking branch is not allowed in this repository" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   117
			exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   118
		fi
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   119
		;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   120
	*)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   121
		# Anything else (is there anything else?)
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   122
		echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   123
		exit 1
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   124
		;;
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   125
esac
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   126
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   127
# --- Finished
0147c0a9ce2b Added a README and the files of the empty vmm.git
Pascal Volk <user@localhost.localdomain.org>
parents:
diff changeset
   128
exit 0