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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 1, 2009, 00:03 UTC
Message-ID
<1235865822-14625-4-git-send-email-gitster@pobox.com>
In-Reply-To
<1235865822-14625-3-git-send-email-gitster@pobox.com>
This implements the requesting side of the pair.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-init-db.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 t/t0001-init.sh   |   12 ++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 9628803..18754d7 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,37 @@ static int guess_repository_type(const char *git_dir)
 	return 1;
 }
 
+static int remote_init(const char *remote, const char *init_serve,
+		       int argc, const char **argv)
+{
+	struct child_process *child;
+	int fd[2], i, len, status;
+	char line[1000];
+
+	if (!init_serve)
+		init_serve = "git init-serve";
+	child = git_connect(fd, remote, init_serve, 0);
+	for (i = 1; i < argc; i++) {
+		const char *arg = argv[i];
+		if (!prefixcmp(arg, "--remote=") ||
+		    !prefixcmp(arg, "--exec="))
+			continue;
+		packet_write(fd[1], "arg %s\n", 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')
+		status = error("%s", line);
+	status |= finish_connect(child);
+	return status;
+}
+
 static const char init_db_usage[] =
 "git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
 
@@ -378,6 +410,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 	const char *template_dir = NULL;
 	unsigned int flags = 0;
 	const char *shared_given = NULL;
+	const char *remote_given = NULL;
+	const char *exec_given = NULL;
 	int bare_given = 0;
 	int i;
 
@@ -394,10 +428,20 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 			shared_given = arg + 9;
 		else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
 			flags |= INIT_DB_QUIET;
+		else if (!prefixcmp(arg, "--remote="))
+			remote_given = arg + 9;
+		else if (!prefixcmp(arg, "--exec="))
+			exec_given = arg + 7;
 		else
 			usage(init_db_usage);
 	}
 
+	if (remote_given || exec_given) {
+		if (!remote_given)
+			die("--exec= without --remote=?");
+		return remote_init(remote_given, exec_given, argc, argv);
+	}
+
 	if (bare_given) {
 		static char git_dir[PATH_MAX+1];
 		is_bare_repository_cfg = 1;
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 5ac0a27..6f47930 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -199,4 +199,16 @@ 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" &&
+	test_must_fail git init --remote="$R" --bare --template=frotz &&
+	git init --remote="$R" --bare &&
+	test -d "$R/objects/pack" &&
+	test_must_fail git init --remote="$R" &&
+	rm -fr "$R" &&
+	test_must_fail git init --remote="$R" --exec="false is not git" &&
+	git init --remote="$R" --exec="$TEST_DIRECTORY/../git-init-serve" &&
+	test -d "$R/.git/objects/pack"
+'
+
 test_done
-- 
1.6.2.rc2.99.g9f3bb
Previous: Junio C HamanoNext: Jeff King
Message 4 of 43 in “Refactor list of environment variables to be sanitized”
  1. 1/4 Refactor list of environment variables to be sanitizedJunio C Hamano, Mar 1, 2009
  2. 2/4 git-init: inject some sanity to the option parserJunio C Hamano, Mar 1, 2009
  3. 3/4 Add init-serve, the remote side of "git init --remote=host:path"Junio C Hamano, Mar 1, 2009
  4. 4/4 "git init --remote=host:path"Junio C Hamano, Mar 1, 2009
  5. Jeff KingMar 1, 2009
  6. Junio C HamanoMar 1, 2009
  7. Jeff KingMar 1, 2009
  8. Shawn O. PearceMar 1, 2009
  9. Subject: [PATCH] Push to createJunio C Hamano, Mar 3, 2009
  10. Jay SoffianMar 3, 2009
  11. Jeff KingMar 3, 2009
  12. Jay SoffianMar 3, 2009
  13. Jay SoffianMar 3, 2009
  14. Junio C HamanoMar 3, 2009
  15. Jay SoffianMar 3, 2009
  16. Junio C HamanoMar 3, 2009
  17. Junio C HamanoMar 3, 2009
  18. Jay SoffianMar 3, 2009
  19. Jeff KingMar 3, 2009
  20. Jay SoffianMar 3, 2009
  21. Jeff KingMar 4, 2009
  22. Junio C HamanoMar 4, 2009
  23. Jay SoffianMar 4, 2009
  24. Junio C HamanoMar 3, 2009
  25. Jeff KingMar 3, 2009
  26. Junio C HamanoMar 3, 2009
  27. Jeff KingMar 3, 2009
  28. Junio C HamanoMar 3, 2009
  29. Jay SoffianMar 3, 2009
  30. Theodore TsoMar 3, 2009
  31. Johannes SchindelinMar 3, 2009
  32. Theodore TsoMar 4, 2009
  33. Miles BaderMar 6, 2009
  34. Shawn O. PearceMar 3, 2009
  35. 1/2 improve missing repository error messageJeff King, Mar 4, 2009
  36. Matthieu MoyMar 4, 2009
  37. Jeff KingMar 4, 2009
  38. Shawn O. PearceMar 4, 2009
  39. Jeff KingMar 5, 2009
  40. 2/2 make remote hangup warnings more friendlyJeff King, Mar 4, 2009
  41. Shawn O. PearceMar 4, 2009
  42. Jeff KingMar 5, 2009
  43. Daniel BarkalowMar 3, 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.