From ac8463d2b4c0e88011c40985bc519c0e2e2f2278 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Tue, 3 Mar 2009 16:08:20 +0100 Subject: git submodule: Add test cases for git submodule add Add simple test cases for adding and initialising submodules. The init step is necessary in order to verify the added information. The second test exposes a known breakage due to './' in the path: git ls-files simplifies the path but git add does not, which leads to git init looking for different lines in .gitmodules than git add adds. The other tests add test cases for '//' and '..' in the path which currently fail for the same reason. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2ec7ac6..132d0b9 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -47,6 +47,55 @@ test_expect_success 'Prepare submodule testing' ' GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git ' +test_expect_success 'Prepare submodule add testing' ' + submodurl=$(pwd) + ( + mkdir addtest && + cd addtest && + git init + ) +' + +test_expect_success 'submodule add' ' + ( + cd addtest && + git submodule add "$submodurl" submod && + git submodule init + ) +' + +test_expect_failure 'submodule add with ./ in path' ' + ( + cd addtest && + git submodule add "$submodurl" ././dotsubmod/./frotz/./ && + git submodule init + ) +' + +test_expect_failure 'submodule add with // in path' ' + ( + cd addtest && + git submodule add "$submodurl" slashslashsubmod///frotz// && + git submodule init + ) +' + +test_expect_failure 'submodule add with /.. in path' ' + ( + cd addtest && + git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && + git submodule init + ) +' + +test_expect_failure 'submodule add with ./, /.. and // in path' ' + ( + cd addtest && + git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && + git submodule init + ) +' + test_expect_success 'status should fail for unmapped paths' ' if git submodule status then -- cgit v0.10.2-6-g49f6 From db75ada559dd4de99fedd1fc4f62a9273f032dd3 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Tue, 3 Mar 2009 16:08:21 +0100 Subject: git submodule: Fix adding of submodules at paths with ./, .. and // 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. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano diff --git a/git-submodule.sh b/git-submodule.sh index 2f47e06..68d6afd 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -166,9 +166,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|\([^/]*\)/\.\./|| + 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 132d0b9..21c19a2 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/a/b/c/d/../../../../frotz//.. && -- cgit v0.10.2-6-g49f6