[PATCH 2/2] [WIP] Allow running git init on a remote repository specification.
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")
Show changes to 3 files +21 −0
builtin/init-db.c, remote.c, remote.h
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