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

Allow git submodule add in subdirectory of the working tree

From
LLuKaRo <lists@lrose.de>
Date
Oct 2, 2020, 11:00 UTC
Message-ID
<b56306ea-f302-a660-7d4a-a0ec096d7073@lrose.de>
Hi everyone,

I just stumbled upon a weird limitation that I think doesn't make sense. Submodules with relative remote paths are allowed when added from the root of the working tree, but not allowed when added within a subdirectory. Always having to cd to the root directory first and then having to specify the full path where the submodule should reside, is not a huge limitation but I don't think it's neccessary. Or am I missing something? See my bug report created with git bugreport.

Please include me in CC in replies to this message, as this is the first time I'm posting to this list and I haven't subscribed yet.

What did you do before the bug happened? (Steps to reproduce your issue) Run `git submodule add ../foo` with a relative remote path (`../foo`) in a subdirectory (`bar/`) of the current git tree.

What did you expect to happen? (Expected behavior) The submodule `foo` gets added under `bar/foo` with remote `../foo`.

What happened instead? (Actual behavior) An error message occured: `Relative path can only be used from the toplevel of the working tree`

What's different between what you expected and what actually happened? The git cli didn't allow to use the relative remote path for the submodule in a subdirectory of the current git tree, although running `git submodule add ../foo` under `/bar` is equal to running `git submodule add ../foo bar/foo` from the root level directory of the current git tree. The second version is allowed, the first one isn't, although both are equivalent.

Anything else you want to add: I think that it doesn't make sense to forbid a relative remote path on a subdirectory of the git tree. Relative remotes are a crucial feature if you don't want to specify the protocol to use to fetch the submodule (some people working on the same repository use HTTPS, others use SSH, in both cases the preferred method should be used to fetch the submodule). Having to add all submodules from the top level directory is a limitation that I think isn't neccessary.

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.28.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.8.12-arch1-1 #1 SMP PREEMPT Sat, 26 Sep 2020 21:42:58 +0000 x86_64 compiler info: gnuc: 10.1 libc info: glibc: 2.32 $SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks]

Thanks, LuKaRo

Message 1 of 1 in “Allow git submodule add in subdirectory of the working tree”
  1. LuKaRoOct 2, 2020

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.