How to join worktree locally into monorepo
I've got a monorepo (tvl.fyi), cloned sparsely.
The monorepo contains an imported project at web/planet-mars.
I filtered this project with josh:
josh-filter :web/planet-mars
and put it in a separate worktree:
git worktree add ../planet-mars FILTERED_HEAD
Made a commit and want to get the commit back into the monorepo in the main worktree:
josh-filter :join(f299c40b882a03b07f0411154b15d4b767aa7dde:prefix=web/planet-mars) canon
I canceled the last command after 10 minutes. The sha-1 is the commit I created and canon is the HEAD of the monorepo.
Thanks for any pointers.
My idea is, that the above workflow would allow me to push via ssh and avoid http credentials which would be needed for the josh proxy. See also #22.
The planet mars project was previously imported with josh: https://code.tvl.fyi/commit/web/planet-mars?id=0a83e6567b4c8ef342890bbc549332767a5d6bf1
I could actually work around the problem with
git cherry-pick -X subtree=web/planet-mars $COMMIT
in the main worktree. However this of course only works as long as I don't use josh workspaces. But it hopefully illustrates what I want to achieve. After the cherry-pick I can push to the mono repo with SSH and I now exactly what commit(s) end up in the monorepo.
:join is not really meant for this. For the workflow you are after the --reverse flag should be used. The easiest would be to crate a branch: josh-filter :web/planet-mars refs/heads/canon --update refs/heads/filtered_canon.
Create the worktree and commit on filtered_canon then bring the commit to the full tree: josh-filter :web/planet-mars refs/heads/canon --update refs/heads/filtered_canon --reverse`
Thanks a lot, it worked! With two remarks for future readers:
-
The index does not get updated by josh, thus git status shows the tree as staged in the previous state.
-
The josh-filter commands given in the previous comment apparently are missing a slash after the colon:
josh-filter :/web/planet-mars refs/heads/canon --update refs/heads/filtered_canon --reverse
I'd like to script my workflow and would appreciate if this issue would remain open until I double checked the full roundtrip also with my script.