git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Submodules always use a relative path to gitdir
@ 2011-12-29 21:00 Antony Male
  2011-12-29 22:40 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Antony Male @ 2011-12-29 21:00 UTC (permalink / raw)
  To: git; +Cc: gitster, iveqy, Antony Male

This fixes a problem where moving a git repository with checked-out
submodules would cause a fatal error when commands such as 'git
submodule update' were run.

Git submoule clone uses git clone --separate-git-dir to checkout a
submodule's git repository into <supermodule>/.git/modules, if this
folder does not already exist. git clone --separate-git-dir was
designed for a scenario where the git repository stays in one location
and the working copy can be moved. Therefore the .git file in the
working copy uses an absolute path to specify the location of the
repository.

In the submodules scenario, neither the git repository nor the working
copy will be moved relative to each other. However, the supermodule may
be moved, which moves both the submodule's git repository and its
working copy. This means that the submodule's .git file no longer
points to its repository, causing the error.

Previously, if git submodule clone was called when the submodule's git
repository already existed in <supermodule>/.git/modules, it would
simply re-create the submodule's .git file, using a relative path.
This patch uses the above mechanism to re-write the .git file after git
clone --separate-git-dir is run, replacing the absolute path with a
relative one.

An alternative patch would teach git-clone an option to control whether
an absolute or relative path is used when --separate-git-dir is passed.

Signed-off-by: Antony Male <antony.male@gmail.com>
---
 git-submodule.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 3adab93..18eb5ff 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -159,7 +159,6 @@ module_clone()
 	if test -d "$gitdir"
 	then
 		mkdir -p "$path"
-		echo "gitdir: $rel_gitdir" >"$path/.git"
 		rm -f "$gitdir/index"
 	else
 		mkdir -p "$gitdir_base"
@@ -171,6 +170,7 @@ module_clone()
 		fi ||
 		die "$(eval_gettext "Clone of '\$url' into submodule path '\$path' failed")"
 	fi
+	echo "gitdir: $rel_gitdir" >"$path/.git"
 }
 
 #
-- 
1.7.8

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-01-06 18:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-29 21:00 [PATCH] Submodules always use a relative path to gitdir Antony Male
2011-12-29 22:40 ` Junio C Hamano
2011-12-31 21:28   ` Phil Hord
2012-01-03 18:45     ` Junio C Hamano
2012-01-03 19:58       ` Junio C Hamano
2012-01-01 14:58   ` Jens Lehmann
2012-01-03 18:27     ` Junio C Hamano
2012-01-03 22:10       ` Jens Lehmann
2012-01-03 22:17         ` Junio C Hamano
2012-01-05 22:52           ` Jens Lehmann
2012-01-06  0:11             ` Junio C Hamano
2012-01-06 14:26               ` Phil Hord
2012-01-06 15:07                 ` Nguyen Thai Ngoc Duy
2012-01-06 18:53                 ` Junio C Hamano
2011-12-29 22:48 ` Fredrik Gustafsson
2011-12-31 20:31 ` Phil Hord

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).