git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell Yanofsky <russ@yanofsky.org>
To: git@vger.kernel.org
Cc: Russell Yanofsky <russ@yanofsky.org>
Subject: [PATCH 1/1] git-submodule.sh: fix relative paths with ssh urls
Date: Thu,  2 Dec 2010 21:53:41 -0500	[thread overview]
Message-ID: <1291344821-20964-1-git-send-email-russ@yanofsky.org> (raw)

Fix handling of submodule urls starting with ../ when the remote url is
an scp-style URL with the format user@host.xz:repo.git. For example, if
the remote url is user@host.xz:repo.git and the submodule URL is
../submodule.git, the combined default URL will now be
user@host.xz:submodule.git instead of
user@host.xz:repo.git/submodule.git.
---
 git-submodule.sh |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index c291eed..533cf5d 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -36,13 +36,25 @@ resolve_relative_url ()
 	remoteurl=$(git config "remote.$remote.url") ||
 		die "remote ($remote) does not have a url defined in .git/config"
 	url="$1"
+	sep="/"
 	remoteurl=${remoteurl%/}
 	while test -n "$url"
 	do
 		case "$url" in
 		../*)
 			url="${url#../}"
-			remoteurl="${remoteurl%/*}"
+			remoteparent="${remoteurl%/*}"
+			if test "$remoteparent" != "$remoteurl"
+			then
+				remoteurl="$remoteparent"
+			else
+				remoteparent="${remoteurl%:*}"
+				if test "$remoteparent" != "$remoteurl"
+				then
+					remoteurl="$remoteparent"
+					sep=":"
+				fi
+			fi
 			;;
 		./*)
 			url="${url#./}"
@@ -51,7 +63,7 @@ resolve_relative_url ()
 			break;;
 		esac
 	done
-	echo "$remoteurl/${url%/}"
+	echo "$remoteurl$sep${url%/}"
 }
 
 #
-- 
1.7.3.2

                 reply	other threads:[~2010-12-03  3:02 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=1291344821-20964-1-git-send-email-russ@yanofsky.org \
    --to=russ@yanofsky.org \
    --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).