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

[PATCH 2/2] "git init --remote=host:path"

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 28, 2009, 21:13 UTC
Message-ID
<7vocwme03b.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7vsklye05k.fsf@gitster.siamese.dyndns.org>
This implements the requesting side of the pair.

It probably should take the same --exec=init-serve parameter similar to the way other programs like receive-pack and send-pack does, but I am too lazy to add it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-init-db.c |   34 +++++++++++++++++++++++++++++++++-
 t/t0001-init.sh   |    7 +++++++
 2 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index ee3911f..0b6da70 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "builtin.h"
 #include "exec_cmd.h"
+#include "pkt-line.h"
 
 #ifndef DEFAULT_GIT_TEMPLATE_DIR
 #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -363,6 +364,33 @@ static int guess_repository_type(const char *git_dir)
 	return 1;
 }
 
+static int remote_init(const char *remote, int argc, const char **argv)
+{
+	struct child_process *child;
+	int fd[2], i, len, status;
+	char line[1000];
+
+	child = git_connect(fd, remote, "git init-serve", 0);
+	for (i = 1; i < argc; i++) {
+		fprintf(stderr, "writing %d (%s)\n", i, argv[i]);
+		packet_write(fd[1], argv[i]);
+	}
+	packet_flush(fd[1]);
+
+	status = 0;
+	len = packet_read_line(fd[0], line, sizeof(line));
+	if (len < 3 ||
+	    (memcmp(line, "ok ", 3) && memcmp(line, "ng ", 3)))
+		die("protocol error: %s\n", line);
+
+	if (line[0] != 'o') {
+		error("%s", line);
+		status = -1;
+	}
+	status |= finish_connect(child);
+	return status;
+}
+
 static const char init_db_usage[] =
 "git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
 
@@ -394,7 +422,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 			init_shared_repository = git_config_perm("arg", arg+9);
 		else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
 			flags |= INIT_DB_QUIET;
-		else
+		else if (!prefixcmp(arg, "--remote=")) {
+			if (i != 1)
+				die("--remote option must be given first");
+			return remote_init(arg+9, argc-1, argv+1);
+		} else
 			usage(init_db_usage);
 	}
 
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 5ac0a27..d1069ee 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -199,4 +199,11 @@ test_expect_success 'init honors global core.sharedRepository' '
 	x`git config -f shared-honor-global/.git/config core.sharedRepository`
 '
 
+test_expect_success 'init --remote' '
+	R="$(pwd)/test-of-remote" &&
+	git init --remote="$R" --bare &&
+	test -d "$R/objects/pack" &&
+	test_must_fail git init --remote="$R"
+'
+
 test_done
-- 
1.6.2.rc2.99.g9f3bb
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 3 in “Add init-serve, the remote side of "git init --remote=host:path"”
  1. 1/2 Add init-serve, the remote side of "git init --remote=host:path"Junio C Hamano, Feb 28, 2009
  2. 2/2 "git init --remote=host:path"Junio C Hamano, Feb 28, 2009
  3. Junio C HamanoMar 1, 2009

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.