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 --- git-submodule.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'git-submodule.sh') diff --git a/git-submodule.sh b/git-submodule.sh index 2f47e065fe..68d6afd15c 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" -- cgit v1.2.3