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

[RFC v3 0/4] Preferred local submodule branches

From
W. Trevor King <wking@tremily.us>
Date
Jan 9, 2014, 06:17 UTC
Message-ID
<cover.1389247320.git.wking@tremily.us>
In-Reply-To
<20140108040627.GD29954@odin.tremily.us>
From: "W. Trevor King" <wking@tremily.us>

In another branch of the submodule thread Francesco kicked off, I mentioned that we could store the preferred local submodule branch on a per-superbranch level if we used the .git/modules/<submodule-name>/config for local overrides [1]. Here's a patch series that greatly extends my v2 "submodule: Respect requested branch on all clones" series [2] to also support automatic, recursive submodule checkouts, as I outlined here [3]. After this series, I can get through:

  # create the subproject
  mkdir subproject &&
  (
    cd subproject &&
    git init &&
    echo 'Hello, world' > README &&
    git add README &&
    git commit -m 'Subproject v1'
  ) &&
  # create the superproject
  mkdir superproject
  (
    cd superproject &&
    git init &&
    git submodule add ../subproject submod &&
    git config -f .gitmodules submodule.submod.update merge &&
    git commit -am 'Superproject v1' &&
    ( # 'submodule update' doesn't look in .gitmodules (yet [4]) for a
      # default update mode.  Copy submodule.submod.update over to
      # .git/config
      git submodule init
    )
  ) &&
  # start a feature branch on the superproject
  (
    cd superproject &&
    #git checkout -b my-feature --recurse-submodules &&
    ( # 'git submodule checkout --recurse-submodules' doesn't exist yet, so...
      git checkout -b my-feature &&
      git submodule checkout -b --gitmodules
    ) &&
    (
      cd submod &&
      echo 'Add the subproject side of this feature' > my-feature &&
      git add my-feature &&
      git commit -m 'Add my feature to the subproject'
    ) &&
    echo 'Add the superproject side of this feature' > my-feature &&
    git add my-feature &&
    git commit -am 'Add the feature to the superproject'
  ) &&
  # meanwhile, the subproject has been advancing
  (
    cd subproject &&
    echo 'Goodbye, world' >> README &&
    git commit -am 'Subproject v2'
  ) &&
  # we need to get that critical advance into the superproject quick!
  (
    cd superproject &&
    # update the master branch
    #git checkout --recurse-submodules master
    ( # 'git checkout --recurse-submodules' doesn't exist yet [5,6].
      # Even with that patch, 'git checkout' won't respect
      # submodule.<name>.local-branch without further work.
      git checkout master &&
      git submodule checkout
    ) &&
    git submodule update --remote &&
    git commit -am 'Catch submod up with Subproject v2' &&
    # update the my-feature branch
    #git checkout --recurse-submodules my-feature &&
    ( # 'git checkout --recurse-submodules' doesn't exist yet [5,6].
      git checkout my-feature &&
      git submodule checkout
    ) &&
    git submodule update --remote &&
    git commit -am 'Catch submod up with Subproject v2' &&
    # what does the history look like?
    (
      cd submod &&
      git --no-pager log --graph --date-order --oneline --decorate --all
      # *   16d9e3e (HEAD, my-feature) Merge commit 'f5e134d5747ee4a206e96d8c017f92f5b29a07f3' into my-feature
      # |\  
      # | * f5e134d (origin/master, origin/HEAD, master) Subproject v2
      # * | 0a1cd07 Add my feature to the subproject
      # |/  
      # * c2d32ba Subproject v1
    ) &&
    printf 'master: ' &&
    git ls-tree master submod &&
    # master: 160000 commit f5e134d5747ee4a206e96d8c017f92f5b29a07f3  submod
    printf 'my-feature: ' &&
    git ls-tree my-feature submod
    # my-feature: 160000 commit 16d9e3ea2fb57e7a166587203abdb328f90895d1  submod
  )
  git --version
  # git version 1.8.5.2.237.g01c62c6

I think the first three patches are fairly solid. The last one gets through the above script, but I'd need a more thorough test suite before I trusted it. I tried to be detailed in the commit messages, but of course, we'd want some user-facing documentation if we actually merged something like this series. I'm sending it to the list mostly to explain my current views and re-focus debate [1].

[1]: http://article.gmane.org/gmane.comp.version-control.git/240240 [2]: http://article.gmane.org/gmane.comp.version-control.git/239967 [3]: http://article.gmane.org/gmane.comp.version-control.git/240192 [4]: http://article.gmane.org/gmane.comp.version-control.git/239246 [5]: http://thread.gmane.org/gmane.comp.version-control.git/239695 [6]: http://article.gmane.org/gmane.comp.version-control.git/240117

Cheers, Trevor

W. Trevor King (4):
  submodule: Add helpers for configurable local branches
  submodule: Teach 'update' to preserve local branches
  submodule: Teach 'add' about a configurable local-branch
  submodule: Add a new 'checkout' command
 git-submodule.sh | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 138 insertions(+), 14 deletions(-)
-- 
1.8.5.2.237.g01c62c6
Previous: W. Trevor KingNext: W. Trevor King
Message 15 of 40 in “git-submodule.sh: Support 'checkout' as a valid update command”
  1. 1/2 git-submodule.sh: Support 'checkout' as a valid update commandFrancesco Pretto, Jan 5, 2014
  2. 2/2 Introduce git submodule attached updateFrancesco Pretto, Jan 5, 2014
  3. Francesco PrettoJan 5, 2014
  4. Heiko VoigtJan 5, 2014
  5. Francesco PrettoJan 5, 2014
  6. Heiko VoigtJan 6, 2014
  7. Francesco PrettoJan 6, 2014
  8. David EngsterJan 6, 2014
  9. W. Trevor KingJan 7, 2014
  10. W. Trevor KingJan 7, 2014
  11. Preferred local submodule branches (was: Introduce git submodule attached update)W. Trevor King, Jan 7, 2014
  12. W. Trevor KingJan 7, 2014
  13. W. Trevor KingJan 8, 2014
  14. W. Trevor KingJan 8, 2014
  15. 0/4 Preferred local submodule branchesW. Trevor King, Jan 9, 2014
  16. 1/4 submodule: Add helpers for configurable local branchesW. Trevor King, Jan 9, 2014
  17. 2/4 submodule: Teach 'update' to preserve local branchesW. Trevor King, Jan 9, 2014
  18. 3/4 submodule: Teach 'add' about a configurable local-branchW. Trevor King, Jan 9, 2014
  19. Francesco PrettoJan 15, 2014
  20. W. Trevor KingJan 15, 2014
  21. 4/4 submodule: Add a new 'checkout' commandW. Trevor King, Jan 9, 2014
  22. Tight submodule bindings (was: Preferred local submodule branches)W. Trevor King, Jan 12, 2014
  23. Jens LehmannJan 13, 2014
  24. W. Trevor KingJan 13, 2014
  25. Junio C HamanoJan 13, 2014
  26. W. Trevor KingJan 14, 2014
  27. Heiko VoigtJan 7, 2014
  28. W. Trevor KingJan 7, 2014
  29. Junio C HamanoJan 7, 2014
  30. Francesco PrettoJan 7, 2014
  31. Junio C HamanoJan 7, 2014
  32. Francesco PrettoJan 7, 2014
  33. Francesco PrettoJan 5, 2014
  34. Heiko VoigtJan 6, 2014
  35. W. Trevor KingJan 6, 2014
  36. Heiko VoigtJan 5, 2014
  37. W. Trevor KingJan 5, 2014
  38. Junio C HamanoJan 6, 2014
  39. Junio C HamanoJan 6, 2014
  40. Francesco PrettoJan 6, 2014

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.