submodules: always use a relative path to gitdir

Since recently a submodule with name <name> has its git directory in the .git/modules/<name> directory of the superproject while the work tree contains a gitfile pointing there. When the submodule git directory needs to be cloned because it is not found in .git/modules/<name> the clone command will write an absolute path into the gitfile. When no clone is necessary the git directory will be reactivated by the git-submodule.sh script by writing a relative path into the gitfile. This is inconsistent, as the behavior depends on the submodule having been cloned before into the .git/modules of the superproject. A relative path is preferable here because it allows the superproject to be moved around without invalidating the gitfile. We do that by always writing the relative path into the gitfile, which overwrites the absolute path the clone command may have written there. This is only the first step to make superprojects movable again like they were before the separate-git-dir approach was introduced. The second step is to use a relative path in core.worktree too. Enhance t7400 to ensure that future versions won't re-add absolute paths by accident. While at it also replace an if/else construct evaluating the presence of the 'reference' option with a single line of bash code. Reported-by: Antony Male <antony.male@gmail.com> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Mar 4, 2012 at 22:14 UTC ea115a0d43d176f873855f9a7372376161dd8e65
2 files changed +6 -7
git-submodule.sh
+4 -7
@@ -160,18 +160,15 @@ module_clone()
160 if test -d "$gitdir"
161 then
162 mkdir -p "$path"
163 - echo "gitdir: $rel_gitdir" >"$path/.git"
163 rm -f "$gitdir/index"
164 else
165 mkdir -p "$gitdir_base"
167 - if test -n "$reference"
168 - then
169 - git-clone $quiet "$reference" -n "$url" "$path" --separate-git-dir "$gitdir"
170 - else
171 - git-clone $quiet -n "$url" "$path" --separate-git-dir "$gitdir"
172 - fi ||
166 + git clone $quiet -n ${reference:+"$reference"} \
167 + --separate-git-dir "$gitdir" "$url" "$path" ||
168 die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
169 fi
170 +
171 + echo "gitdir: $rel_gitdir" >"$path/.git"
172 }
173
174 #
t/t7400-submodule-basic.sh
+2
@@ -79,6 +79,8 @@ test_expect_success 'submodule add' '
79 cd addtest &&
80 git submodule add -q "$submodurl" submod >actual &&
81 test ! -s actual &&
82 + echo "gitdir: ../.git/modules/submod" >expect &&
83 + test_cmp expect submod/.git &&
84 git submodule init
85 ) &&
86