All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] [RFC] Detect attempts at calling git init specifying a remote repository.
  2010-11-12 11:31 [PATCH 0/2] RFC: Better handling of git init remote-spec Peter Krefting
@ 2010-11-12 11:27 ` Peter Krefting
  2010-11-16 17:57   ` Junio C Hamano
  2010-11-12 11:30 ` [PATCH 2/2] [WIP] Allow running git init on a remote repository specification Peter Krefting
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Krefting @ 2010-11-12 11:27 UTC (permalink / raw)
  To: Git

We can only initialize local repositories, so bail out immediately if the
user tries to specify a remote repository.
---
 builtin/init-db.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 9d4886c..f80ff08 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -435,7 +435,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 		int mkdir_tried = 0;
 	retry:
 		if (chdir(argv[0]) < 0) {
-			if (!mkdir_tried) {
+			if (is_url(argv[0]) || strchr(argv[0], '@') != NULL || (strchr(argv[0], ':') != NULL && !has_dos_drive_prefix(argv[0]))) {
+				/*
+				 * We were passed a remote repository specification.
+				 */
+				die("Cannot initialize remote repository '%s'", argv[0]);
+			} else if (!mkdir_tried) {
 				int saved;
 				/*
 				 * At this point we haven't read any configuration,
-- 
1.7.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.
  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-12 11:30 ` Peter Krefting
  2010-11-13 21:29   ` Sverre Rabbelier
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Krefting @ 2010-11-12 11:30 UTC (permalink / raw)
  To: Git

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 0/2] RFC: Better handling of git init remote-spec
@ 2010-11-12 11:31 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-12 11:30 ` [PATCH 2/2] [WIP] Allow running git init on a remote repository specification Peter Krefting
  0 siblings, 2 replies; 9+ messages in thread
From: Peter Krefting @ 2010-11-12 11:31 UTC (permalink / raw)
  To: Git

>From time to time I forget myself and try to initialize a repository on a remote
machine by writing something like

  git init --bare remote.machine:myrepo.git

just to get a local directory called "remote.machine:myrepo.git" set up.

Or, even worse, a

  git init --bare ssh://remote.machine/myrepo.git

These patches try to fix this. The first patch tries to detect if a remote
repository specification was supplied, and just stop with an error message.
That one is fairly safe.

The second one I haven't got working yet, but I have the beginnings of a
patch that actually tries to run "git-init" on the remote repository. Any
ideas on how to get this actually working (it should be possible for the
"ssh" transport at least) are welcome.

Peter Krefting (2):
  Detect attempts at calling git init specifying a remote repository.
  WIP: Allow running git init on a remote repository specification.

 builtin/init-db.c |   16 +++++++++++++++-
 remote.c          |   11 +++++++++++
 remote.h          |    1 +
 3 files changed, 27 insertions(+), 1 deletions(-)

-- 
1.7.3

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.
  2010-11-12 11:30 ` [PATCH 2/2] [WIP] Allow running git init on a remote repository specification Peter Krefting
@ 2010-11-13 21:29   ` Sverre Rabbelier
  2010-11-16  5:33     ` Peter Krefting
  0 siblings, 1 reply; 9+ messages in thread
From: Sverre Rabbelier @ 2010-11-13 21:29 UTC (permalink / raw)
  To: Peter Krefting, Scott Chacon, Jeff King; +Cc: Git

Heya,

On Fri, Nov 12, 2010 at 12:30, Peter Krefting <peter@softwolves.pp.se> wrote:
> 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.

I remember some discussion about this before, I think Scott and Jeff
(cc-ed) were involved at least, maybe they remember? I remember the
idea of a new remote service (e.g., in addition to 'git-upload-pack'
and 'git-receive-pack') to create a new repository. The reason for
making this a new service was so that (among others) the github guys
could make that do something sensible for their service.

-- 
Cheers,

Sverre Rabbelier

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.
  2010-11-13 21:29   ` Sverre Rabbelier
@ 2010-11-16  5:33     ` Peter Krefting
  2010-11-16 17:58       ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Krefting @ 2010-11-16  5:33 UTC (permalink / raw)
  To: Sverre Rabbelier; +Cc: Scott Chacon, Jeff King, Git

Hi!

Sverre Rabbelier:

> I remember the idea of a new remote service (e.g., in addition to 
> 'git-upload-pack' and 'git-receive-pack') to create a new repository. The 
> reason for making this a new service was so that (among others) the github 
> guys could make that do something sensible for their service.

Right, that does indeed make sense. I guess that means I need to read up a 
bit more on how to hook things together. It wasn't quite as obvious on a 
cursory glance :-)


Any objections to the first part of the patch (that detects attempts at 
remote init and rejects them)?

-- 
\\// Peter - http://www.softwolves.pp.se/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] [RFC] Detect attempts at calling git init specifying a remote repository.
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2010-11-16 17:57 UTC (permalink / raw)
  To: Peter Krefting; +Cc: Git

Peter Krefting <peter@softwolves.pp.se> writes:

> We can only initialize local repositories, so bail out immediately if the
> user tries to specify a remote repository.
> ---
>  builtin/init-db.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/builtin/init-db.c b/builtin/init-db.c
> index 9d4886c..f80ff08 100644
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -435,7 +435,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
>  		int mkdir_tried = 0;
>  	retry:
>  		if (chdir(argv[0]) < 0) {
> -			if (!mkdir_tried) {
> +			if (is_url(argv[0]) || strchr(argv[0], '@') != NULL || (strchr(argv[0], ':') != NULL && !has_dos_drive_prefix(argv[0]))) {
> +				/*
> +				 * We were passed a remote repository specification.

Or a directory with ':' in its pathname, no?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.
  2010-11-16  5:33     ` Peter Krefting
@ 2010-11-16 17:58       ` Junio C Hamano
  2010-11-16 20:12         ` Peter Krefting
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2010-11-16 17:58 UTC (permalink / raw)
  To: Peter Krefting; +Cc: Sverre Rabbelier, Scott Chacon, Jeff King, Git

Peter Krefting <peter@softwolves.pp.se> writes:

> Any objections to the first part of the patch (that detects attempts
> at remote init and rejects them)?

Yes.

Didn't we discuss this long time ago and decided, if anything is to be
done, it would be something like "the first push creates"?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] [RFC] Detect attempts at calling git init specifying a remote repository.
  2010-11-16 17:57   ` Junio C Hamano
@ 2010-11-16 20:10     ` Peter Krefting
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Krefting @ 2010-11-16 20:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git

Junio C Hamano:

>> --- a/builtin/init-db.c
>> +++ b/builtin/init-db.c
>> @@ -435,7 +435,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
>>  		int mkdir_tried = 0;
>>  	retry:
>>  		if (chdir(argv[0]) < 0) {
>> -			if (!mkdir_tried) {
>> +			if (is_url(argv[0]) || strchr(argv[0], '@') != NULL || (strchr(argv[0], ':') != NULL && !has_dos_drive_prefix(argv[0]))) {
>> +				/*
>> +				 * We were passed a remote repository specification.
> Or a directory with ':' in its pathname, no?

Indeed. Don't do that, then :-)

Seriously, though, I tried finding an API that checked if the pathspec is 
local or remote, but I was unable to. Is there one I should use instead?

-- 
\\// Peter - http://www.softwolves.pp.se/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] [WIP] Allow running git init on a remote repository specification.
  2010-11-16 17:58       ` Junio C Hamano
@ 2010-11-16 20:12         ` Peter Krefting
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Krefting @ 2010-11-16 20:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Sverre Rabbelier, Scott Chacon, Jeff King, Git

Junio C Hamano:

> Didn't we discuss this long time ago and decided, if anything is to be 
> done, it would be something like "the first push creates"?

I have probably missed that reference. But you mean to instead set up an 
empty repository, with a configured remote? That is an interesting 
alternative, but would still fail as there still is no way to initialize a 
new repository on the remote.

But I am definitely open to fix it properly, I just haven't been able to 
figure out how to do that yet.

-- 
\\// Peter - http://www.softwolves.pp.se/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-11-16 20:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] [WIP] Allow running git init on a remote repository specification Peter Krefting
2010-11-13 21:29   ` Sverre Rabbelier
2010-11-16  5:33     ` Peter Krefting
2010-11-16 17:58       ` Junio C Hamano
2010-11-16 20:12         ` Peter Krefting

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.