git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonas Schulze <jschulze@mpi-magdeburg.mpg.de>
To: git <git@vger.kernel.org>
Subject: Adding existing repo at sub-sub-directory as submodule
Date: Thu, 15 Sep 2022 12:49:26 +0200 (CEST)	[thread overview]
Message-ID: <1678038401.2138998.1663238966604.JavaMail.zimbra@mpi-magdeburg.mpg.de> (raw)

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

                 reply	other threads:[~2022-09-15 10:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1678038401.2138998.1663238966604.JavaMail.zimbra@mpi-magdeburg.mpg.de \
    --to=jschulze@mpi-magdeburg.mpg.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).