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

Adding existing repo at sub-sub-directory as submodule

From
JSJonas Schulze <jschulze@mpi-magdeburg.mpg.de>
Date
Sep 15, 2022, 10:49 UTC
Message-ID
<1678038401.2138998.1663238966604.JavaMail.zimbra@mpi-magdeburg.mpg.de>
Hi everyone! 
Is the following a bug? I am working with git v2.25.1. I hope I won't annoy anyone with a duplicate of an existing/known issue. I'm new to working with mailing lists as well. 
# Problem Description 

I would eventually like to add a submodule to `extern/foo` that is checked out at a particular tag. As I cannot `git clone`/`git submodule add` that tag directly, I have to first checkout the default and then check out the desired tag. If I do so from the repo's base directory, everything works as expected: ```bash git clone <URL> foo pushd foo git checkout v1.1.1 popd git submodule add ./foo ``` where the last one prints ``` Adding existing repo at 'foo' to the index ```

If, however, I do so with a target directory one level below, i.e. `./extern/foo` instead of `./foo`, ```bash git submodule add ./extern/foo ``` tries to clone `<current remote URL.git>/extern/foo` into `./foo` and fails: ``` Cloning into '/path/to/repo/foo'... remote: remote: ======================================================================== remote: remote: The namespace you were looking for could not be found. remote: remote: ======================================================================== remote: fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. fatal: clone of '<current remote URL.git>/extern/foo' into submodule path '/path/to/repo/foo' failed ```

Using `git submodule add ./foo` from within `extern/` does not work either (`Relative path can only be used from the toplevel of the working tree`). 
# Expected Behavior 
Given the documentation `git submodule --help`, in particular the part of `add` where it says 
> If <path> exists and is already a valid Git repository, then it is staged for commit without cloning. 

I would expect the output ``` Adding existing repo at 'extern/foo' to the index ```

# Current Workaround 

Adding the submodule first and then updating it works: ``` git submodule add <URL> extern/foo pushd extern/foo git checkout v1.1.1 popd git add extern/foo ```

# Feature Request 
It would be nice if I could do something like `git submodule add -t v1.1.1 <URL> extern/foo`. 
Thanks in advance! 
Jonas
Message 1 of 1 in “Adding existing repo at sub-sub-directory as submodule”
  1. Jonas SchulzeSep 15, 2022

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.