Repository navigation
feat: add submodules init to nest all submodules at once - #228
Merged
Merged
Conversation
`git nested submodules init` turns each submodule into a nested repo, at the commit it pins. Each one gets a commit. - `--recursive` nests their submodules too, at any depth. - `--only` and `--ignore` pick some of them. `init` keeps the choice in .gitmodules. - `--resolve-relative <url>` resolves relative submodule urls. Without it, `init` stops at one. - The choice goes into .gitnested as `submodules: nest` or `keep`. - A branch or push of a nested repo inside a nested repo leaves the outer one alone. Refs #184
4 tasks done
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #228 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 50 51 +1
Lines 2907 2985 +78
=========================================
+ Hits 2907 2985 +78
|
|
thorsten-klein
added a commit
that referenced
this pull request
Nov 14, 2026
## What this changes A new command keeps the nested repos of `submodules init` (#228) in step with upstream: ```bash git fetch upstream git nested submodules update --dry-run upstream/main # see what it would do git nested submodules update upstream/main # merge, then update the nested repos ``` `update` merges the commit and keeps each upstream commit, with its SHA and author. Then it changes the nested repos the way upstream changed its submodules. Each changed submodule gets one commit. It never fetches. | Upstream did | `update` does | |---|---| | moved a pin | pull the nested repo to it. Local changes stay | | added a submodule | nest it, as `submodules:` in `.gitnested` says | | removed a submodule | remove the nested repo. Warn if it had local changes | | moved a submodule | move the folder. Local changes stay | | changed a url | write the new `remote` | - It keeps what `init` chose. A new submodule that `--only` or `--ignore` leaves out stays a submodule. So does one with `update = none`, as in git. - Options: `--dry-run` (also shows deeper nested repos), `--single-commit`, `--continue`, `--abort`, `-S`, `--signoff`. - A nested repo with a `pin` stays where it is. - If the commit is merged already, `update` only updates the nested repos that lag behind. So after `--abort`, a second run does the rest. - A plain `git merge` of upstream is not the way. `update` says to abort it and use `update` instead. - Nested repos with patches work: the patches go on the new pin. It also fixes what a test on tdesktop found (see #184): - `update = none` submodules got nested. Now they stay submodules, also in `init` and `clone --recurse-submodules`. - `--abort` left a half sync and the stopped worktree. - git-nested's block in `.gitattributes` conflicted with new upstream rules. - `--dry-run` missed deeper submodules. - LF files that a parent rule would check out with CRLF now stay LF. - A conflict in a nested repo showed the steps of a plain `pull`. Now it shows only `update --continue` and `--abort`. ### Trade-offs - The upstream commits come in as they are. So they still have their gitlinks. A checkout of one shows empty submodule folders. Use `git bisect --first-parent`. Your own commits never have a gitlink. - By default the merge commit comes first. One commit per submodule follows. `--single-commit` makes one merge commit instead. ### Speed 20 submodules, all moved by upstream: about 11 s with local repos. No submodule moved: 0.25 s. Over a network, each moved submodule adds one fetch. ## Why A fork of a project with submodules wants plain files, the upstream history, and updates from upstream. A plain `git merge` of upstream breaks on the gitlinks. Fixes #184 ## Checklist - [x] `uv run poe all` passes (ruff, mypy, pyright, bandit, complexipy, and the tests at 100% coverage) - [x] New behaviour has a test - [x] README / `--help` / the man page updated, if the change is visible to users - [x] The PR title reads as a [Conventional Commit](https://www.conventionalcommits.org) (`feat:`, `fix:`, `docs:`, …) — it becomes the squash-merge commit message and the changelog line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What this changes
A new command turns all submodules of a repository into nested
repositories:
--onlyand--ignorepick some of them.initkeeps the choice in.gitmodules.--resolve-relative <url>resolves relative submodule urls. Without it,initstops at one. In a fork,originis the wrong base..gitnestedassubmodules: nestorkeep.one alone.
Why
Part one of #184. #202 builds on it:
submodules mergeandsubmodules pullkeep the nested repos in step with upstream.Stack: #228 (this) → #202.
Checklist
uv run poe allpasses (ruff, mypy, pyright, bandit, complexipy, and thetests at 100% coverage)
--help/ the man page updated, if the change is visible to users(
feat:,fix:,docs:, …) — it becomes the squash-merge commit messageand the changelog line