threads / discuss / 33934

git clone does not understand insteadOf URLs

Subject: git clone does not understand insteadOf URLs

## tl;dr

10 messages between May 25, 2013 and May 28, 2013.

replies: 9people: 5as markdown or json

Gioele Barabucci· May 25, 2013, 20:23 UTC · lore
Hello,

it seems that `git clone` does not understand keywords used `insteadOf` longer URLs.

     $ git clone remote-repo/ProjectA.git
     fatal repository 'remote-repo/ProjectA.git' does not exist

I suppose that git interprets the argument as a local directory. Git should see if the argument matches one of the known URLs before raising an error.

Regards,
-- 
Gioele Barabucci <gioele@svario.it>
Elia Pinto· May 26, 2013, 15:13 UTC · re: Gioele Barabucci · lore

Re: git clone does not understand insteadOf URLs

Why someone should be do something like this ? What is the use case ?
Best regards
2013/5/25, Gioele Barabucci <gioele@svario.it>:
Show 21 quoted lines
> Hello,
>
> it seems that `git clone` does not understand keywords used `insteadOf`
> longer URLs.
>
>      $ git clone remote-repo/ProjectA.git
>      fatal repository 'remote-repo/ProjectA.git' does not exist
>
> I suppose that git interprets the argument as a local directory. Git
> should see if the argument matches one of the known URLs before raising
> an error.
>
> Regards,
>
> --
> Gioele Barabucci <gioele@svario.it>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
-- 
Inviato dal mio dispositivo mobile
Gioele Barabucci· May 26, 2013, 17:55 UTC · re: Elia Pinto · lore

Re: git clone does not understand insteadOf URLs

Il 26/05/2013 17:13, Elia Pinto ha scritto:
 >>       $ git clone remote-repo/ProjectA.git
 >>       fatal repository 'remote-repo/ProjectA.git' does not exist
 >
> Why someone should be do something like this ? What is the use case ?

Simple, I keep all my projects on the same server, so I would like to refer to that server + path using 'remote-repo'.

"git+ssh://git.example.org//users/gioele/projects" insteadOf "remote-repo"

I also helps me when I move all the projects from one path to another in the remote server: I only need to change the path once in `~/.gitconfig`.

Please note that `git remote add` correctly understands 'remote-repo/ProjectA.git'. I was expecting that `clone` and `remote` both used the same code to parse paths.

Regards,
-- 
Gioele Barabucci <gioele@svario.it>
Andreas Schwab· May 26, 2013, 18:00 UTC · re: Gioele Barabucci · lore

Re: git clone does not understand insteadOf URLs

Gioele Barabucci <gioele@svario.it> writes:
> Simple, I keep all my projects on the same server, so I would like to
> refer to that server + path using 'remote-repo'.
>
> "git+ssh://git.example.org//users/gioele/projects" insteadOf "remote-repo"
You can use "remote-repo:" instead.
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Gioele Barabucci· May 26, 2013, 18:09 UTC · re: Andreas Schwab · lore

Re: git clone does not understand insteadOf URLs

Il 26/05/2013 20:00, Andreas Schwab ha scritto:
Show 6 quoted lines
>> Simple, I keep all my projects on the same server, so I would like to
>> refer to that server + path using 'remote-repo'.
>>
>> "git+ssh://git.example.org//users/gioele/projects" insteadOf "remote-repo"
>
> You can use "remote-repo:" instead.

Do you mean I could use "git+ssh://git.example.org//users/gioele/projects" insteadOf "remote-repo:"? Yes, but now I have dozens of repositories already set up in various workstations and I do not want to go and change all of them.

What really bugs me is the fact that `git clone` and `git remote add` parse the same path in different ways. Git already has many inconsistencies. This one can be easily ironed out.

Regards,
-- 
Gioele Barabucci <gioele@svario.it>
John Keeping· May 26, 2013, 18:14 UTC · re: Gioele Barabucci · lore

Re: git clone does not understand insteadOf URLs

On Sun, May 26, 2013 at 08:09:56PM +0200, Gioele Barabucci wrote:
Show 16 quoted lines
> Il 26/05/2013 20:00, Andreas Schwab ha scritto:
> >> Simple, I keep all my projects on the same server, so I would like to
> >> refer to that server + path using 'remote-repo'.
> >>
> >> "git+ssh://git.example.org//users/gioele/projects" insteadOf "remote-repo"
> >
> > You can use "remote-repo:" instead.
> 
> Do you mean I could use 
> "git+ssh://git.example.org//users/gioele/projects" insteadOf 
> "remote-repo:"? Yes, but now I have dozens of repositories already set 
> up in various workstations and I do not want to go and change all of them.
> 
> What really bugs me is the fact that `git clone` and `git remote add` 
> parse the same path in different ways. Git already has many 
> inconsistencies. This one can be easily ironed out.
In what way do you think that `git remote add` handles the path?

All `git remote add` does is add a new "remote.<name>.url" entry to the configuration file with the value as given on the command line. The insteadOf mapping will only be applied when you try to fetch from/push to the remote.

Gioele Barabucci· May 26, 2013, 18:21 UTC · re: John Keeping · lore

Re: git clone does not understand insteadOf URLs

Il 26/05/2013 20:14, John Keeping ha scritto:
Show 13 quoted lines
> On Sun, May 26, 2013 at 08:09:56PM +0200, Gioele Barabucci wrote:
>> Il 26/05/2013 20:00, Andreas Schwab ha scritto:
>>>> Simple, I keep all my projects on the same server, so I would like to
>>>> refer to that server + path using 'remote-repo'.
>>>>
>>>> "git+ssh://git.example.org//users/gioele/projects" insteadOf "remote-repo"
>
> In what way do you think that `git remote add` handles the path?
>
> All `git remote add` does is add a new "remote.<name>.url" entry to the
> configuration file with the value as given on the command line.  The
> insteadOf mapping will only be applied when you try to fetch from/push
> to the remote.
Regardless of the implementation of the commands, if I do
     mkdir projectA
     cd projectA
     git init .
     git remote add origin remote-repo/projectA.git
     git pull origin master
I get a working repository. If I do
     git clone remote-repo/projectA.git
all I will get is an error.

I do not see any reason (UX-wise) why the two sequences of commands shouldn't work the same when used on the same URL.

Regards,
-- 
Gioele Barabucci <gioele@svario.it>
John Keeping· May 26, 2013, 19:00 UTC · re: Gioele Barabucci · lore

Re: git clone does not understand insteadOf URLs

On Sun, May 26, 2013 at 08:21:45PM +0200, Gioele Barabucci wrote:
Show 28 quoted lines
> Il 26/05/2013 20:14, John Keeping ha scritto:
> > On Sun, May 26, 2013 at 08:09:56PM +0200, Gioele Barabucci wrote:
> >> Il 26/05/2013 20:00, Andreas Schwab ha scritto:
> >>>> Simple, I keep all my projects on the same server, so I would like to
> >>>> refer to that server + path using 'remote-repo'.
> >>>>
> >>>> "git+ssh://git.example.org//users/gioele/projects" insteadOf "remote-repo"
> >
> > In what way do you think that `git remote add` handles the path?
> >
> > All `git remote add` does is add a new "remote.<name>.url" entry to the
> > configuration file with the value as given on the command line.  The
> > insteadOf mapping will only be applied when you try to fetch from/push
> > to the remote.
> 
> Regardless of the implementation of the commands, if I do
> 
>      mkdir projectA
>      cd projectA
>      git init .
>      git remote add origin remote-repo/projectA.git
>      git pull origin master
> 
> I get a working repository. If I do
> 
>      git clone remote-repo/projectA.git
> 
> all I will get is an error.

So the problem is that "git clone" does not seem to perform normal remote processing if you give it something that looks like a path.

More specifically, it looks like the problem is that if you give clone something that does not contain a colon (':') it considers it to be a local path and dies if that path does not exist. Adding a colon as Andreas suggested makes it look like a remote URL so it will be handled correctly.

Gioele Barabucci· May 26, 2013, 19:03 UTC · re: John Keeping · lore

Re: git clone does not understand insteadOf URLs

Il 26/05/2013 21:00, John Keeping ha scritto:
Show 16 quoted lines
>> Regardless of the implementation of the commands, if I do
>>
>>       mkdir projectA
>>       cd projectA
>>       git init .
>>       git remote add origin remote-repo/projectA.git
>>       git pull origin master
>>
>> I get a working repository. If I do
>>
>>       git clone remote-repo/projectA.git
>>
>> all I will get is an error.
>
> So the problem is that "git clone" does not seem to perform normal
> remote processing if you give it something that looks like a path.

I understand the problem. In the original email that started this thread I asked for...

> I suppose that git interprets the argument as a local directory. Git
> should see if the argument matches one of the known URLs before
> raising an error.

I think all the paths should mean the same in every git command. In this case, checking for insteadOf URLs before failing would solve this problem.

Regards,
-- 
Gioele Barabucci <gioele@svario.it>
Junio C Hamano· May 28, 2013, 20:06 UTC · re: Andreas Schwab · lore

Re: git clone does not understand insteadOf URLs

Andreas Schwab <schwab@linux-m68k.org> writes:
Show 8 quoted lines
> Gioele Barabucci <gioele@svario.it> writes:
>
>> Simple, I keep all my projects on the same server, so I would like to
>> refer to that server + path using 'remote-repo'.
>>
>> "git+ssh://git.example.org//users/gioele/projects" insteadOf "remote-repo"
>
> You can use "remote-repo:" instead.

That "with colon" is pretty much how it was designed to be used, but the code did not insist that the insteadof has at least the scheme part, and by mistake allowed something like this

	[url "k.org:/pub/scm/git"] insteadOf = g
to be used with "g/foo" to expand to "k.org:/pub/scm/git/foo".

But if "git fetch g/foo" with such a configuration happily goes to "k.org:/pub/scm/git/foo" without problems, then I think it is very reasonable to delay the "is that a local filename?" short-cut "git clone" does and let the insteadof URL expand take place before it.

← back to recent threads