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

Re: Moving (renaming) submodules, recipe/script

From
W. Trevor King <wking@tremily.us>
Date
Jan 8, 2013, 14:32 UTC
Message-ID
<20130108143214.GA3755@odin.tremily.us>
In-Reply-To
<50EA7269.1080006@web.de>
On Mon, Jan 07, 2013 at 07:59:53AM +0100, Jens Lehmann wrote:
Show 8 quoted lines
> Am 07.01.2013 02:39, schrieb Jonathan Nieder:
> > (just cc-ing Jens and Peter, who might be interested)
> 
> I´m currently working on teaching mv to move submodules and intend
> to send those patches to the list after finishing submodule deinit.
> Please see
>   https://github.com/jlehmann/git-submod-enhancements/commits/mv-submodules
> for the current state of this series.

Thinking about this a bit more, I'm not clear on how out-of-tree updates (i.e. worktree in .git/modules/*/config) propogated during branch checkouts (merges, rebases, etc.). I just got a broken rebase trying to move a trivial patch back before the submodule move, and Git was confused about what had happened to the submodules. Here's a simple script that illustrates the problem:

  #!/bin/sh
  rm -rf a b c
  mkdir a
  (cd a
   git init
   echo a > README
   git add README
   git commit -am 'a'
  )
  git clone a b
  (cd b
   git submodule add ../a submod-1
   git commit -am 'add submodule at submod-1'
  )
  git clone b c
  (cd c
   git submodule update --init
  )
  (cd b
   git-submodule-mv.sh submod-1 submod-2
   git commit -am 'move submodule from submod-1 to submod-2'
  )
  (cd c
   git pull
   ls -d .git/modules/*
   cat .git/modules/submod-1/config
   ls -a submod*
  )

The end result is that `c` gets the `.gitmodules` path updates and new gitlinked directory from the submodule move in `b` (using my git-submodule-mv.sh posted earlier in this thread), but `submod-1` is left lying around (because Git doesn't know that it can remove submod-1/.git and submod-1/README). The Git directory for the submodule stays in .git/modules/submod-1/ (good), but the worktree in .git/modules/submod-1/config still points to ../../../submod-1 (bad).

This means that submodule moves are possible, but anyone trying to share them between several repositories (or trying to rebase across the move within their own repository) is in for a world of suffering ;). I'm not sure how this should be addressed, but I didn't see anything handling it in Jens' new series.

Thanks, Trevor

-- 
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
Previous: W. Trevor KingNext: W. Trevor King
Message 8 of 11 in “Moving (renaming) submodules, recipe/script”
  1. W. Trevor KingJan 7, 2013
  2. Jonathan NiederJan 7, 2013
  3. Jens LehmannJan 7, 2013
  4. Junio C HamanoJan 7, 2013
  5. Jens LehmannJan 7, 2013
  6. Junio C HamanoJan 7, 2013
  7. W. Trevor KingJan 7, 2013
  8. W. Trevor KingJan 8, 2013
  9. W. Trevor KingJan 8, 2013
  10. Jens LehmannJan 8, 2013
  11. W. Trevor KingJan 8, 2013

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.