josh icon indicating copy to clipboard operation
josh copied to clipboard

How to join worktree locally into monorepo

Open thkoch2001 opened this issue 10 months ago • 3 comments

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

thkoch2001 avatar Apr 21 '25 18:04 thkoch2001

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.

thkoch2001 avatar Apr 22 '25 05:04 thkoch2001

: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`

christian-schilling avatar Apr 22 '25 11:04 christian-schilling

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.

thkoch2001 avatar Apr 23 '25 16:04 thkoch2001