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

jj git colocate #4833

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

jj git colocate #4833

wants to merge 2 commits into from

Conversation

cormacrelf
Copy link
Collaborator

Fixes #4624

Open to bikesheds on what to call the inverse command. jj git delocate?

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

@joyously
Copy link

Open to bikesheds on what to call the inverse command. jj git delocate?

Would it be isolate?

@cormacrelf cormacrelf force-pushed the git-colocate branch 2 times, most recently from 14df9e7 to c5ad1b8 Compare November 11, 2024 15:58
@neongreen
Copy link
Collaborator

jj git dismantle? jj git purify?

@cormacrelf
Copy link
Collaborator Author

cormacrelf commented Nov 11, 2024

If you're turning off git, you are really turning a page on what once was. One might type it with a renewed sense of purpose, confidence in your knowledge of the JJ way, and independence of the crutch you once needed. In that vein I suggest

  • jj git renounce, my favourite; or
  • jj git disavow

(Also like jj git dismantle.)

@martinvonz
Copy link
Owner

jj git internalize might be okay. I think of the operation as making the .git/ dir internal to .jj/. But it's not as cheeky as some of the other options :)

@emilazy
Copy link
Collaborator

emilazy commented Nov 11, 2024

jj git conceal keeps everything nicely under a co‐ namespace. (Not serious. Or am I?)

@joyously
Copy link

separate comes to mind.
Or jj git colocate --reverse
I think of most of the git subcommands as actual Git commands, but this is not, so it seems a bit different. (both colocate and its reverse)

lib/src/workspace.rs Outdated Show resolved Hide resolved
We need this to differentiate primary/secondary workspaces when choosing
how to colocate them (and for now, doing nothing for workspaces as
worktrees have not landed).
@cormacrelf cormacrelf force-pushed the git-colocate branch 2 times, most recently from c510233 to 335ac54 Compare November 12, 2024 09:43
@cormacrelf cormacrelf requested a review from yuja November 12, 2024 09:58
@essiene
Copy link
Collaborator

essiene commented Nov 12, 2024

separate comes to mind. Or jj git colocate --reverse I think of most of the git subcommands as actual Git commands, but this is not, so it seems a bit different. (both colocate and its reverse)

I really like colocate --reverse since unlike other suggestions, I don't have to think about what this does.

If there must be a command under jj git, a close second of colocate --reverse would be jj git decolocate, which is not a real word to be sure, but also communicates intent clearly.

fwiw ;-)

Comment on lines 83 to 114
let old_path = workspace_command.repo_path().join("store").join("git");
let new_path = workspace.workspace_root().join(".git");
fs::rename(&old_path, &new_path).context(old_path)?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, we have to check that old_path exists (and is a directory, and is not a symlink, and also that git_target points to it) before we commit to writing out core.bare=false.

As long as we check this, I don't think we need to handle the large variety of git_target scenarios outside of this, because there will soon be an alternative, which is to just add a worktree. Which will work in many more scenarios. git_target can point into outer space for all we care.

The idea is to have --prefer-worktree switch to using worktrees in the primary workspace, as well as secondary ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@cormacrelf cormacrelf force-pushed the git-colocate branch 3 times, most recently from 60c3272 to db0a1eb Compare November 12, 2024 14:26
Initially, we can only colocate the primary workspace.

See <https://martinvonz.github.io/jj/latest/git-compatibility/#converting-a-repo-into-a-co-located-repo> for the steps.

Adds a Workspace::reload() function to reload the workspace from the
file system, which is technically not necessary for this diff, but will
become necessary soon, when we make the GitBackend colocation-aware.
@PhilipMetzger
Copy link
Collaborator

Open to bikesheds on what to call the inverse command. jj git delocate?

I'd like to have the inverse in the native backend with something like adopt but that can wait. Otherwise internalize is a fine name.

}

let git_repo = git_backend.git_repo();
if workspace.is_primary_workspace() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we detect this somehow by caller or git layer?

I don't think "is primary workspace" can be a common concept across working-copy/workspace-loader backends.


if workspace_command.working_copy_shared_with_git() {
return Err(user_error(format!(
"Workspace '{}' is already colocated.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: error message doesn't usually contain period

let old_path_canon = old_path.canonicalize().ok();

let mut config =
gix::config::File::from_git_dir(common_dir.to_path_buf()).map_err(internal_error)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe this should be a user error (assuming it would do some I/O)?

BTW, the gix' fetch/clone implementation might help understand their config API. I'm not familiar with that.
https://github.com/GitoxideLabs/gitoxide/blob/main/gix/src/clone/fetch/util.rs

//
// This way we end up with a git HEAD written immediately, rather than
// next time @ moves. And you can immediately start running git commands.
let workspace = workspace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use command.workspace_helper_no_snapshot()?


git::reset_head(tx.repo_mut(), &git2_repo, &wc_commit)?;

tx.finish(ui, format!("Colocated existing workspace {name}"))?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Colocated -> colocate

Comment on lines +88 to +89
if old_path.is_symlink()
|| !old_path.is_dir()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use .symlink_metadata() instead of stat()ing twice?

@yuja
Copy link
Collaborator

yuja commented Nov 15, 2024

jj git colocate --reverse

I don't like the name --reverse, but it's nice that we don't have to add two separate commands which would be rarely used.

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.

FR: Add a jj git colocate command
8 participants