Skip to content

Commit

Permalink
git submodule: Fix adding of submodules at paths with ./, .. and //
Browse files Browse the repository at this point in the history
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 <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael J Gruber authored and Junio C Hamano committed Mar 4, 2009
1 parent ac8463d commit db75ada
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 4 additions & 4 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ 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/./ &&
git submodule init
)
'

test_expect_failure 'submodule add with // in path' '
test_expect_success 'submodule add with // in path' '
(
cd addtest &&
git submodule add "$submodurl" slashslashsubmod///frotz// &&
git submodule init
)
'

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/.. &&
git submodule init
)
'

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//.. &&
Expand Down

0 comments on commit db75ada

Please sign in to comment.