git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Krefting <peter@softwolves.pp.se>
To: Git <git@vger.kernel.org>
Subject: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.
Date: Fri, 12 Nov 2010 12:30:48 +0100	[thread overview]
Message-ID: <ba28273f7efb0fa3e403a8a9d7b923b61bb62ce3.1289561504.git.peter@softwolves.pp.se> (raw)
In-Reply-To: <cover.1289561504.git.peter@softwolves.pp.se>

If we pass a remote repository specification to git init, we should try
connecting to the remote and run git init there. Not all transports
can support this, so fall back to reporting an error message for those
that cannot.
---
 builtin/init-db.c |    9 +++++++++
 remote.c          |   11 +++++++++++
 remote.h          |    1 +
 3 files changed, 21 insertions(+), 0 deletions(-)

This one doesn't work. I am not sure getting this to work is even possible.

  $ ~/proj/git/git-init remote.server:/home/peter/foobartest.git
  bash: git-init: command not found
  error: cannot run ssh: No such file or directory

(it is the remote side that complains about not finding "git-init")

diff --git a/builtin/init-db.c b/builtin/init-db.c
index f80ff08..e7baf4a 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -7,6 +7,8 @@
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "parse-options.h"
+#include "remote.h"
+#include "transport.h"
 
 #ifndef DEFAULT_GIT_TEMPLATE_DIR
 #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -439,6 +441,13 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 				/*
 				 * We were passed a remote repository specification.
 				 */
+				struct remote *remote = remote_get_unconfigured(argv[0]);
+				struct transport *transport = transport_get(remote, argv[0]);
+				int fd[2];
+				fd[0] = 0;
+				fd[1] = 1;
+				if (0 == transport_connect(transport, argv[0], "git-init", fd))
+					return transport_disconnect(transport);
 				die("Cannot initialize remote repository '%s'", argv[0]);
 			} else if (!mkdir_tried) {
 				int saved;
diff --git a/remote.c b/remote.c
index 9143ec7..fa57689 100644
--- a/remote.c
+++ b/remote.c
@@ -722,6 +722,17 @@ struct remote *remote_get(const char *name)
 	return ret;
 }
 
+struct remote *remote_get_unconfigured(const char *remotespec)
+{
+	struct remote *ret = xcalloc(1, sizeof(struct remote));
+	if (!ret)
+		return NULL;
+	add_url_alias(ret, remotespec);
+	if (!valid_remote(ret))
+		return NULL;
+	return ret;
+}
+
 int remote_is_configured(const char *name)
 {
 	int i;
diff --git a/remote.h b/remote.h
index 888d7c1..eafa578 100644
--- a/remote.h
+++ b/remote.h
@@ -51,6 +51,7 @@ struct remote {
 };
 
 struct remote *remote_get(const char *name);
+struct remote *remote_get_unconfigured(const char *remotespec);
 int remote_is_configured(const char *name);
 
 typedef int each_remote_fn(struct remote *remote, void *priv);
-- 
1.7.3

  parent reply	other threads:[~2010-11-12 11:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-12 11:31 [PATCH 0/2] RFC: Better handling of git init remote-spec Peter Krefting
2010-11-12 11:27 ` [PATCH 1/2] [RFC] Detect attempts at calling git init specifying a remote repository Peter Krefting
2010-11-16 17:57   ` Junio C Hamano
2010-11-16 20:10     ` Peter Krefting
2010-11-12 11:30 ` Peter Krefting [this message]
2010-11-13 21:29   ` [PATCH 2/2] [WIP] Allow running git init on a remote repository specification Sverre Rabbelier
2010-11-16  5:33     ` Peter Krefting
2010-11-16 17:58       ` Junio C Hamano
2010-11-16 20:12         ` Peter Krefting

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ba28273f7efb0fa3e403a8a9d7b923b61bb62ce3.1289561504.git.peter@softwolves.pp.se \
    --to=peter@softwolves.pp.se \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).