git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Submodules always use a relative path to gitdir

From
Antony Male <antony.male@gmail.com>
Date
Dec 29, 2011, 21:00 UTC
Message-ID
<1325192426-10103-1-git-send-email-antony.male@gmail.com>

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
Next: Junio C Hamano
Message 1 of 16 in “Submodules always use a relative path to gitdir”
  1. Submodules always use a relative path to gitdirAntony Male, Dec 29, 2011
  2. Junio C HamanoDec 29, 2011
  3. Phil HordDec 31, 2011
  4. Junio C HamanoJan 3, 2012
  5. Junio C HamanoJan 3, 2012
  6. Jens LehmannJan 1, 2012
  7. Junio C HamanoJan 3, 2012
  8. Jens LehmannJan 3, 2012
  9. Junio C HamanoJan 3, 2012
  10. Jens LehmannJan 5, 2012
  11. Junio C HamanoJan 6, 2012
  12. Phil HordJan 6, 2012
  13. Nguyen Thai Ngoc DuyJan 6, 2012
  14. Junio C HamanoJan 6, 2012
  15. Fredrik GustafssonDec 29, 2011
  16. Phil HordDec 31, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.