git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael J Gruber <git@drmicha.warpmail.net>
To: git@vger.kernel.org
Cc: Johannes Sixt <j.sixt@viscovery.net>,
	Andrei Thorp <garoth@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCHv3 2/2] git submodule: Fix adding of submodules at paths with ./, .. and //
Date: Tue,  3 Mar 2009 13:39:49 +0100	[thread overview]
Message-ID: <1236083989-20526-3-git-send-email-git@drmicha.warpmail.net> (raw)
In-Reply-To: <1236083989-20526-2-git-send-email-git@drmicha.warpmail.net>

Make 'git submodule add' normalize the submodule path in the
same way as 'git ls-files' does, so that 'git submodule init' looks up
the information in .gitmodules with the same key under which 'git
submodule add' stores it.

This fixes 4 known breakages.
---
Note that sed on AIX does not like comments, which is why they are not
in the sed expression.

 git-submodule.sh           |   15 ++++++++++++---
 t/t7400-submodule-basic.sh |    8 ++++----
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 204aab6..7a25f47 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -167,9 +167,18 @@ cmd_add()
 	;;
 	esac
 
-	# strip trailing slashes from path
-	path=$(echo "$path" | sed -e 's|/*$||')
-
+	# normalize path:
+	# multiple //; leading ./; /./; /../; trailing /
+	path=$(printf '%s/\n' "$path" |
+		sed -e '
+			s|//*|/|g
+			s|^\(\./\)*||
+			s|/\./|/|g
+			:start
+			s|\([^/]*\)/\.\./||g
+			tstart
+			s|/*$||
+		')
 	git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
 	die "'$path' already exists in the index"
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 4f42585..1c82f8c 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -64,7 +64,7 @@ test_expect_success 'submodule add' '
 	)
 '
 
-test_expect_failure 'submodule add with ./ in path' '
+test_expect_success 'submodule add with ./ in path' '
 	(
 		cd addtest &&
 		git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
@@ -72,7 +72,7 @@ test_expect_failure 'submodule add with ./ in path' '
 	)
 '
 
-test_expect_failure 'submodule add with // in path' '
+test_expect_success 'submodule add with // in path' '
 	(
 		cd addtest &&
 		git submodule add "$submodurl" slashslashsubmod///frotz// &&
@@ -80,7 +80,7 @@ test_expect_failure 'submodule add with // in path' '
 	)
 '
 
-test_expect_failure 'submodule add with /.. in path' '
+test_expect_success 'submodule add with /.. in path' '
 	(
 		cd addtest &&
 		git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
@@ -88,7 +88,7 @@ test_expect_failure 'submodule add with /.. in path' '
 	)
 '
 
-test_expect_failure 'submodule add with ./, /.. and // in path' '
+test_expect_success 'submodule add with ./, /.. and // in path' '
 	(
 		cd addtest &&
 		git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/frotz//.. &&
-- 
1.6.2.rc2

  reply	other threads:[~2009-03-03 12:41 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <80055d7c0902241541o5c8fad50ra4eace5919bcf6df@mail.gmail.com>
2009-02-24 23:56 ` Fwd: Git Submodule Misbehaviour With ./ Andrei Thorp
2009-02-25 11:03   ` [PATCH 0/2] Fix git submodule add for paths with ./ Michael J Gruber
2009-02-25 11:03     ` [PATCH 1/2] git submodule: Add test cases for git submodule add Michael J Gruber
2009-02-25 11:03       ` [PATCH 2/2] git submodule: Fix adding of submodules at paths with ./ Michael J Gruber
2009-02-25 11:21         ` Johannes Sixt
2009-02-25 12:35           ` Michael J Gruber
2009-02-25 13:04             ` Johannes Sixt
2009-02-25 13:26               ` [PATCHv2 0/4] Fix git submodule add for funky paths Michael J Gruber
2009-02-25 13:26                 ` [PATCHv2 1/4] git submodule: Add test cases for git submodule add Michael J Gruber
2009-02-25 13:26                   ` [PATCHv2 2/4] git submodule: Fix adding of submodules at paths with ./ Michael J Gruber
2009-02-25 13:26                     ` [PATCHv2 3/4] git submodule: Add more tests for add with funky paths Michael J Gruber
2009-02-25 13:26                       ` [PATCHv2 4/4] git submodule: Fix handling of // and /.. in paths for added submodules Michael J Gruber
2009-02-25 14:06                         ` Johannes Sixt
2009-02-25 14:33                           ` Michael J Gruber
2009-02-25 15:03                             ` Johannes Sixt
2009-02-25 21:25                               ` Junio C Hamano
2009-02-26  9:05                                 ` Michael J Gruber
2009-02-26 17:04                                   ` Junio C Hamano
2009-03-03 12:39                                     ` [PATCHv3 0/2] git submodule: normalize paths before adding Michael J Gruber
2009-03-03 12:39                                       ` [PATCHv3 1/2] git submodule: Add test cases for git submodule add Michael J Gruber
2009-03-03 12:39                                         ` Michael J Gruber [this message]
2009-03-03 13:08                                           ` [PATCHv3 2/2] git submodule: Fix adding of submodules at paths with ./, .. and // Johannes Sixt
2009-03-03 14:09                                             ` Michael J Gruber
2009-03-03 15:08                                               ` [PATCHv4 0/2] git submodule: normalize paths before adding Michael J Gruber
2009-03-03 15:08                                                 ` [PATCHv4 1/2] git submodule: Add test cases for git submodule add Michael J Gruber
2009-03-03 15:08                                                   ` [PATCHv4 2/2] git submodule: Fix adding of submodules at paths with ./, .. and // Michael J Gruber
2009-03-03 15:28                                                     ` Johannes Sixt
2009-03-03 15:39                                                       ` Michael J Gruber
2009-03-03 16:32                                                 ` [PATCHv4 0/2] git submodule: normalize paths before adding Junio C Hamano
2009-03-03 15:36                                             ` [PATCHv3 2/2] git submodule: Fix adding of submodules at paths with ./, .. and // Junio C Hamano
2009-03-03 15:48                                               ` Michael J Gruber
2009-03-03 14:29                                           ` Johannes Schindelin
2009-03-03 14:58                                             ` Michael J Gruber
2009-02-25 21:25               ` [PATCH 2/2] git submodule: Fix adding of submodules at paths with ./ Junio C Hamano
2009-02-25 21:24       ` [PATCH 1/2] git submodule: Add test cases for git submodule add Junio C Hamano

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=1236083989-20526-3-git-send-email-git@drmicha.warpmail.net \
    --to=git@drmicha.warpmail.net \
    --cc=garoth@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    /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).