# [PATCH] git-submodule - register module url if adding in place

4 messages from 2008-07-08 to 2008-07-09. Participants: Mark Levedahl, Johannes Schindelin.
Thread: https://gitlist.dev/t/14336

## Mark Levedahl, 2008-07-08 02:37

Subject: [PATCH] git-submodule - register module url if adding in place
Message-ID: <1215484630-3784-1-git-send-email-mlevedahl@gmail.com>
URL: https://gitlist.dev/e/1215484630-3784-1-git-send-email-mlevedahl%40gmail.com

```
When adding a new submodule in place, meaning the user created the
submodule as a git repo in the tree first, we don't go through
git submodule init to register the module. Thus, the url is
not stored in .git/config, and no git operation will ever do so. In
this case, assume the url the user supplies to git add is the one
that should be registered, and do so.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
 git-submodule.sh |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 099a7d7..7525922 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -173,6 +173,16 @@ cmd_add()
 		else
 			die "'$path' already exists and is not a valid git repo"
 		fi
+
+		case "$repo" in
+		./*|../*)
+			url=$(resolve_relative_url "$repo") || exit
+		    ;;
+		*)
+			url="$repo"
+			;;
+		esac
+		git config submodule."$path".url "$url"
 	else
 		case "$repo" in
 		./*|../*)
-- 
1.5.6.2.271.g73ad8

```

## Johannes Schindelin, 2008-07-08 11:34

Subject: Re: [PATCH] git-submodule - register module url if adding in place
Message-ID: <alpine.DEB.1.00.0807081332580.4319@eeepc-johanness>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807081332580.4319%40eeepc-johanness
In-Reply-To: <1215484630-3784-1-git-send-email-mlevedahl@gmail.com>

```
Hi,

On Mon, 7 Jul 2008, Mark Levedahl wrote:

> When adding a new submodule in place, meaning the user created the 
> submodule as a git repo in the tree first, we don't go through git 
> submodule init to register the module. Thus, the url is not stored in 
> .git/config, and no git operation will ever do so. In this case, assume 
> the url the user supplies to git add is the one that should be 
> registered, and do so.

I agree with Sylvain here, namely that this is too dangerous.  Imagine 
this very valid scenario:

	$ git clone <somewhere> abc
	$ git submodule add abc

Bummer.

Yes, happened to me.

So I'd like this to be an error, not something that tries to be helpful, 
when it clearly cannot be.

Ciao,
Dscho

```

## Mark Levedahl, 2008-07-08 23:59

Subject: Re: [PATCH] git-submodule - register module url if adding in place
Message-ID: <4873FF6E.2020602@gmail.com>
URL: https://gitlist.dev/e/4873FF6E.2020602%40gmail.com
In-Reply-To: <alpine.DEB.1.00.0807081332580.4319@eeepc-johanness>

```
Johannes Schindelin wrote:
> I agree with Sylvain here, namely that this is too dangerous.  Imagine 
> this very valid scenario:
>
> 	$ git clone <somewhere> abc
> 	$ git submodule add abc
>
> Bummer.
>
> Yes, happened to me.
>
> So I'd like this to be an error, not something that tries to be helpful, 
> when it clearly cannot be.
>
> Ciao,
> Dscho
>
>   
I think the real issue here is that submodule-add is too flexible and 
poorly documented, see my response to Junio in the other thread.

Mark

```

## Johannes Schindelin, 2008-07-09 00:11

Subject: Re: [PATCH] git-submodule - register module url if adding in place
Message-ID: <alpine.DEB.1.00.0807090210080.5277@eeepc-johanness>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807090210080.5277%40eeepc-johanness
In-Reply-To: <4873FF6E.2020602@gmail.com>

```
Hi,

On Tue, 8 Jul 2008, Mark Levedahl wrote:

> Johannes Schindelin wrote:
> > I agree with Sylvain here, namely that this is too dangerous.  
> > Imagine this very valid scenario:
> >
> >  $ git clone <somewhere> abc
> >  $ git submodule add abc
> >
> > Bummer.
> >
> > Yes, happened to me.
> >
> > So I'd like this to be an error, not something that tries to be 
> > helpful, when it clearly cannot be.
>
> I think the real issue here is that submodule-add is too flexible and 
> poorly documented, see my response to Junio in the other thread.

In contrast, I think that we should either disallow the form without URL, 
or get the URL automatically from the submodule's current branch's default 
remote.

Ciao,
Dscho

```
