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

[PATCH 2/2] [WIP] Allow running git init on a remote repository specification.

From
Peter Krefting <peter@softwolves.pp.se>
Date
Nov 12, 2010, 11:30 UTC
Message-ID
<ba28273f7efb0fa3e403a8a9d7b923b61bb62ce3.1289561504.git.peter@softwolves.pp.se>
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
Previous: Peter KreftingNext: Sverre Rabbelier
Message 5 of 9 in “RFC: Better handling of git init remote-spec”
  1. 0/2 RFC: Better handling of git init remote-specPeter Krefting, Nov 12, 2010
  2. 1/2 [RFC] Detect attempts at calling git init specifying a remote repository.Peter Krefting, Nov 12, 2010
  3. Junio C HamanoNov 16, 2010
  4. Peter KreftingNov 16, 2010
  5. 2/2 [WIP] Allow running git init on a remote repository specification.Peter Krefting, Nov 12, 2010
  6. Sverre RabbelierNov 13, 2010
  7. Peter KreftingNov 16, 2010
  8. Junio C HamanoNov 16, 2010
  9. Peter KreftingNov 16, 2010

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.