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

POC for GitBackend opening worktrees #4801

Closed
wants to merge 10 commits into from

Conversation

cormacrelf
Copy link

Just to illustrate what #4644 could do differently. See discussion there.

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

A colocated workspace is one that also happens to have a valid .git file
or directory. To create a colocated workspace in an existing JJ repo, 
we need to add a corresponding git _worktree_.

JJ doesn't have the ability to create colocated workspaces yet. We want
to test a bunch of code around colocating worktrees with a workspace,
assuming we will build the functionality to actually create one in JJ
itself later. So here's a helper function to do it the really hacky
way with the `git` CLI, moving a .git file into place, and running
`git worktree repair`.
Previously, only the default workspace could be colocated. This adds
logic to the colocation-detection code to support finding a worktree
with a "gitfile" as well as a full-on .git directory.

There are some new tests for what happens when you `jj git init
--git-repo=...` either in or pointing at an existing worktree. I do not
expect these to be common workflows, but there is new behaviour here
that we need to track.
…_head

This makes colocated workspaces independent. You can move @ in a
workspace and JJ will write HEAD = @- to the git worktree in that
workspace. And you can run mutating git commands in a workspace, and
JJ will import the new HEAD only in that workspace.

Previously, any imports and exports were against the git backing repo,
which is sometimes colocated with the default workspace. So colocated
workspaces were not independent, they all read and wrote from the same
HEAD in the backing repo.
…t worktree

Now that colocated workspaces exist, it is necessary to distinguish the
two kinds of git repository `jj` might open. There's the git backend
(which is either a bare repository or a colocated one) and the worktrees
for all the colocated workspaces. Both of these are a
`gix/git2::Repository`, the difference is just which path you opened. So
you have to distinguish them with names.

This rename mostly serves as an opportunity to review at least some of
the usages of explicit usage of the git backend repo.
@cormacrelf cormacrelf force-pushed the workspace-colocate-minimal branch from 1f362de to ba0823a Compare November 8, 2024 11:25
@cormacrelf cormacrelf mentioned this pull request Nov 8, 2024
4 tasks
@cormacrelf cormacrelf changed the title Git backend worktree POC for GitBackend opening worktrees Nov 8, 2024
We want to check for colocated workspaces in the GitBackend
initialization code. So it has to move to jj_lib.
This does the plumbing but does not actually use it.
- Add MaybeColocatedGitRepo helper, to open the workspace root if
  colocation is detected
- Save any warning generated on the GitBackend via
  `GitRepoColocationType::NotColocated { warning: Some(...) }`
- try reopening as colocated during GitBackend::init_external, in addition to during ::load
This allows us to have a differently configured GitBackend in the newly-
added workspace, i.e. one which was opened at the workspace root if we
are creating a colocated workspace.

This was easier than I anticipated -- we can use RepoLoader by
itself to load the store from disk, and then create the new working
copy commit immediately.
No longer necessary. GitBackend has already opened the correct repo.
So we may simply get the store's git backend and read the HEAD from it.

We do NOT remove the repository parameter from git::reset_head, because:

- it has had this param since before the worktree code came around
- it still uses `git2::Repository` and judging from a token attempt,
  converting this code is a lot of work.

But, at least in theory, git::reset_head can just use the `gix::Repository`
on the GitBackend.
@cormacrelf cormacrelf force-pushed the workspace-colocate-minimal branch 4 times, most recently from 3750492 to 3d83cdb Compare November 10, 2024 12:25
@cormacrelf
Copy link
Author

Closed because this is all in #4644 now.

@cormacrelf cormacrelf closed this Nov 10, 2024
@cormacrelf cormacrelf deleted the git-backend-worktree branch November 10, 2024 12:55
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