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

Re: Making submodules easier to work with (auto-update on checkout or merge, stash & restore submodules)

From
Andreas Ericsson <ae@op5.se>
Date
Apr 30, 2008, 06:14 UTC
Message-ID
<48180E2D.6020907@op5.se>
In-Reply-To
<8B885217-8C18-417E-8F11-BB6661792CD3@gmail.com>
Tim Harper wrote:
Show 50 quoted lines
> OVERVIEW:
> On the Git TextMate Bundle, I've automated a lot of the submodule 
> commands to make them not a terrible pain to work with. (don't get me 
> wrong - I really like the git submodule implementation, I just don't 
> like how hard it is to work with).
> 
> "WARTS" WITH EXISTING IMPLEMENTATION
> 1) The submodule stays in the working copy when changing to a branch 
> that does not have a submodule.  This can break a build and cause 
> problems.  To work around, I have to delete the folder completely 
> (git-clean).  Then, when I switch back to the branch again, I have to 
> re-download the submodule.
> 2) I have to type "git checkout branch && git submodule init && git 
> submodule update" to be sure that I really have the whole contents of 
> the branch.  That's 3 commands, and a lot of typing.
> 3) If I don't run "git submodule update", and carelessly run "git commit 
> -a" or "git add .", I risk propagating a submodule version from another 
> branch or undoing an important change.
> 
> SUGGESTED ALGORITHM (AS HAS BEEN IMPLEMENTED IN THE GIT TEXTMATE BUNDLE)
> When pulling / merging / changing branches:
> 1) cache all submodules to ~/.git/submodules_cache
>    a) move from the working directory to a folder that is a MD5 hex-hash 
> of both the submodule path and the submodule url
> 2) execute the pull / merge / branch change
> 3) restore all defined submodules to ~/.git/submodules_cache (only the 
> submodules that are still defined after the merge / change / pull)
> 4) execute git submodule init && git submodule update
> 
> 
> PITFALLS:
> pitfall)
> If you commit a change on a submodule that's not on a branch, 
> auto-updating submodules will make it difficult to revive that change.
> 
> workaround)
> Don't allow the user to commit unless they are on a branch.
> 
> ... couldn't think of anymore.  Anyone?
> 
> CONCLUSION
> So far, this algorithm holds up well in my use cases, and has made 
> submodule management seamless for me (I don't have to know that I'm 
> working with submodules).  It's resolved every one of the above outlined 
> interface warts.
> 
> Would it be a good idea to build this algorithm into git?  What would be 
> the best approach?  Am I completely overlooking something by designing 
> the Git TextMate bundle to handle submodules this way?
> 

I don't use submodules at the moment, but I have several "lib-ish" pieces of code that would benefit greatly from becoming submodules. The not-exactly seamlessness of them has so far been a hindrance though, but it sounds as if your changes (assuming they don't affect anything else) should make lessen the submodule headaches somewhat.

So, where be the patches?
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Previous: Tim HarperNext: Johannes Schindelin
Message 3 of 22 in “Making submodules easier to work with (auto-update on checkout or merge, stash & restore submodules)”
  1. Tim HarperApr 30, 2008
  2. Tim HarperApr 30, 2008
  3. Andreas EricssonApr 30, 2008
  4. Johannes SchindelinApr 30, 2008
  5. Avery PennarunApr 30, 2008
  6. Ping YinApr 30, 2008
  7. Roman ShaposhnikApr 30, 2008
  8. Avery PennarunApr 30, 2008
  9. Tim HarperApr 30, 2008
  10. Avery PennarunApr 30, 2008
  11. Tim HarperApr 30, 2008
  12. Avery PennarunApr 30, 2008
  13. Roman ShaposhnikApr 30, 2008
  14. Avery PennarunApr 30, 2008
  15. Finn Arne GangstadMay 1, 2008
  16. Avery PennarunMay 1, 2008
  17. Roman ShaposhnikMay 6, 2008
  18. Avery PennarunMay 7, 2008
  19. Ping YinMay 8, 2008
  20. Steven GrimmMay 1, 2008
  21. Roman ShaposhnikMay 6, 2008
  22. Ping YinMay 1, 2008

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.