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

Re: [PATCH] submodule add: improve message when resolving a relative url fails

From
Marc Branchaud <marcnarc@xiplink.com>
Date
Jun 1, 2011, 15:55 UTC
Message-ID
<4DE660E2.9080500@xiplink.com>
In-Reply-To
<4DE565DF.7050207@cisco.com>
On 11-05-31 06:04 PM, Phil Hord wrote:
Show 20 quoted lines
> On 05/31/2011 04:57 PM, Marc Branchaud wrote:
>> Thanks for the cogent explanation & patch.  I think the message could be
>> improved a bit:
>>
>> 	Cannot resolve "../sub" relative to this repository's "origin"
>> 	remote: The remote's URL is not set in .git/config
>>
>> However, overall I think this is a pretty fragile way to handle relative
>> paths.  Consider:
>>
>>  - The super-repo must be a clone in order for this to work at all.
> 
> Yes, but that constraint (mostly) makes sense to me.  But if 'git
> submodule add' did not initialize .git/config, this constraint could be
> dropped.
> 
>>  - The super-repo cannot be checked out on a detached HEAD.
> 
> Why do you think that?  I just tried this and it worked fine for me.  I
> can't think of a reason for it to fail.

Whoops, right. I was confusing a different error with the fact that "git symbolic-ref HEAD" fails on a detached HEAD. The code defaults to "origin" as the remote name in this case (perhaps that's not strictly the right thing to do, but I'm sure this isn't the only part of git that assumes there's a remote called "origin").

Show 5 quoted lines
>>  - The current code rewrites the URL so that any relative path is either
>>    rejected or munged into an absolute remote URL.
> 
> I don't see the URL getting munged away from being relative.  Can you
> point to an example?
I reached this conclusion because if I go into my clone of git.git and do
	git submodule add ../MyThing
where ../MyThing is a regular git repo, I get

Cloning into MyThing... fatal: The remote end hung up unexpectedly Clone of 'git://git.kernel.org/pub/scm/git/MyThing' into submodule path 'MyThing' failed

So it seemed the relative URL became an absolute URL.

Looking more closely at a working example, I can see that (as you show below) the URL in the super-repo's .gitmodules file retains the relative path, but the submodule's remote.origin.url is an absolute path.

In any case, "submodule add" isn't doing what I expected: make my local MyThing repo a submodule of my git.git clone.

Show 40 quoted lines
>> It seems to me that this feature will only work in a fairly narrow set of
>> circumstances, and even when it does work it's likely to do something
>> unexpected (think of a super-repo with several remotes).
> 
> I use it this way with several remotes. 
> 
>> Back when Junio accepted the original patch, he said "If you maintain and
>> serve a set related projects you need to give the users a single URL (per
>> where the user is and how to reach the server)."  I'm not sure I understand
>> that:  Why would the users be adding their own submodules to the
>> superproject?  Wouldn't the superproject define the submodules in for them?
> I am a user.  I admin a super-project for other users.  This project
> lives at three remotes, remotes/public, remotes/shared and remotes/build. 
> 
> I add a new submodule to the superproject like this:
> 
>    mkdir sub && cd sub && git init
>    cd ..
>    git submodule add ../sub sub
> 
> This results in the new submodule being inserted into my .gitmodules
> file and my .git/config:
> 
>    tail -3 .gitmodules
>    [submodule "sub"]
>        path = sub
>        url = ../sub
> 
>    tail -2 .git/config
>    [submodule "sub"]
>        url = public:git/sub
> 
> I do have to make sure to push my submodule to the correct location on
> each remote before pushing my new .gitmodules.
> 
> But the exact same commands work for me if I do this first and then do
> 'git submodule add ../sub' afterwards. 
> 
> So, I don't understand your objections.  Do you understand my use case
> any better?
It's not so much an objection as confusion over how "submodule add" works.

I believe your case works smoothly only because in your super-project you're careful to make sure you have checked out a branch that remotely tracks a something in remotes/public. If you checked out a branch that tracks a different remote you'd get different results. This seems fragile to me.

When you tried the detached-HEAD scenario, did you get URLs for "public:git/sub" or "origin:git/sub"? Does "origin" just happen to be the remote you want to use in any case?

My fundamental point is that "git submodule add" seems to do confusing things with relative paths. Maybe all that's needed is to clarify the documentation. I'll post a patch.

		M.
Previous: Phil HordNext: Phil Hord
Message 9 of 40 in “Tests for some submodule corner cases.”
  1. 0/2 Tests for some submodule corner cases.Marc Branchaud, May 30, 2011
  2. 1/2 Added a test for "submodule add" using a ../relative/path/to/the/submodule/repoMarc Branchaud, May 30, 2011
  3. 2/2 Added a test for "submodule status" when the submodule's working directory has deleted files.Marc Branchaud, May 30, 2011
  4. Jens LehmannMay 31, 2011
  5. submodule add: improve message when resolving a relative url failsJens Lehmann, May 31, 2011
  6. Marc BranchaudMay 31, 2011
  7. submodule add: improve message when resolving a relative url failsJens Lehmann, May 31, 2011
  8. Phil HordMay 31, 2011
  9. Marc BranchaudJun 1, 2011
  10. Phil HordJul 27, 2011
  11. Marc BranchaudJul 29, 2011
  12. Junio C HamanoMay 31, 2011
  13. Clarified how "git submodule add" handles relative paths.Marc Branchaud, Jun 1, 2011
  14. Junio C HamanoJun 1, 2011
  15. Jens LehmannJun 1, 2011
  16. Junio C HamanoJun 2, 2011
  17. Jens LehmannJun 3, 2011
  18. Junio C HamanoJun 3, 2011
  19. Mark LevedahlJun 4, 2011
  20. Jens LehmannJun 4, 2011
  21. Jens LehmannJun 4, 2011
  22. Junio C HamanoJun 5, 2011
  23. 0/3 submodule add: allow relative repository path even when no url is setJens Lehmann, Jun 6, 2011
  24. 1/3 submodule add: test failure when url is not configured in superprojectJens Lehmann, Jun 6, 2011
  25. 2/3 submodule add: allow relative repository path even when no url is setJens Lehmann, Jun 6, 2011
  26. 0/2 Improve "git submodule add" documentation.Marc Branchaud, Jun 6, 2011
  27. 1/2 More precisely described how "git submodule add" handles relative submodule URLs.Marc Branchaud, Jun 6, 2011
  28. 2/2 Moved paragraph describing the utility of relative submodule URLs.Marc Branchaud, Jun 6, 2011
  29. 3/3 submodule add: clean up duplicated codeJens Lehmann, Jun 6, 2011
  30. Junio C HamanoJun 6, 2011
  31. Marc BranchaudJun 6, 2011
  32. Jens LehmannJun 6, 2011
  33. Jens LehmannJun 7, 2011
  34. Phil HordJun 8, 2011
  35. [PATCHv2] Clarified how "git submodule add" handles relative paths.Marc Branchaud, Jun 2, 2011
  36. Marc BranchaudMay 31, 2011
  37. Jens LehmannMay 31, 2011
  38. Marc BranchaudJun 1, 2011
  39. Junio C HamanoJun 1, 2011
  40. Jens LehmannJun 1, 2011

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.