Skip to content
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

Workspace colocate 2 #4678

Draft
wants to merge 8 commits into
base: workspace-colocate-minimal
Choose a base branch
from

Conversation

cormacrelf
Copy link
Collaborator

This is a draft, still cleaning up, but you can see how we create the worktrees. Follow-on from #4644

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

This forms the basis of `jj workspace add --colocate`.

The libraries don't quite have the functionality we need
- gix doesn't do it at all
- git2 does (Repository::worktree(name, opts)), but it
  always has to check out a commit.

This implementation
- can create in an already-existing directory;
- writes a dummy HEAD and index; and
- does not check out any files.

JJ handles all three of those things (enabled in a later diff).
We need this for when we forget colocated workspaces, so that users
do not have to `git worktree remove` manually.

The validation / removal separation is so we can two-phase-commit the
removals during a multi-workspace forget operation, checking they're all
valid and able to be removed during the transaction and removing the
worktrees afterwards. Missing worktrees (like when the user has ALREADY
run `git worktree remove`) are ignored.
We need to include WorkspaceId in error messages more frequently now.
New flag: jj workspace add --colocate. This is hidden, because we will
be splitting the colocated workspaces code over a few PRs and it's
plausible a new JJ will be released before the feature is ready.

To implement, we add a worktree. And remove it during `workspace
forget`.
We're getting paths like this, I think.

    gitdir: \\?\C:\Users\runneradmin\AppData\Local\Temp\jj-test-fy26a2\second

But I don't know what git does, and I don't have access to a windows machine.
Adding this so the CI windows build can tell us what's wrong.
Before

    gitdir: \\?\C:\Users\runneradmin\AppData\Local\Temp\jj-test-fy26a2\second

After

    gitdir: C:/Users/runneradmin/AppData/Local/Temp/jj-test-fy26a2/second

And same for the other worktree bits and pieces. We also change the way
the tests run git commands, because of yet another error to do with
Git being unable to handle verbatim paths:

    command=`"git" "worktree" "add" "\\\\?\\C:\\Users\\runneradmin\\AppData\\Local\\Temp\\jj-test-ti0MHE\\second"`
    code=128
    stdout=""
    stderr=```
    Preparing worktree (new branch \'second\')
    fatal: could not create leading directories of \'//?/C:/Users/runneradmin/AppData/Local/Temp/jj-test-ti0MHE/second/.git\': Invalid argument
@cormacrelf cormacrelf mentioned this pull request Oct 20, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant