{"thread":{"id":"25725","subject":"[PATCH 1/2] [RFC] Detect attempts at calling git init specifying a remote repository.","startedAt":"2010-11-12T11:27:35Z","lastAt":"2010-11-16T20:12:46Z","messageCount":9,"participants":["Peter Krefting","Sverre Rabbelier","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"155772","messageId":"3f7d07a2b3a02c1d3f864d2a17f3b8808890a4d1.1289561504.git.peter@softwolves.pp.se","threadId":"25725","inReplyTo":"cover.1289561504.git.peter@softwolves.pp.se","subject":"[PATCH 1/2] [RFC] Detect attempts at calling git init specifying a remote repository.","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2010-11-12T11:27:35Z","receivedAt":"2010-11-12T11:27:35Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"We can only initialize local repositories, so bail out immediately if the\nuser tries to specify a remote repository.\n---\n builtin/init-db.c |    7 ++++++-\n 1 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 9d4886c..f80ff08 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -435,7 +435,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\tint mkdir_tried = 0;\n \tretry:\n \t\tif (chdir(argv[0]) < 0) {\n-\t\t\tif (!mkdir_tried) {\n+\t\t\tif (is_url(argv[0]) || strchr(argv[0], '@') != NULL || (strchr(argv[0], ':') != NULL && !has_dos_drive_prefix(argv[0]))) {\n+\t\t\t\t/*\n+\t\t\t\t * We were passed a remote repository specification.\n+\t\t\t\t */\n+\t\t\t\tdie(\"Cannot initialize remote repository '%s'\", argv[0]);\n+\t\t\t} else if (!mkdir_tried) {\n \t\t\t\tint saved;\n \t\t\t\t/*\n \t\t\t\t * At this point we haven't read any configuration,\n-- \n1.7.3\n"},{"id":"155774","messageId":"ba28273f7efb0fa3e403a8a9d7b923b61bb62ce3.1289561504.git.peter@softwolves.pp.se","threadId":"25725","inReplyTo":"cover.1289561504.git.peter@softwolves.pp.se","subject":"[PATCH 2/2] [WIP] Allow running git init on a remote repository specification.","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2010-11-12T11:30:48Z","receivedAt":"2010-11-12T11:30:48Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"If we pass a remote repository specification to git init, we should try\nconnecting to the remote and run git init there. Not all transports\ncan support this, so fall back to reporting an error message for those\nthat cannot.\n---\n builtin/init-db.c |    9 +++++++++\n remote.c          |   11 +++++++++++\n remote.h          |    1 +\n 3 files changed, 21 insertions(+), 0 deletions(-)\n\nThis one doesn't work. I am not sure getting this to work is even possible.\n\n  $ ~/proj/git/git-init remote.server:/home/peter/foobartest.git\n  bash: git-init: command not found\n  error: cannot run ssh: No such file or directory\n\n(it is the remote side that complains about not finding \"git-init\")\n\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex f80ff08..e7baf4a 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -7,6 +7,8 @@\n #include \"builtin.h\"\n #include \"exec_cmd.h\"\n #include \"parse-options.h\"\n+#include \"remote.h\"\n+#include \"transport.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n@@ -439,6 +441,13 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\t\t\t/*\n \t\t\t\t * We were passed a remote repository specification.\n \t\t\t\t */\n+\t\t\t\tstruct remote *remote = remote_get_unconfigured(argv[0]);\n+\t\t\t\tstruct transport *transport = transport_get(remote, argv[0]);\n+\t\t\t\tint fd[2];\n+\t\t\t\tfd[0] = 0;\n+\t\t\t\tfd[1] = 1;\n+\t\t\t\tif (0 == transport_connect(transport, argv[0], \"git-init\", fd))\n+\t\t\t\t\treturn transport_disconnect(transport);\n \t\t\t\tdie(\"Cannot initialize remote repository '%s'\", argv[0]);\n \t\t\t} else if (!mkdir_tried) {\n \t\t\t\tint saved;\ndiff --git a/remote.c b/remote.c\nindex 9143ec7..fa57689 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -722,6 +722,17 @@ struct remote *remote_get(const char *name)\n \treturn ret;\n }\n \n+struct remote *remote_get_unconfigured(const char *remotespec)\n+{\n+\tstruct remote *ret = xcalloc(1, sizeof(struct remote));\n+\tif (!ret)\n+\t\treturn NULL;\n+\tadd_url_alias(ret, remotespec);\n+\tif (!valid_remote(ret))\n+\t\treturn NULL;\n+\treturn ret;\n+}\n+\n int remote_is_configured(const char *name)\n {\n \tint i;\ndiff --git a/remote.h b/remote.h\nindex 888d7c1..eafa578 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -51,6 +51,7 @@ struct remote {\n };\n \n struct remote *remote_get(const char *name);\n+struct remote *remote_get_unconfigured(const char *remotespec);\n int remote_is_configured(const char *name);\n \n typedef int each_remote_fn(struct remote *remote, void *priv);\n-- \n1.7.3\n"},{"id":"155773","messageId":"cover.1289561504.git.peter@softwolves.pp.se","threadId":"25725","inReplyTo":null,"subject":"[PATCH 0/2] RFC: Better handling of git init remote-spec","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2010-11-12T11:31:44Z","receivedAt":"2010-11-12T11:31:44Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":">From time to time I forget myself and try to initialize a repository on a remote\nmachine by writing something like\n\n  git init --bare remote.machine:myrepo.git\n\njust to get a local directory called \"remote.machine:myrepo.git\" set up.\n\nOr, even worse, a\n\n  git init --bare ssh://remote.machine/myrepo.git\n\nThese patches try to fix this. The first patch tries to detect if a remote\nrepository specification was supplied, and just stop with an error message.\nThat one is fairly safe.\n\nThe second one I haven't got working yet, but I have the beginnings of a\npatch that actually tries to run \"git-init\" on the remote repository. Any\nideas on how to get this actually working (it should be possible for the\n\"ssh\" transport at least) are welcome.\n\nPeter Krefting (2):\n  Detect attempts at calling git init specifying a remote repository.\n  WIP: Allow running git init on a remote repository specification.\n\n builtin/init-db.c |   16 +++++++++++++++-\n remote.c          |   11 +++++++++++\n remote.h          |    1 +\n 3 files changed, 27 insertions(+), 1 deletions(-)\n\n-- \n1.7.3\n"},{"id":"155833","messageId":"AANLkTimqLeyDW9sJVR8NPOXQ1Xdz+kRmu9-8fPn1yj_j@mail.gmail.com","threadId":"25725","inReplyTo":"ba28273f7efb0fa3e403a8a9d7b923b61bb62ce3.1289561504.git.peter@softwolves.pp.se","subject":"Re: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-11-13T21:29:22Z","receivedAt":"2010-11-13T21:29:22Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Fri, Nov 12, 2010 at 12:30, Peter Krefting <peter@softwolves.pp.se> wrote:\n> If we pass a remote repository specification to git init, we should try\n> connecting to the remote and run git init there. Not all transports\n> can support this, so fall back to reporting an error message for those\n> that cannot.\n\nI remember some discussion about this before, I think Scott and Jeff\n(cc-ed) were involved at least, maybe they remember? I remember the\nidea of a new remote service (e.g., in addition to 'git-upload-pack'\nand 'git-receive-pack') to create a new repository. The reason for\nmaking this a new service was so that (among others) the github guys\ncould make that do something sensible for their service.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"155978","messageId":"alpine.DEB.2.00.1011160632280.20293@ds9.cixit.se","threadId":"25725","inReplyTo":"AANLkTimqLeyDW9sJVR8NPOXQ1Xdz+kRmu9-8fPn1yj_j@mail.gmail.com","subject":"Re: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2010-11-16T05:33:50Z","receivedAt":"2010-11-16T05:33:50Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Hi!\n\nSverre Rabbelier:\n\n> I remember the idea of a new remote service (e.g., in addition to \n> 'git-upload-pack' and 'git-receive-pack') to create a new repository. The \n> reason for making this a new service was so that (among others) the github \n> guys could make that do something sensible for their service.\n\nRight, that does indeed make sense. I guess that means I need to read up a \nbit more on how to hook things together. It wasn't quite as obvious on a \ncursory glance :-)\n\n\nAny objections to the first part of the patch (that detects attempts at \nremote init and rejects them)?\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"156005","messageId":"7vfwv1i22u.fsf@alter.siamese.dyndns.org","threadId":"25725","inReplyTo":"3f7d07a2b3a02c1d3f864d2a17f3b8808890a4d1.1289561504.git.peter@softwolves.pp.se","subject":"Re: [PATCH 1/2] [RFC] Detect attempts at calling git init specifying a remote repository.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-16T17:57:13Z","receivedAt":"2010-11-16T17:57:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Peter Krefting <peter@softwolves.pp.se> writes:\n\n> We can only initialize local repositories, so bail out immediately if the\n> user tries to specify a remote repository.\n> ---\n>  builtin/init-db.c |    7 ++++++-\n>  1 files changed, 6 insertions(+), 1 deletions(-)\n>\n> diff --git a/builtin/init-db.c b/builtin/init-db.c\n> index 9d4886c..f80ff08 100644\n> --- a/builtin/init-db.c\n> +++ b/builtin/init-db.c\n> @@ -435,7 +435,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n>  \t\tint mkdir_tried = 0;\n>  \tretry:\n>  \t\tif (chdir(argv[0]) < 0) {\n> -\t\t\tif (!mkdir_tried) {\n> +\t\t\tif (is_url(argv[0]) || strchr(argv[0], '@') != NULL || (strchr(argv[0], ':') != NULL && !has_dos_drive_prefix(argv[0]))) {\n> +\t\t\t\t/*\n> +\t\t\t\t * We were passed a remote repository specification.\n\nOr a directory with ':' in its pathname, no?\n"},{"id":"156006","messageId":"7vbp5pi20z.fsf@alter.siamese.dyndns.org","threadId":"25725","inReplyTo":"alpine.DEB.2.00.1011160632280.20293@ds9.cixit.se","subject":"Re: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-16T17:58:20Z","receivedAt":"2010-11-16T17:58:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Peter Krefting <peter@softwolves.pp.se> writes:\n\n> Any objections to the first part of the patch (that detects attempts\n> at remote init and rejects them)?\n\nYes.\n\nDidn't we discuss this long time ago and decided, if anything is to be\ndone, it would be something like \"the first push creates\"?\n"},{"id":"156019","messageId":"alpine.DEB.2.00.1011162107580.13543@perkele.intern.softwolves.pp.se","threadId":"25725","inReplyTo":"7vfwv1i22u.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 1/2] [RFC] Detect attempts at calling git init specifying a remote repository.","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2010-11-16T20:10:03Z","receivedAt":"2010-11-16T20:10:03Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Junio C Hamano:\n\n>> --- a/builtin/init-db.c\n>> +++ b/builtin/init-db.c\n>> @@ -435,7 +435,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n>>  \t\tint mkdir_tried = 0;\n>>  \tretry:\n>>  \t\tif (chdir(argv[0]) < 0) {\n>> -\t\t\tif (!mkdir_tried) {\n>> +\t\t\tif (is_url(argv[0]) || strchr(argv[0], '@') != NULL || (strchr(argv[0], ':') != NULL && !has_dos_drive_prefix(argv[0]))) {\n>> +\t\t\t\t/*\n>> +\t\t\t\t * We were passed a remote repository specification.\n> Or a directory with ':' in its pathname, no?\n\nIndeed. Don't do that, then :-)\n\nSeriously, though, I tried finding an API that checked if the pathspec is \nlocal or remote, but I was unable to. Is there one I should use instead?\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"156020","messageId":"alpine.DEB.2.00.1011162110300.13543@perkele.intern.softwolves.pp.se","threadId":"25725","inReplyTo":"7vbp5pi20z.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2010-11-16T20:12:46Z","receivedAt":"2010-11-16T20:12:46Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Junio C Hamano:\n\n> Didn't we discuss this long time ago and decided, if anything is to be \n> done, it would be something like \"the first push creates\"?\n\nI have probably missed that reference. But you mean to instead set up an \nempty repository, with a configured remote? That is an interesting \nalternative, but would still fail as there still is no way to initialize a \nnew repository on the remote.\n\nBut I am definitely open to fix it properly, I just haven't been able to \nfigure out how to do that yet.\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"}]}