worktree: add --recurse-submodules support to git worktree add#2112
worktree: add --recurse-submodules support to git worktree add#2112Ergus wants to merge 4 commits into
Conversation
Welcome to GitGitGadgetHi @Ergus, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that either:
You can CC potential reviewers by adding a footer to the PR description with the following syntax: NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description, Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txtTo iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description): To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
submodule_name_to_gitdir() currently returns a path under the superproject's worktrees/ tree in a linked worktree: $GIT_COMMON_DIR/worktrees/<wt-id>/modules/<name>/ That path is invisible to the shared submodule repository at $GIT_COMMON_DIR/modules/<name>/, so "git gc" on the shared repo cannot find it via get_worktrees() and may prune commits that are only reachable from a per-worktree HEAD. Return the per-worktree gitdir as a genuine linked worktree of the shared submodule repository instead: $GIT_COMMON_DIR/modules/<name>/worktrees/<wt-id>/ Because it lives inside the shared repo's worktrees/ tree, "git gc" sees it via get_worktrees() and protects per-worktree objects. Update validate_submodule_legacy_git_dir() to strip the trailing /worktrees/<wt-id> before the sibling-clash name check, since the new path no longer ends with the submodule name. Signed-off-by: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
When "git submodule update --init" runs in a linked worktree, set up the submodule's gitdir following the layout from the previous commit: $GIT_COMMON_DIR/modules/<name>/worktrees/<wt-id>/ Any cloning targets the shared submodule repo at $GIT_COMMON_DIR/modules/<name>/. Once that exists, a thin per-worktree gitdir is created under the shared repo's own worktrees/ tree with a "commondir" file pointing back at the shared repo. The per-worktree gitdir holds only HEAD and (after first use) the index; all objects, refs and config come from the shared repo. If the shared repo is missing and the main worktree has an in-tree .git/ directory for the submodule, run absorbgitdirs first to relocate it; if that yields nothing, clone from the upstream URL. Skip overwriting core.worktree in the shared repo's config in ensure_core_worktree() when the submodule gitdir has different_commondir set; writing a per-worktree relative path into the shared config would corrupt the main worktree's view. Signed-off-by: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
"git worktree add" leaves submodules uninitialised in the new working tree; the user must run "git submodule update --init" afterwards. Add --recurse-submodules to do this automatically. After the checkout succeeds, a child "git submodule update --init --recursive" is run with its working directory set to the new worktree path. Each submodule's gitdir is set up as a linked worktree of the shared submodule repository, so objects and refs are shared without requiring hardlinks. The flag is incompatible with --no-checkout (nothing checked out) and --orphan (no commits to carry submodule config). Teach "worktree remove" to delete per-worktree submodule gitdirs from $GIT_COMMON_DIR/modules/<name>/worktrees/<wt-id>/ when the worktree is removed; they are no longer nested inside the worktree's own gitdir and must be cleaned up explicitly. Worktrees where all submodules use this model are allowed past the submodule guard in check_clean_worktree(); the existing "git status" check still blocks removal of trees with uncommitted submodule changes. Signed-off-by: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
Add tests verifying: * "worktree add --recurse-submodules" initialises submodules and places their per-worktree gitdir at $GIT_COMMON_DIR/modules/<name>/worktrees/<wt-id>/ with a commondir file pointing at the shared repo and no objects/ of its own. * "worktree remove" deletes the per-worktree submodule gitdir and leaves the shared submodule repo intact. * Removal is blocked when any submodule uses the legacy shared gitdir layout or when submodule changes are uncommitted. * scan_modules_for_wt_id() handles nested submodule repos and slash-named submodule paths correctly. * The auto-absorb path works when the main worktree has an in-tree submodule .git/ directory. Signed-off-by: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
233efe0 to
cea155c
Compare
"git worktree add" leaves submodules uninitialised in the new working
tree. This series adds --recurse-submodules to initialise them
automatically, using the same per-worktree-gitdir model that linked
worktrees already use for the superproject.
The key design choice is where the per-worktree submodule gitdir lives.
An earlier iteration (v1) nested it under the superproject's own
worktrees/ tree:
Junio pointed out that this placement is invisible to the shared
submodule repository, so "git gc" on the shared repo can prune commits
reachable only from a per-worktree HEAD. This series follows the
approach he suggested instead: treat the absorbed submodule repo as a
bare-like repo and create proper linked worktrees off it:
Because this path lives inside the shared repo's own worktrees/ tree,
"git gc" finds it via get_worktrees() and protects per-worktree objects.
The series is structured as follows: