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

7 messages from 2020-03-17 to 2020-03-23. Participants: Benjamin Shropshire, brian m. carlson.
Thread: https://gitlist.dev/t/53013

## Benjamin Shropshire, 2020-03-17 18:34

Subject: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
Message-ID: <CAAjm7Ga5JOJ2w=01o1-x-80HMGVaYQQy8SBBb-zJ6MOQAe4SxQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAAjm7Ga5JOJ2w%3D01o1-x-80HMGVaYQQy8SBBb-zJ6MOQAe4SxQ%40mail.gmail.com

```
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, 2020-03-18 00:26

Subject: Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
Message-ID: <20200318002630.GA366567@camp.crustytoothpaste.net>
URL: https://gitlist.dev/e/20200318002630.GA366567%40camp.crustytoothpaste.net
In-Reply-To: <CAAjm7Ga5JOJ2w=01o1-x-80HMGVaYQQy8SBBb-zJ6MOQAe4SxQ@mail.gmail.com>

```
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
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

```

## Benjamin Shropshire, 2020-03-18 16:02

Subject: Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
Message-ID: <CAAjm7Gb8DdGUCfoPO+p2=YsmvFj5eoCn3jjEbwg3-hwRnt0Q9A@mail.gmail.com>
URL: https://gitlist.dev/e/CAAjm7Gb8DdGUCfoPO%2Bp2%3DYsmvFj5eoCn3jjEbwg3-hwRnt0Q9A%40mail.gmail.com
In-Reply-To: <20200318002630.GA366567@camp.crustytoothpaste.net>

```
On Tue, Mar 17, 2020 at 5:26 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> 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, 2020-03-20 01:18

Subject: Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
Message-ID: <20200320011809.GG366567@camp.crustytoothpaste.net>
URL: https://gitlist.dev/e/20200320011809.GG366567%40camp.crustytoothpaste.net
In-Reply-To: <CAAjm7Gb8DdGUCfoPO+p2=YsmvFj5eoCn3jjEbwg3-hwRnt0Q9A@mail.gmail.com>

```
On 2020-03-18 at 16:02:18, Benjamin Shropshire wrote:
> 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, 2020-03-23 01:11

Subject: Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
Message-ID: <20200323011117.GC6499@camp.crustytoothpaste.net>
URL: https://gitlist.dev/e/20200323011117.GC6499%40camp.crustytoothpaste.net
In-Reply-To: <CAAjm7Ga5JOJ2w=01o1-x-80HMGVaYQQy8SBBb-zJ6MOQAe4SxQ@mail.gmail.com>

```
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

```

## Benjamin Shropshire, 2020-03-23 15:09

Subject: Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
Message-ID: <CAAjm7GZXNXcGMp7p2f+UoDUWMPY+Z4aFHv35tynteVSKDf2Fqw@mail.gmail.com>
URL: https://gitlist.dev/e/CAAjm7GZXNXcGMp7p2f%2BUoDUWMPY%2BZ4aFHv35tynteVSKDf2Fqw%40mail.gmail.com
In-Reply-To: <20200323011117.GC6499@camp.crustytoothpaste.net>

```
$ git --version
git version 2.20.1

On Sun, Mar 22, 2020 at 6:11 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
>
> 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, 2020-03-23 23:53

Subject: Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
Message-ID: <20200323235358.GF6499@camp.crustytoothpaste.net>
URL: https://gitlist.dev/e/20200323235358.GF6499%40camp.crustytoothpaste.net
In-Reply-To: <CAAjm7GZXNXcGMp7p2f+UoDUWMPY+Z4aFHv35tynteVSKDf2Fqw@mail.gmail.com>

```
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

```
