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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux