Repository navigation
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
|
You may want to also think about how affects your use-case (please review it) Also think about testing how symlinks in db_snapshots might possibly work (I don't think they would, but take a look) |
Why do you suspect they would not work. Seems like an interesting solution to me. An entirely different solution is to have the worktrees point to the DB service of the parent. I know that can be chaotic for some use cases but for others its perfectly reasonable. It also saves you the restore time at the start of each new worktree. |
The .ddev/db_snapshots is bind-mounted; I don't expect the bind mount to follow a host symlink. |
|
Thanks for the good thinking here @tyler36 . Please take a look at #8705 (would appreciate your review). It may scratch this itch, as you can now I do think the strategy there (and additional mount) would make this work, and maybe the logic could be shared. |
…napshot restore` ## The Issue Related to ddev#8623 ("Allow worktrees to share DB snapshots" by @tyler36): a snapshot taken in one git worktree of a project isn't visible to `ddev snapshot restore` in another worktree of the same repository, so reusing a database across worktrees means manually copying snapshot files around. ddev#8623 predates the path-based snapshot restore/seed support that's landed on `main` since it was opened (ddev#8704, ddev#8705), and its `RestoreSnapshot(name, sourceRoot)` signature no longer matches `RestoreSnapshot(name, force)` on `main` - it needs a rewrite on top of current code either way. This is that rewrite, built directly on the newer mechanism instead of duplicating it. ## How This PR Solves The Issue `ddev snapshot restore` and `ddev snapshot restore --latest` already support restoring from an arbitrary host path via `resolveSnapshotSource`. This adds automatic discovery on top of that, rather than a parallel restore mechanism: - `DdevApp.ListSnapshotRestoreTargets()` lists the current project's own snapshots plus any snapshots found in the same project checked out in other worktrees of the same git repository (via `git worktree list`), newest first. A worktree match requires the same repository and the same relative project path - determined entirely from git and the filesystem, never from the `.ddev/config.yaml` project name (worktree projects don't usually share a name). A separate clone that happens to sit at the same relative path is not offered. - `DdevApp.GetLatestSnapshotRestoreTarget()` extends `--latest` the same way. - The interactive picker in `ddev snapshot restore` shows a worktree snapshot's name and source directory (`snapshot-name (worktree-dir)`); selecting one restores by its absolute path, reusing the existing path-based restore/bind-mount plumbing rather than a copy step. I considered going further with a repository-agnostic shared snapshot pool keyed by project name (so any two checkouts with the same name could share snapshots, not just worktrees of one repo). I left that out: project names collide too easily across unrelated projects, and a git worktree relationship is a precise, verifiable identity check that a name is not. The fully general case - "restore a snapshot from anywhere on disk" - is already covered by the existing path argument. ## Manual Testing Instructions 1. Create a git repo and a worktree of it, each with a DDEV project at the same relative path (project names deliberately differ, since that's the normal case for worktrees): ```bash git init repo && cd repo && git commit --allow-empty -m init ddev config --project-type=php --project-name=repo-a ddev start ddev snapshot --name=shared-snapshot cd .. && git -C repo worktree add ../repo-b HEAD cd repo-b ddev config --project-type=php --project-name=repo-b ddev start ``` 2. `ddev snapshot restore` in `repo-b` - the picker should list `shared-snapshot (repo)` alongside any of `repo-b`'s own snapshots. `ddev snapshot restore --latest` should restore it directly. 3. A separate `git clone` of `repo` at the same relative depth should *not* have its snapshots offered from `repo-b`. ## Automated Testing Overview Covered in the following commit, along with a fix for a real bug found while writing it. ## Release/Deployment Notes No config or behavior changes for projects outside a git worktree. Within a worktree, `ddev snapshot restore` and `--latest` now also see snapshots from sibling worktrees of the same project; this is additive and doesn't change what a bare snapshot name resolves to. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…napshot restore` ## The Issue Related to ddev#8623 ("Allow worktrees to share DB snapshots" by @tyler36): a snapshot taken in one git worktree of a project isn't visible to `ddev snapshot restore` in another worktree of the same repository, so reusing a database across worktrees means manually copying snapshot files around. ddev#8623 predates the path-based snapshot restore/seed support that's landed on `main` since it was opened (ddev#8704, ddev#8705), and its `RestoreSnapshot(name, sourceRoot)` signature no longer matches `RestoreSnapshot(name, force)` on `main` - it needs a rewrite on top of current code either way. This is that rewrite, built directly on the newer mechanism instead of duplicating it. ## How This PR Solves The Issue `ddev snapshot restore` and `ddev snapshot restore --latest` already support restoring from an arbitrary host path via `resolveSnapshotSource`. This adds automatic discovery on top of that, rather than a parallel restore mechanism: - `DdevApp.ListSnapshotRestoreTargets()` lists the current project's own snapshots plus any snapshots found in the same project checked out in other worktrees of the same git repository (via `git worktree list`), newest first. A worktree match requires the same repository and the same relative project path - determined entirely from git and the filesystem, never from the `.ddev/config.yaml` project name (worktree projects don't usually share a name). A separate clone that happens to sit at the same relative path is not offered. - `DdevApp.GetLatestSnapshotRestoreTarget()` extends `--latest` the same way. - The interactive picker in `ddev snapshot restore` shows a worktree snapshot's name and source directory (`snapshot-name (worktree-dir)`); selecting one restores by its absolute path, reusing the existing path-based restore/bind-mount plumbing rather than a copy step. I considered going further with a repository-agnostic shared snapshot pool keyed by project name (so any two checkouts with the same name could share snapshots, not just worktrees of one repo). I left that out: project names collide too easily across unrelated projects, and a git worktree relationship is a precise, verifiable identity check that a name is not. The fully general case - "restore a snapshot from anywhere on disk" - is already covered by the existing path argument. ## Manual Testing Instructions 1. Create a git repo and a worktree of it, each with a DDEV project at the same relative path (project names deliberately differ, since that's the normal case for worktrees): ```bash git init repo && cd repo && git commit --allow-empty -m init ddev config --project-type=php --project-name=repo-a ddev start ddev snapshot --name=shared-snapshot cd .. && git -C repo worktree add ../repo-b HEAD cd repo-b ddev config --project-type=php --project-name=repo-b ddev start ``` 2. `ddev snapshot restore` in `repo-b` - the picker should list `shared-snapshot (repo)` alongside any of `repo-b`'s own snapshots. `ddev snapshot restore --latest` should restore it directly. 3. A separate `git clone` of `repo` at the same relative depth should *not* have its snapshots offered from `repo-b`. ## Automated Testing Overview Covered in the following commit, along with a fix for a real bug found while writing it. ## Release/Deployment Notes No config or behavior changes for projects outside a git worktree. Within a worktree, `ddev snapshot restore` and `--latest` now also see snapshots from sibling worktrees of the same project; this is additive and doesn't change what a bare snapshot name resolves to. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Closing in favor of which uses newer available snapshot techniques. |
…napshot restore` ## The Issue Related to ddev#8623 ("Allow worktrees to share DB snapshots" by @tyler36): a snapshot taken in one git worktree of a project isn't visible to `ddev snapshot restore` in another worktree of the same repository, so reusing a database across worktrees means manually copying snapshot files around. ddev#8623 predates the path-based snapshot restore/seed support that's landed on `main` since it was opened (ddev#8704, ddev#8705), and its `RestoreSnapshot(name, sourceRoot)` signature no longer matches `RestoreSnapshot(name, force)` on `main` - it needs a rewrite on top of current code either way. This is that rewrite, built directly on the newer mechanism instead of duplicating it. ## How This PR Solves The Issue `ddev snapshot restore` and `ddev snapshot restore --latest` already support restoring from an arbitrary host path via `resolveSnapshotSource`. This adds automatic discovery on top of that, rather than a parallel restore mechanism: - `DdevApp.ListSnapshotRestoreTargets()` lists the current project's own snapshots plus any snapshots found in the same project checked out in other worktrees of the same git repository (via `git worktree list`), newest first. A worktree match requires the same repository and the same relative project path - determined entirely from git and the filesystem, never from the `.ddev/config.yaml` project name (worktree projects don't usually share a name). A separate clone that happens to sit at the same relative path is not offered. - `DdevApp.GetLatestSnapshotRestoreTarget()` extends `--latest` the same way. - The interactive picker in `ddev snapshot restore` shows a worktree snapshot's name and source directory (`snapshot-name (worktree-dir)`); selecting one restores by its absolute path, reusing the existing path-based restore/bind-mount plumbing rather than a copy step. I considered going further with a repository-agnostic shared snapshot pool keyed by project name (so any two checkouts with the same name could share snapshots, not just worktrees of one repo). I left that out: project names collide too easily across unrelated projects, and a git worktree relationship is a precise, verifiable identity check that a name is not. The fully general case - "restore a snapshot from anywhere on disk" - is already covered by the existing path argument. ## Manual Testing Instructions 1. Create a git repo and a worktree of it, each with a DDEV project at the same relative path (project names deliberately differ, since that's the normal case for worktrees): ```bash git init repo && cd repo && git commit --allow-empty -m init ddev config --project-type=php --project-name=repo-a ddev start ddev snapshot --name=shared-snapshot cd .. && git -C repo worktree add ../repo-b HEAD cd repo-b ddev config --project-type=php --project-name=repo-b ddev start ``` 2. `ddev snapshot restore` in `repo-b` - the picker should list `shared-snapshot (repo)` alongside any of `repo-b`'s own snapshots. `ddev snapshot restore --latest` should restore it directly. 3. A separate `git clone` of `repo` at the same relative depth should *not* have its snapshots offered from `repo-b`. ## Automated Testing Overview Covered in the following commit, along with a fix for a real bug found while writing it. ## Release/Deployment Notes No config or behavior changes for projects outside a git worktree. Within a worktree, `ddev snapshot restore` and `--latest` now also see snapshots from sibling worktrees of the same project; this is additive and doesn't change what a bare snapshot name resolves to. Co-Authored-By: Claude Sonnet 5 <[email protected]>
The Issue
Recently watched git-worktree-contributor-training which uses
ddev export-dbandddev import-dbvia a top-level .tarballs directory:While this works,
ddev snapshot restorecan be faster and has a nice TUI to browse snapshots. It would be nice if we could reuse this when using worktree workflow.How This PR Solves The Issue
This update enables database snapshots to be shared across git worktrees, allowing users to restore snapshots from corresponding project paths in other worktrees.
It attempts to detect if the project is a worktree and displays snapshots from other worktrees via TUI. Selecting a snapshot from a different worktree, copies the file locally before importing to maintain correct mounting paths.
Projects that are NOT a worktree are unchanged.
Manual Testing Instructions
"snapshot restore" lists worktree snapshots
ddev start ddev drush si -y ddev launch # Confirm Drupal welcome page is displayed.$ ddev snapshot ... Restore this snapshot with 'ddev snapshot restore d11simple_20260727184413'git worktree add ../feat-95 cd ../feat-95ddev launch # Confirm page loads Drupal setup wizard$ ddev snapshot restore Use the arrow keys to navigate: ↓ ↑ → ← Snapshot: ▸ d11simple_20260727184413 ... Database snapshot d11simple_20260727184413 was restored in 15sddev launch # Confirm DDEV welcome screen is displayedgit worktree add ../feat/new-67"snapshot restore" does NOT see non-worktree snapshots at same level
Assuming the following file structure:
$ ddev snapshot restore No snapshots found for project fake$ ddev snapshot ... Restore this snapshot with 'ddev snapshot restore fake_20260727190329'cd ../d11simple ddev snapshot restore Snapshot: ▸ d11simple_20260727184413Automated Testing Overview
Introduced tests to verify that the snapshot restoration process includes targets from other worktrees.
Release/Deployment Notes
No additional deployment steps are required, but ensure that users are aware of the new functionality regarding worktree snapshot sharing.