summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-03-08 13:04:52 -0800
committerJunio C Hamano <gitster@pobox.com>2012-03-08 13:04:52 -0800
commit7ac6609d9afde0d56705842fd60abb41715c1d1e (patch)
tree94cef0f47010b1c306b0a29df22026a6e5fc8fd0
parentaa145bf6f1cb45ad66250c40da3cd708956cf71e (diff)
parent4dce7d9b408b2935b85721b54a2010eda7ec1be9 (diff)
downloadgit-7ac6609d9afde0d56705842fd60abb41715c1d1e.tar.gz
Merge branch 'jl/maint-submodule-relative'
By Jens Lehmann (3) and Johannes Sixt (1) * jl/maint-submodule-relative: submodules: fix ambiguous absolute paths under Windows submodules: refactor computation of relative gitdir path submodules: always use a relative path from gitdir to work tree submodules: always use a relative path to gitdir
-rwxr-xr-xgit-submodule.sh58
-rwxr-xr-xt/t7400-submodule-basic.sh22
-rwxr-xr-xt/t7406-submodule-update.sh17
3 files changed, 68 insertions, 29 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 9bb2e13e92..efc86ad4e0 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -132,46 +132,46 @@ 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
mkdir -p "$path"
- echo "gitdir: $rel_gitdir" >"$path/.git"
rm -f "$gitdir/index"
else
mkdir -p "$gitdir_base"
- if test -n "$reference"
- then
- git-clone $quiet "$reference" -n "$url" "$path" --separate-git-dir "$gitdir"
- else
- git-clone $quiet -n "$url" "$path" --separate-git-dir "$gitdir"
- fi ||
+ git clone $quiet -n ${reference:+"$reference"} \
+ --separate-git-dir "$gitdir" "$url" "$path" ||
die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
fi
+
+ a=$(cd "$gitdir" && pwd)/
+ b=$(cd "$path" && pwd)/
+ # normalize Windows-style absolute paths to POSIX-style absolute paths
+ case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac
+ case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac
+ # Remove all common leading directories after a sanity check
+ if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then
+ die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")"
+ fi
+ while test "${a%%/*}" = "${b%%/*}"
+ do
+ a=${a#*/}
+ b=${b#*/}
+ done
+ # Now chop off the trailing '/'s that were added in the beginning
+ 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")
}
#
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 695f7afdf3..b377a7af28 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -79,6 +79,15 @@ test_expect_success 'submodule add' '
cd addtest &&
git submodule add -q "$submodurl" submod >actual &&
test ! -s actual &&
+ echo "gitdir: ../.git/modules/submod" >expect &&
+ test_cmp expect submod/.git &&
+ (
+ cd submod &&
+ git config core.worktree >actual &&
+ echo "../../../submod" >expect &&
+ test_cmp expect actual &&
+ rm -f actual expect
+ ) &&
git submodule init
) &&
@@ -498,4 +507,17 @@ test_expect_success 'relative path works with user@host:path' '
)
'
+test_expect_success 'moving the superproject does not break submodules' '
+ (
+ cd addtest &&
+ git submodule status >expect
+ )
+ mv addtest addtest2 &&
+ (
+ cd addtest2 &&
+ git submodule status >actual &&
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 5b97222c48..dcb195b4cf 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -619,4 +619,21 @@ test_expect_success 'submodule add properly re-creates deeper level submodules'
)
'
+test_expect_success 'submodule update properly revives a moved submodule' '
+ (cd super &&
+ git commit -am "pre move" &&
+ git status >expect&&
+ H=$(cd submodule2; git rev-parse HEAD) &&
+ git rm --cached submodule2 &&
+ rm -rf submodule2 &&
+ mkdir -p "moved/sub module" &&
+ git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
+ git config -f .gitmodules submodule.submodule2.path "moved/sub module"
+ git commit -am "post move" &&
+ git submodule update &&
+ git status >actual &&
+ test_cmp expect actual
+ )
+'
+
test_done