threads / discuss / 53013

Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.

Subject: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.

## tl;dr

7 messages between Mar 17, 2020 and Mar 23, 2020.

replies: 6people: 2as markdown or json

Benjamin Shropshire· Mar 17, 2020, 18:34 UTC · lore
From my perspective, this is a bug.
If I clone a repo twice like this:

git clone https://github.com/user/repo.git ./https git clone git@github.com:user/repo.git ./ssh

And if it contains a .gitmodules like this:
[submodule "x"]
    path = xxx
    url = ../../different-user/something.git

When I `git submodule update --init --recursive` in each, only the HTTPS version works. the SSH version confusingly seems to try to find something at ~/different-user/something.git or some other path in the local file system.

this seems consistent with the URL parsing resulting in different segmentation and thus the ../../ ending up in different places:

https =[..., 'github.com', 'user', 'repo.git'] ssh=['git@github.com:user', 'repo.git']

# ../../ https[:-2] -> [..., 'github.com'] ssh[:-2] -> []

This theory is supported by the fact that this works:

git clone ssh://git@github.com/user/repo.git ./ssh cd ssh git submodule update --init --recursive

---- See also: https://stackoverflow.com/questions/36564696/how-to-use-same-protocol-for-git-submodules

brian m. carlson· Mar 18, 2020, 00:26 UTC · re: Benjamin Shropshire · lore

Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.

On 2020-03-17 at 18:34:09, Benjamin Shropshire wrote:
Show 20 quoted lines
> From my perspective, this is a bug.
> 
> If I clone a repo twice like this:
> 
> git clone https://github.com/user/repo.git ./https
> git clone git@github.com:user/repo.git ./ssh
> 
> And if it contains a .gitmodules like this:
> 
> [submodule "x"]
>     path = xxx
>     url = ../../different-user/something.git
> 
> When I `git submodule update --init --recursive` in each, only the
> HTTPS version works. the SSH version confusingly seems to try to find
> something at ~/different-user/something.git or some other path in the
> local file system.
> 
> this seems consistent with the URL parsing resulting in different
> segmentation and thus the ../../ ending up in different places:

Looking at the code, it appears that we don't let you go above the top of the URL, which makes sense. So we interpret it as a file system path.

(And since this SSH format is not technically a URL, we don't have a root slash, which is probably why this is a problem.)

Does it work if you write the following?
  git clone git@github.com:/user/repo.git ./ssh
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Benjamin Shropshire· Mar 18, 2020, 16:02 UTC · re: brian m. carlson · lore

Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.

On Tue, Mar 17, 2020 at 5:26 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 32 quoted lines
> On 2020-03-17 at 18:34:09, Benjamin Shropshire wrote:
> > From my perspective, this is a bug.
> >
> > If I clone a repo twice like this:
> >
> > git clone https://github.com/user/repo.git ./https
> > git clone git@github.com:user/repo.git ./ssh
> >
> > And if it contains a .gitmodules like this:
> >
> > [submodule "x"]
> >     path = xxx
> >     url = ../../different-user/something.git
> >
> > When I `git submodule update --init --recursive` in each, only the
> > HTTPS version works. the SSH version confusingly seems to try to find
> > something at ~/different-user/something.git or some other path in the
> > local file system.
> >
> > this seems consistent with the URL parsing resulting in different
> > segmentation and thus the ../../ ending up in different places:
>
> Looking at the code, it appears that we don't let you go above the top
> of the URL, which makes sense.  So we interpret it as a file system
> path.
>
> (And since this SSH format is not technically a URL, we don't have a
> root slash, which is probably why this is a problem.)
>
> Does it work if you write the following?
>
>   git clone git@github.com:/user/repo.git ./ssh

That seems to work... thought if the final resolution is telling people to just use a particular format for the repo address, I'd vote for telling them to use a full and proper ssh:// URL. (Technically I think `git@host:/...` may be a protocol relative URL? or maybe that would need to be `//git@host:/....`?)

> --
> brian m. carlson: Houston, Texas, US
> OpenPGP: https://keybase.io/bk2204
brian m. carlson· Mar 20, 2020, 01:18 UTC · re: Benjamin Shropshire · lore

Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.

On 2020-03-18 at 16:02:18, Benjamin Shropshire wrote:
Show 18 quoted lines
> On Tue, Mar 17, 2020 at 5:26 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> > Looking at the code, it appears that we don't let you go above the top
> > of the URL, which makes sense.  So we interpret it as a file system
> > path.
> >
> > (And since this SSH format is not technically a URL, we don't have a
> > root slash, which is probably why this is a problem.)
> >
> > Does it work if you write the following?
> >
> >   git clone git@github.com:/user/repo.git ./ssh
> 
> That seems to work... thought if the final resolution is telling
> people to just use a particular format for the repo address, I'd vote
> for telling them to use a full and proper ssh:// URL. (Technically I
> think `git@host:/...` may be a protocol relative URL? or maybe that
> would need to be `//git@host:/....`?)

I do intend to send a patch to make your particular use case work such that we consider a colon equivalent to a leading slash, but I have a little less time than usual (mostly due to current events). I hope to find some time this weekend, although of course anyone is welcome to send a patch sooner if they get to it first.

I agree that the URL form is probably better overall, but I suspect I'm in the minority there.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
brian m. carlson· Mar 23, 2020, 01:11 UTC · re: Benjamin Shropshire · lore

Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.

On 2020-03-17 at 18:34:09, Benjamin Shropshire wrote:
Show 17 quoted lines
> From my perspective, this is a bug.
> 
> If I clone a repo twice like this:
> 
> git clone https://github.com/user/repo.git ./https
> git clone git@github.com:user/repo.git ./ssh
> 
> And if it contains a .gitmodules like this:
> 
> [submodule "x"]
>     path = xxx
>     url = ../../different-user/something.git
> 
> When I `git submodule update --init --recursive` in each, only the
> HTTPS version works. the SSH version confusingly seems to try to find
> something at ~/different-user/something.git or some other path in the
> local file system.

What version of Git are you using? This works fine for me on a recent next. In addition, I see we have tests for this in t0060, and adding an additional case for this appears to pass.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
Benjamin Shropshire· Mar 23, 2020, 15:09 UTC · re: brian m. carlson · lore

Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.

$ git --version git version 2.20.1

On Sun, Mar 22, 2020 at 6:11 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 26 quoted lines
>
> On 2020-03-17 at 18:34:09, Benjamin Shropshire wrote:
> > From my perspective, this is a bug.
> >
> > If I clone a repo twice like this:
> >
> > git clone https://github.com/user/repo.git ./https
> > git clone git@github.com:user/repo.git ./ssh
> >
> > And if it contains a .gitmodules like this:
> >
> > [submodule "x"]
> >     path = xxx
> >     url = ../../different-user/something.git
> >
> > When I `git submodule update --init --recursive` in each, only the
> > HTTPS version works. the SSH version confusingly seems to try to find
> > something at ~/different-user/something.git or some other path in the
> > local file system.
>
> What version of Git are you using?  This works fine for me on a recent
> next.  In addition, I see we have tests for this in t0060, and adding an
> additional case for this appears to pass.
> --
> brian m. carlson: Houston, Texas, US
> OpenPGP: https://keybase.io/bk2204
brian m. carlson· Mar 23, 2020, 23:53 UTC · re: Benjamin Shropshire · lore

Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.

On 2020-03-23 at 15:09:39, Benjamin Shropshire wrote:
> $ git --version
> git version 2.20.1

Hmmm, it looks like that version has the same test, t0060, which has this:

  test_submodule_relative_url "(null)" "user@host:path/to/repo" "../subrepo" "user@host:path/to/subrepo"
  test_submodule_relative_url "(null)" "user@host:repo" "../subrepo" "user@host:subrepo"
  test_submodule_relative_url "(null)" "user@host:repo" "../../subrepo" ".:subrepo"

I have confirmed that your test case does work for me on the version of Git I mentioned above with the following repos:

  bmc@castro:foo/foo.git
  bmc@castro:bar/bar.git
And foo.git having the following .gitmodules:
  [submodule "bar.git"]
          path = bar.git
          url = ../../bar/bar.git

It's puzzling to me that this isn't working for you on 2.20.1 but it works for me on a 2.26 prerelease, yet both versions have the same test.

-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

← back to recent threads