From: Junio C Hamano Date: Sun, 22 Mar 2009 06:08:27 +0000 (-0700) Subject: Merge branch 'mg/maint-submodule-normalize-path' into maint X-Git-Tag: v1.6.2.2~24 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/8af95ca0174f05344e36d05b61844c8af4764b92?ds=inline;hp=-c 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 --- 8af95ca0174f05344e36d05b61844c8af4764b92 diff --combined git-submodule.sh index 204aab671e,68d6afd15c..0a27232b90 --- a/git-submodule.sh +++ b/git-submodule.sh @@@ -5,7 -5,7 +5,7 @@@ # Copyright (c) 2007 Lars Hjemli USAGE="[--quiet] [--cached] \ -[add [-b branch] ]|[status|init|update [-i|--init]|summary [-n|--summary-limit ] []] \ +[add [-b branch] ]|[status|init|update [-i|--init] [-N|--no-fetch]|summary [-n|--summary-limit ] []] \ [--] [...]|[foreach ]|[sync [--] [...]]" OPTIONS_SPEC= . git-sh-setup @@@ -16,7 -16,6 +16,7 @@@ command branch= quiet= cached= +nofetch= # # print stuff on stdout unless -q was specified @@@ -60,7 -59,7 +60,7 @@@ resolve_relative_url ( # module_list() { - git ls-files --stage -- "$@" | grep '^160000 ' + git ls-files --error-unmatch --stage -- "$@" | grep '^160000 ' } # @@@ -167,9 -166,18 +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" @@@ -301,10 -309,6 +310,10 @@@ cmd_update( shift cmd_init "$@" || return ;; + -N|--no-fetch) + shift + nofetch=1 + ;; --) shift break @@@ -350,16 -354,8 +359,16 @@@ then force="-f" fi - (unset GIT_DIR; cd "$path" && git-fetch && - git-checkout $force -q "$sha1") || + + if test -z "$nofetch" + then + (unset GIT_DIR; cd "$path" && + git-fetch) || + die "Unable to fetch in submodule path '$path'" + fi + + (unset GIT_DIR; cd "$path" && + git-checkout $force -q "$sha1") || die "Unable to checkout '$sha1' in submodule path '$path'" say "Submodule path '$path': checked out '$sha1'" diff --combined t/t7400-submodule-basic.sh index b8cb2df667,21c19a28cf..af690ec6c1 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@@ -47,6 -47,55 +47,55 @@@ test_expect_success 'Prepare submodule 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 @@@ -234,17 -283,4 +283,17 @@@ test_expect_success 'gracefully add sub ' +test_expect_success 'ls-files gracefully handles trailing slash' ' + + test "init" = "$(git ls-files init/)" + +' + +test_expect_success 'submodule warns' ' + + git submodule no-such-submodule 2> output.err && + grep "^error: .*no-such-submodule" output.err + +' + test_done