summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorJens Lehmann <Jens.Lehmann@web.de>2012-03-04 21:15:36 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-03-05 05:22:35 (GMT)
commit69c3051780d6cacfe242563296160634dc667a90 (patch)
tree425c8b1f7802131449da2fc9182a26791cbba97e /git-submodule.sh
parentd75219b4a8a9c44520ddca234cde992498383b89 (diff)
downloadgit-69c3051780d6cacfe242563296160634dc667a90.zip
git-69c3051780d6cacfe242563296160634dc667a90.tar.gz
git-69c3051780d6cacfe242563296160634dc667a90.tar.bz2
submodules: refactor computation of relative gitdir path
In module_clone() the rel_gitdir variable was computed differently when "git rev-parse --git-dir" returned a relative path than when it returned an absolute path. This is not optimal, as different code paths are used depending on the return value of that command. Fix that by reusing the differing path components computed for setting the core.worktree config setting, which leaves a single code path for setting both instead of having three and makes the code much shorter. This also fixes the bug that in the computation of how many directories have to be traversed up to hit the root directory of the submodule the name of the submodule was used where the path should have been used. This lead to problems after renaming submodules into another directory level. Even though the "(cd $somewhere && pwd)" approach breaks the flexibility of symlinks, that is no issue here as we have to have one relative path pointing from the work tree to the gitdir and another pointing back, which will never work anyway when a symlink along one of those paths is changed because the directory it points to was moved. Also add a test moving a submodule into a deeper directory to catch any future breakage here and to document what has to be done when a submodule needs to be moved until git mv learns to do that. Simply moving it to the new location doesn't work, as the core.worktree and possibly the gitfile setting too will be wrong. So it has to be removed from filesystem and index, then the new location has to be added into the index and the .gitmodules file has to be updated. After that a git submodule update will check out the submodule at the new location. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh30
1 files changed, 6 insertions, 24 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index c405caa..a9e9822 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -132,30 +132,11 @@ module_clone()
gitdir_base=
name=$(module_name "$path" 2>/dev/null)
test -n "$name" || name="$path"
- base_path=$(dirname "$path")
+ base_name=$(dirname "$name")
gitdir=$(git rev-parse --git-dir)
- gitdir_base="$gitdir/modules/$base_path"
- gitdir="$gitdir/modules/$path"
-
- case $gitdir in
- /*)
- a="$(cd_to_toplevel && pwd)/"
- b=$gitdir
- while [ "$b" ] && [ "${a%%/*}" = "${b%%/*}" ]
- do
- a=${a#*/} b=${b#*/};
- done
-
- rel="$a$name"
- rel=`echo $rel | sed -e 's|[^/]*|..|g'`
- rel_gitdir="$rel/$b"
- ;;
- *)
- rel=`echo $name | sed -e 's|[^/]*|..|g'`
- rel_gitdir="$rel/$gitdir"
- ;;
- esac
+ gitdir_base="$gitdir/modules/$base_name"
+ gitdir="$gitdir/modules/$name"
if test -d "$gitdir"
then
@@ -168,8 +149,6 @@ module_clone()
die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
fi
- echo "gitdir: $rel_gitdir" >"$path/.git"
-
a=$(cd "$gitdir" && pwd)/
b=$(cd "$path" && pwd)/
# Remove all common leading directories after a sanity check
@@ -185,6 +164,9 @@ module_clone()
a=${a%/}
b=${b%/}
+ rel=$(echo $b | sed -e 's|[^/]*|..|g')
+ echo "gitdir: $rel/$a" >"$path/.git"
+
rel=$(echo $a | sed -e 's|[^/]*|..|g')
(clear_local_git_env; cd "$path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
}