-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve git worktree handling when creating SDK containers #1351
Open
krnowak
wants to merge
5
commits into
main
Choose a base branch
from
krnowak/sdk-scripts-worktree
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+334
−6
Conversation
This file contains 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
The library has the following functionality: - Discover the git repository layout. This figures out where is the main repository (whose `.git` entry is a directory and contains all the git configuration and objects) and all its linked worktrees (their `.git` entries are just files with a path to their respective worktree metadata directory inside the main repo's `.git`). The layout is basically two things: a path to the main repo and a map of linked worktree name to the path of the linked worktree. Name of a worktree is the `<name>` part in the path `<main-repo>/.git/worktrees/<name>`. - Map the discovered git repository layout into possible git repository layout inside the SDK container. The worktrees (both main one and linked ones) are put into a chosen base directory inside SDK so the main worktree is in `<base>/main-repo`, while linked worktrees are in `<base>/linked/<name>`. It's also possible to override the path for any worktree to be put elsewhere (for example, we may want to put the worktree being in current working directory to `/mnt/host/source/src/scripts`, while the rest of the worktrees go somewhere under `/mnt/host/all-worktrees/scripts` directory). - Generate Docker volume options based on both git repository layouts. It results in an array of strings in form of `"-v" "<path-to-worktree:path-to-worktree-inside-SDK"` that can be passed directly to docker/podman. - Generate replacements based on git repository layout inside the SDK container. Replacements is a bash file to be sourced. It defines a map of file paths to the new contents that those files should have. Currently the generated replacements are for `.git` files in the linked worktrees and `gitdir` files inside main worktree's `.git/worktrees/<name>` directories. Such replacement file should be mounted inside the SDK container with -v option (just like the worktrees). - Map the replacements to a set of bind-mounts. This action should be done inside the SDK container - it sources the replacements files, creates temporary files with the contents being the values in the map from the replacements file and bind-mounts them into the locations being keys of the map.
This is something I have done, because I needed it in early drafts of the work. The work has evolved and the need disappeared, but maybe it makes sense to keep it.
This makes sure that the worktrees mounted into the SDK container properly reference other worktrees, so they won't be treated by git as stale and get cleaned up.
Nothing changes if the scripts repo is standalone and has no linked worktrees.
They get the same treatment like the scripts repo.
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.
This mounts all related worktrees of the scripts repo and of any extra git repo passed through the -g option into the SDK container, so:
For more details, please see the commit messages, especially the one that adds the git worktree handling library.
Tested locally.