Re: Submodule using different repository URLs
- From
Peter Voss <info@petervoss.org>
- Date
- Jul 13, 2009, 13:33 UTC
- Message-ID
- <9B026405-27EB-4D48-8D08-461D213453C3@petervoss.org>
- In-Reply-To
- <200907131443.25719.johan@herland.net>
Hi Johan,
On 13.07.2009, at 14:43, Johan Herland wrote:
Show 31 quoted lines
> On Monday 13 July 2009, Johan Herland wrote:
>> On Monday 13 July 2009, Peter Voss wrote:
>>> On 13.07.2009, at 12:59, Johan Herland wrote:
>>>> You might be able to pull this off using relative submodule URLs.
>>>
>>> That's a good hint. Unfortunately I can't use this to go up 2
>>> directories. I.e. I can't get from
>>> git@github.com:xxx/mymodule.git
>>> to
>>> git@github.com:yyy/foo.git
>>>
>>> Using the relative URL ../../yyy/foo.git leads to the result:
>>> Clone of 'git@github.com:xxx/yyy/foo.git' into submodule path 'foo'
>>> failed
>>>
>>> So I basically cannot replace the xxx part.
>>
>> This is due to a small bug in git-submodule.sh. In the
>> resolve_relative_url() function, when repeatedly unwrapping '../'s
>> from $url in the while loop, the line remoteurl="${remoteurl%/*}"
>> removes everything _after_ the last slash, which does not work for
>> the git@github.com:xxx part of your URL.
>>
>> This should be relatively easy to fix, although maybe not as
>> straightforwardly trivial as it might seem at first sight.
>>
>> I don't have the time to look into this now, so feel free to take a
>> stab at it.
>
> Here's a first stab at it (TOTALLY UNTESTED). Obviously it needs a
> testcase (typically in t7400-submodule-basic.sh) as well.And I thought you didn't have time. ;-) Thanks for this patch. I will test this out tomorrow.
Thanks, --Peter
Show 46 quoted lines
>
>
> Have fun! :)
>
> ...Johan
>
>
> diff --git a/git-submodule.sh b/git-submodule.sh
> index ebed711..7d8f7a7 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -27,12 +27,19 @@ resolve_relative_url ()
> die "remote ($remote) does not have a url defined in .git/config"
> url="$1"
> remoteurl=${remoteurl%/}
> + sep="/"
> while test -n "$url"
> do
> case "$url" in
> ../*)
> url="${url#../}"
> - remoteurl="${remoteurl%/*}"
> + newremoteurl="${remoteurl%/*}"
> + if test "$newremoteurl" = "$remoteurl" -a "$sep" = "/"
> + then
> + newremoteurl="${remoteurl%:*}"
> + sep=":"
> + fi
> + remoteurl="$newremoteurl"
> ;;
> ./*)
> url="${url#./}"
> @@ -41,7 +48,7 @@ resolve_relative_url ()
> break;;
> esac
> done
> - echo "$remoteurl/${url%/}"
> + echo "$remoteurl$sep${url%/}"
> }
>
> #
>
>
> --
> Johan Herland, <johan@herland.net>
> www.herland.net