Skip to contentSkip to conversation

Install sample hooks

PATCH New Junio C Hamano 1 participant 1 message Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Install sample hooks

Josef Weidendorfer made a good suggestion to throw in sample hooks, disabled by default, to newly created repositories. Here is a proposed patch. I will advance it to the master branch if I do not hear objections, probably by the end of the week.

------------
A template mechanism to populate newly initialized repository with default set of files is introduced. Use it to ship example hooks that can be used for update and post update checks, as Josef Weidendorfer suggests.

---

 Makefile                     |    5 +
 cache.h                      |    4 +
 init-db.c                    |  142 ++++++++++++++++++++++++++++++++++++++++++
 templates/Makefile           |   19 ++++++
 templates/hooks--post-update |    8 ++
 templates/hooks--update      |   21 ++++++
 6 files changed, 199 insertions(+), 0 deletions(-)
 create mode 100644 templates/Makefile
 create mode 100644 templates/hooks--post-update
 create mode 100644 templates/hooks--update

a03cd67d2ff5dd0cf43a0be53e6f35e4cb684b8e

Makefile +5 -0
@@ -39,6 +39,8 @@ CFLAGS+=$(COPTS) -Wall $(DEFINES)
 
 prefix=$(HOME)
 bindir=$(prefix)/bin
+etcdir=$(prefix)/etc
+etcgitdir=$(etcdir)/git-core
 # dest=
 
 CC?=gcc
@@ -143,6 +145,7 @@ endif
 endif
 
 CFLAGS += '-DSHA1_HEADER=$(SHA1_HEADER)'
+CFLAGS += '-DDEFAULT_GIT_TEMPLATE_ENVIRONMENT="$(etcgitdir)/templates"'
 
 
 
@@ -195,6 +198,7 @@ check:
 install: $(PROG) $(SCRIPTS)
 	$(INSTALL) -m755 -d $(dest)$(bindir)
 	$(INSTALL) $(PROG) $(SCRIPTS) $(dest)$(bindir)
+	$(MAKE) -C templates install
 
 install-tools:
 	$(MAKE) -C tools install
@@ -235,4 +239,5 @@ clean:
 	rm -f git-core-*.tar.gz git-core.spec
 	$(MAKE) -C tools/ clean
 	$(MAKE) -C Documentation/ clean
+	$(MAKE) -C templates/ clean
 	$(MAKE) -C t/ clean
cache.h +4 -0
@@ -128,6 +128,10 @@ extern unsigned int active_nr, active_al
 #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
 #define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
 #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
+#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIRECTORY"
+#ifndef DEFAULT_GIT_TEMPLATE_ENVIRONMENT
+#define DEFAULT_GIT_TEMPLATE_ENVIRONMENT "/etc/git-core/templates"
+#endif
 
 extern char *get_object_directory(void);
 extern char *get_refs_directory(void);
init-db.c +142 -0

154 lines not on this page · raw message

templates/Makefile new file +19 -0
new file mode 100644
@@ -0,0 +1,19 @@
+# make
+
+INSTALL=install
+prefix=$(HOME)
+etcdir=$(prefix)/etc
+etcgitdir=$(etcdir)/git-core
+templatedir=$(etcgitdir)/templates
+# dest=
+
+all:
+clean:
+
+install:
+	$(INSTALL) -d -m755 $(dest)$(templatedir)/hooks/
+	$(foreach s,$(wildcard hooks--*),\
+		$(INSTALL) -m644 $s \
+		$(dest)$(templatedir)/hooks/$(patsubst hooks--%,%,$s);)
+	$(INSTALL) -d -m755 $(dest)$(templatedir)/info
+	$(INSTALL) -d -m755 $(dest)$(templatedir)/branches
templates/hooks--post-update new file +8 -0
new file mode 100644
@@ -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
templates/hooks--update new file +21 -0
new file mode 100644
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# An example hook script to mail out commit update information.
+#
+# To enable this hook:
+# (1) change the recipient e-mail address
+# (2) make this file executable by "chmod +x update".
+#
+
+recipient="[email protected]"
+
+if expr "$2" : '0*$' >/dev/null
+then
+	echo "Created a new ref, with the following commits:"
+	git-rev-list --pretty "$2"
+else
+	echo "New commits:"
+	git-rev-list --pretty "$3" "^$2"
+fi |
+mail -s "Changes to ref $1" "$recipient"
+exit 0