git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
@ 2020-03-17 18:34 Benjamin Shropshire
  2020-03-18  0:26 ` brian m. carlson
  2020-03-23  1:11 ` brian m. carlson
  0 siblings, 2 replies; 7+ messages in thread
From: Benjamin Shropshire @ 2020-03-17 18:34 UTC (permalink / raw)
  To: git

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

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

* Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
  2020-03-17 18:34 Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https Benjamin Shropshire
@ 2020-03-18  0:26 ` brian m. carlson
  2020-03-18 16:02   ` Benjamin Shropshire
  2020-03-23  1:11 ` brian m. carlson
  1 sibling, 1 reply; 7+ messages in thread
From: brian m. carlson @ 2020-03-18  0:26 UTC (permalink / raw)
  To: Benjamin Shropshire; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1215 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

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

* Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
  2020-03-18  0:26 ` brian m. carlson
@ 2020-03-18 16:02   ` Benjamin Shropshire
  2020-03-20  1:18     ` brian m. carlson
  0 siblings, 1 reply; 7+ messages in thread
From: Benjamin Shropshire @ 2020-03-18 16:02 UTC (permalink / raw)
  To: brian m. carlson, Benjamin Shropshire, git

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

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

* Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
  2020-03-18 16:02   ` Benjamin Shropshire
@ 2020-03-20  1:18     ` brian m. carlson
  0 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2020-03-20  1:18 UTC (permalink / raw)
  To: Benjamin Shropshire; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

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

* Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
  2020-03-17 18:34 Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https Benjamin Shropshire
  2020-03-18  0:26 ` brian m. carlson
@ 2020-03-23  1:11 ` brian m. carlson
  2020-03-23 15:09   ` Benjamin Shropshire
  1 sibling, 1 reply; 7+ messages in thread
From: brian m. carlson @ 2020-03-23  1:11 UTC (permalink / raw)
  To: Benjamin Shropshire; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

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

* Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
  2020-03-23  1:11 ` brian m. carlson
@ 2020-03-23 15:09   ` Benjamin Shropshire
  2020-03-23 23:53     ` brian m. carlson
  0 siblings, 1 reply; 7+ messages in thread
From: Benjamin Shropshire @ 2020-03-23 15:09 UTC (permalink / raw)
  To: brian m. carlson, Benjamin Shropshire, git

$ 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

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

* Re: Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https.
  2020-03-23 15:09   ` Benjamin Shropshire
@ 2020-03-23 23:53     ` brian m. carlson
  0 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2020-03-23 23:53 UTC (permalink / raw)
  To: Benjamin Shropshire; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 998 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

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

end of thread, other threads:[~2020-03-23 23:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-17 18:34 Relative url values in .gitmodules confusingly sensitive to clone via ssh vs https Benjamin Shropshire
2020-03-18  0:26 ` brian m. carlson
2020-03-18 16:02   ` Benjamin Shropshire
2020-03-20  1:18     ` brian m. carlson
2020-03-23  1:11 ` brian m. carlson
2020-03-23 15:09   ` Benjamin Shropshire
2020-03-23 23:53     ` brian m. carlson

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).