git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] Filenames with single colon being treated as remote repository

From
Jeff King <peff@peff.net>
Date
Apr 21, 2013, 12:45 UTC
Message-ID
<20130421124511.GA1933@sigill.intra.peff.net>
In-Reply-To
<20130421060538.GB10429@elie.Belkin>
On Sat, Apr 20, 2013 at 11:05:39PM -0700, Jonathan Nieder wrote:
Show 12 quoted lines
> >     Cloning into 'new-baz'...
> >     ssh: Could not resolve hostname /tmp/foo: Success
> >     fatal: Could not read from remote repository.
> 
> Here's a toy patch.  I haven't thought carefully about whether it's a
> good idea, but maybe it can be useful for thinking about that.
> 
> Still needs documentation and tests.
> 
> My main worry is that the proposed rule for when an argument is
> treated as a local path is hard to explain.  There's some precedent in
> handling of bundles, though.  What do you think?
I think the rule could be something like:
  1. If it looks like a URL ("^scheme://"), it is.
  2. Otherwise, if it is a path in the filesystem, it is.
  3. Otherwise, if it has a colon, it's host:path
  4. Otherwise, barf.

where the interesting bit is the ordering of 2 and 3. It seems like "git clone" follows the order above with get_repo_path. But we do not seem to follow it in git_connect, where we prefer 3 over 2.

Show 8 quoted lines
> @@ -942,6 +943,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
>  		ret->disconnect = close_bundle;
>  		ret->smart_options = NULL;
>  	} else if (!is_url(url)
> +		|| (is_local(url) && !stat(url, &st))
>  		|| !prefixcmp(url, "file://")
>  		|| !prefixcmp(url, "git://")
>  		|| !prefixcmp(url, "ssh://")

I don't think that is enough. Something like /path/to/foo:bar would trigger !is_url already, but then git_connect fails.

Try:
  $ git init --bare foo:bar
  $ git clone foo:bar
  ssh: Could not resolve hostname /home/peff/foo: Name or service not known
  fatal: Could not read from remote repository.
  ...

Clone recognizes it as a path and turns it into an absolute path. It then feeds it to the transport code, which triggers !is_url and knows to use the git transport. But then git_connect prefers ssh over the filesystem.

If you do a straight fetch, though, the transport code might see the relative path (if you use one):

  $ git init
  $ git init --bare sub:repo
  $ git fetch sub:repo
  ssh: Could not resolve hostname sub: Name or service not known
but that still triggers the is_url above (which demands the "://").

I am not sure whether your patch covers any cases I am missing, but I think you would need an analogous change to git_connect for these common cases.

-Peff
Previous: Jonathan NiederNext: Jonathan Nieder
Message 3 of 16 in “[BUG] Filenames with single colon being treated as remote repository”
  1. William GiokasApr 21, 2013
  2. Jonathan NiederApr 21, 2013
  3. Jeff KingApr 21, 2013
  4. Jonathan NiederApr 21, 2013
  5. Junio C HamanoApr 21, 2013
  6. Jeff KingApr 22, 2013
  7. Junio C HamanoApr 22, 2013
  8. clone: allow cloning local paths with colons in themNguyễn Thái Ngọc Duy, Apr 27, 2013
  9. William GiokasApr 27, 2013
  10. Junio C HamanoApr 27, 2013
  11. Duy NguyenApr 28, 2013
  12. Eric SunshineApr 28, 2013
  13. Duy NguyenApr 28, 2013
  14. clone: allow cloning local paths with colons in themNguyễn Thái Ngọc Duy, May 4, 2013
  15. Junio C HamanoMay 7, 2013
  16. Jeff KingMay 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.