git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Use the template mechanism to set up refs/ hierarchy as well.

From
Junio C Hamano <junkio@cox.net>
Date
Aug 3, 2005, 06:28 UTC
Message-ID
<7v3bprjzzg.fsf@assigned-by-dhcp.cox.net>

This may be controversial from the robustness standpoint, so I am placing it in the proposed update queue first. Discussions on the list very welcomed.

Once the alternate object pool mechanism is taught to use $GIT_DIR/info/alt file (instead of/in addition to the environment variable), this would help people setting up repositories for underling developers. They can prepare a standard template info/alt that points at the project-wide base object pool that is shared, and have people point GIT_TEMPLATE_DIRECTORY at the project standard template directory.

------------ This removes the hardcoded set of refs/ directory structure that is created by git-init-db and move it to the template mechanism.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 init-db.c            |   22 ----------------------
 t/t5400-send-pack.sh |   16 +++++++++++++++-
 templates/Makefile   |    4 ++++
 3 files changed, 19 insertions(+), 23 deletions(-)
de8b5bf5605274d29b835947932b9b6c109f5d9f
diff --git a/init-db.c b/init-db.c
--- a/init-db.c
+++ b/init-db.c
@@ -167,28 +167,6 @@ static void create_default_files(const c
 
 	if (len && path[len-1] != '/')
 		path[len++] = '/';
-
-	/*
-	 * Create .git/refs/{heads,tags}
-	 */
-	strcpy(path + len, "refs");
-	safe_create_dir(path);
-	strcpy(path + len, "refs/heads");
-	safe_create_dir(path);
-	strcpy(path + len, "refs/tags");
-	safe_create_dir(path);
-
-	/*
-	 * Create the default symlink from ".git/HEAD" to the "master"
-	 * branch
-	 */
-	strcpy(path + len, "HEAD");
-	if (symlink("refs/heads/master", path) < 0) {
-		if (errno != EEXIST) {
-			perror(path);
-			exit(1);
-		}
-	}
 	copy_templates(path);
 }
 
diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh
--- a/t/t5400-send-pack.sh
+++ b/t/t5400-send-pack.sh
@@ -8,6 +8,18 @@ test_description='See why rewinding head
 '
 . ./test-lib.sh
 
+# This part is needed to test before installing templates.
+mkdir -p templates/refs/heads
+ln -s refs/heads/master templates/HEAD
+mkdir -p templates/hooks
+echo '#!/bin/sh
+echo we are here >$GIT_DIR/we-are-here' >templates/hooks/post-update
+chmod +x templates/hooks/post-update
+
+GIT_TEMPLATE_DIRECTORY=`pwd`/templates/
+export GIT_TEMPLATE_DIRECTORY
+git-init-db
+
 cnt='1'
 test_expect_success setup '
 	tree=$(git-write-tree) &&
@@ -50,5 +62,7 @@ test_expect_success \
 	fi &&
 	# this should update
 	git-send-pack --force ./victim/.git/ master &&
-	cmp victim/.git/refs/heads/master .git/refs/heads/master
+	cmp victim/.git/refs/heads/master .git/refs/heads/master &&
+	# and post-update should have run
+	test -f victim/.git/we-are-here
 '
diff --git a/templates/Makefile b/templates/Makefile
--- a/templates/Makefile
+++ b/templates/Makefile
@@ -17,3 +17,7 @@ install:
 		$(dest)$(templatedir)/hooks/$(patsubst hooks--%,%,$s);)
 	$(INSTALL) -d -m755 $(dest)$(templatedir)/info
 	$(INSTALL) -d -m755 $(dest)$(templatedir)/branches
+	$(INSTALL) -d -m755 $(dest)$(templatedir)/refs/heads
+	$(INSTALL) -d -m755 $(dest)$(templatedir)/refs/tags
+	rm -f $(dest)$(templatedir)/HEAD && \
+	ln -s refs/heads/master $(dest)$(templatedir)/HEAD
Next: Johannes Schindelin
Message 1 of 10 in “Use the template mechanism to set up refs/ hierarchy as well.”
  1. Use the template mechanism to set up refs/ hierarchy as well.Junio C Hamano, Aug 3, 2005
  2. Johannes SchindelinAug 4, 2005
  3. Junio C HamanoAug 4, 2005
  4. Johannes SchindelinAug 4, 2005
  5. Junio C HamanoAug 4, 2005
  6. Johannes SchindelinAug 4, 2005
  7. Junio C HamanoAug 4, 2005
  8. Johannes SchindelinAug 5, 2005
  9. barkalow@iabervon.orgAug 4, 2005
  10. Junio C HamanoAug 5, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.