Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-03-22 09:08:27 +0300
committerJunio C Hamano <gitster@pobox.com>2009-03-22 09:08:27 +0300
commit8af95ca0174f05344e36d05b61844c8af4764b92 (patch)
tree90af6ed4c1ef939ebf90b0e6be2f0d59638782c2
parent2aa93deec047763cff750196610268fd7227cfc9 (diff)
parentdb75ada559dd4de99fedd1fc4f62a9273f032dd3 (diff)
Merge branch 'mg/maint-submodule-normalize-path' into maint
* mg/maint-submodule-normalize-path: git submodule: Fix adding of submodules at paths with ./, .. and // git submodule: Add test cases for git submodule add
-rwxr-xr-xgit-submodule.sh15
-rwxr-xr-xt/t7400-submodule-basic.sh49
2 files changed, 61 insertions, 3 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 204aab671e..0a27232b90 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|\([^/]*\)/\.\./||
+ 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 b8cb2df667..af690ec6c1 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_success 'submodule add with ./ in path' '
+ (
+ cd addtest &&
+ git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
+ git submodule init
+ )
+'
+
+test_expect_success 'submodule add with // in path' '
+ (
+ cd addtest &&
+ git submodule add "$submodurl" slashslashsubmod///frotz// &&
+ git submodule init
+ )
+'
+
+test_expect_success 'submodule add with /.. in path' '
+ (
+ cd addtest &&
+ git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
+ git submodule init
+ )
+'
+
+test_expect_success '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