From: Jens Lehmann <Jens.Lehmann@web.de>
To: Jon Seymour <jon.seymour@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [RFC] submodule: fix handling of supermodules with relative origin URLs.
Date: Fri, 18 May 2012 21:58:03 +0200 [thread overview]
Message-ID: <4FB6A9CB.5050702@web.de> (raw)
In-Reply-To: <1337343220-26717-1-git-send-email-jon.seymour@gmail.com>
Am 18.05.2012 14:13, schrieb Jon Seymour:
> Prior to this change, operations such as git submodule sync produces
> the wrong result when the origin URL of the super module
> is itself a relative URL.
>
> The issue arises because in this case, the origin URL of the supermodule
> needs to be prepended with a prefix that navigates from the submodule to
> the supermodule.
>
> This change adds that prefix.
Thanks, sounds sane. Please see my comments below.
> Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
> ---
> git-submodule.sh | 39 +++++++++++++++++++++++----------------
> 1 file changed, 23 insertions(+), 16 deletions(-)
>
> If people are ok with the fix, I'll roll this as a patch together
> with some tests.
Yeah, tests would be great (and while at it please drop the trailing
'.' from the subject ;-).
This version of the patch does break some existing tests, but your
follow up suggests you already found that out yourself ;-)
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 64a70d6..5008867 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -37,7 +37,8 @@ resolve_relative_url ()
> remoteurl=$(git config "remote.$remote.url") ||
> remoteurl=$(pwd) # the repository is its own authoritative upstream
> url="$1"
> - remoteurl=${remoteurl%/}
> + up_path="$(echo "$2" | sed "s/[^/]*/../g")"
Me thinks up_path should be set in the case below, which is the only
place where it is used.
> + remoteurl=${remoteurl%/*}
As you mentioned in your follow up this change is not correct.
> sep=/
> while test -n "$url"
> do
> @@ -45,6 +46,9 @@ resolve_relative_url ()
> ../*)
> url="${url#../}"
> case "$remoteurl" in
> + .*/*)
up_path should be set here.
> + remoteurl="${up_path%/}/${remoteurl%/*}"
> + ;;
> */*)
> remoteurl="${remoteurl%/*}"
> ;;
> @@ -235,11 +239,24 @@ cmd_add()
> usage
> fi
>
> + # normalize path:
> + # multiple //; leading ./; /./; /../; trailing /
> + sm_path=$(printf '%s/\n' "$sm_path" |
> + sed -e '
> + s|//*|/|g
> + s|^\(\./\)*||
> + s|/\./|/|g
> + :start
> + s|\([^/]*\)/\.\./||
> + tstart
> + s|/*$||
> + ')
> +
> # assure repo is absolute or relative to parent
> case "$repo" in
> ./*|../*)
> # dereference source url relative to parent's url
> - realrepo=$(resolve_relative_url "$repo") || exit
> + realrepo=$(resolve_relative_url "$repo" "$sm_path") || exit
> ;;
> *:*|/*)
> # absolute url
> @@ -250,18 +267,6 @@ cmd_add()
> ;;
> esac
>
> - # normalize path:
> - # multiple //; leading ./; /./; /../; trailing /
> - sm_path=$(printf '%s/\n' "$sm_path" |
> - sed -e '
> - s|//*|/|g
> - s|^\(\./\)*||
> - s|/\./|/|g
> - :start
> - s|\([^/]*\)/\.\./||
> - tstart
> - s|/*$||
> - ')
> git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
> die "$(eval_gettext "'\$sm_path' already exists in the index")"
>
> @@ -401,13 +406,14 @@ cmd_init()
> if test -z "$(git config "submodule.$name.url")"
> then
> url=$(git config -f .gitmodules submodule."$name".url)
> + sm_path=$(git config -f .gitmodules submodule."$name".path)
Isn't sm_path already set correctly here? I think this line should
be dropped.
> test -z "$url" &&
> die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
>
> # Possibly a url relative to parent
> case "$url" in
> ./*|../*)
> - url=$(resolve_relative_url "$url") || exit
> + url=$(resolve_relative_url "$url" "$sm_path") || exit
> ;;
> esac
> git config submodule."$name".url "$url" ||
> @@ -960,11 +966,12 @@ cmd_sync()
> do
> name=$(module_name "$sm_path")
> url=$(git config -f .gitmodules --get submodule."$name".url)
> + sm_path=$(git config -f .gitmodules --get submodule."$name".path)
Same here.
>
> # Possibly a url relative to parent
> case "$url" in
> ./*|../*)
> - url=$(resolve_relative_url "$url") || exit
> + url=$(resolve_relative_url "$url" "$sm_path") || exit
> ;;
> esac
>
Other than that the patch looks fine.
next prev parent reply other threads:[~2012-05-18 19:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <AH3Anrr6mLVedBPcgfVwy=5KRjUgdp5W8P0DQ3qaX_UjH-npDw@mail.gmail.com>
2012-05-18 12:13 ` [RFC] submodule: fix handling of supermodules with relative origin URLs Jon Seymour
2012-05-18 12:16 ` Jon Seymour
2012-05-18 19:58 ` Jens Lehmann [this message]
2012-05-18 21:45 ` Jon Seymour
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FB6A9CB.5050702@web.de \
--to=jens.lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jon.seymour@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).