summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-03-21 23:08:27 -0700
committerJunio C Hamano <gitster@pobox.com>2009-03-21 23:08:27 -0700
commit8af95ca0174f05344e36d05b61844c8af4764b92 (patch)
tree90af6ed4c1ef939ebf90b0e6be2f0d59638782c2 /git-submodule.sh
parent2aa93deec047763cff750196610268fd7227cfc9 (diff)
parentdb75ada559dd4de99fedd1fc4f62a9273f032dd3 (diff)
downloadgit-8af95ca0174f05344e36d05b61844c8af4764b92.tar.gz
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
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh15
1 files changed, 12 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"