git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antony Male <antony.male@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, iveqy@iveqy.com, Antony Male <antony.male@gmail.com>
Subject: [PATCH] Submodules always use a relative path to gitdir
Date: Thu, 29 Dec 2011 21:00:26 +0000	[thread overview]
Message-ID: <1325192426-10103-1-git-send-email-antony.male@gmail.com> (raw)

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

             reply	other threads:[~2011-12-29 21:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-29 21:00 Antony Male [this message]
2011-12-29 22:40 ` [PATCH] Submodules always use a relative path to gitdir 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325192426-10103-1-git-send-email-antony.male@gmail.com \
    --to=antony.male@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=iveqy@iveqy.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).