diff --git a/cli/src/commands/git/colocation.rs b/cli/src/commands/git/colocation.rs index f2213125fb..0da789bbb8 100644 --- a/cli/src/commands/git/colocation.rs +++ b/cli/src/commands/git/colocation.rs @@ -52,9 +52,9 @@ pub struct GitColocationDisableArgs {} /// Manage Jujutsu repository colocation with Git #[derive(clap::Subcommand, Clone, Debug)] pub enum GitColocationCommand { - Status(GitColocationStatusArgs), - Enable(GitColocationEnableArgs), Disable(GitColocationDisableArgs), + Enable(GitColocationEnableArgs), + Status(GitColocationStatusArgs), } pub fn cmd_git_colocation( @@ -63,9 +63,9 @@ pub fn cmd_git_colocation( subcommand: &GitColocationCommand, ) -> Result<(), CommandError> { match subcommand { - GitColocationCommand::Status(args) => cmd_git_colocation_status(ui, command, args), - GitColocationCommand::Enable(args) => cmd_git_colocation_enable(ui, command, args), GitColocationCommand::Disable(args) => cmd_git_colocation_disable(ui, command, args), + GitColocationCommand::Enable(args) => cmd_git_colocation_enable(ui, command, args), + GitColocationCommand::Status(args) => cmd_git_colocation_status(ui, command, args), } } @@ -79,9 +79,10 @@ fn repo_supports_git_colocation_commands( git::get_git_backend(workspace_command.repo().store())?; // Ensure that this is the main workspace - if workspace_command.repo_path().is_file() { + let repo_dir = workspace_command.workspace_root().join(".jj").join("repo"); + if repo_dir.is_file() { return Err(user_error( - "This command cannot be used in a non-main Jujutsu workspace.", + "This command cannot be used in a non-main Jujutsu workspace", )); } Ok(()) diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index eff59c82b1..a2ce70074b 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -52,9 +52,9 @@ This document contains the help content for the `jj` command-line program. * [`jj git`↴](#jj-git) * [`jj git clone`↴](#jj-git-clone) * [`jj git colocation`↴](#jj-git-colocation) -* [`jj git colocation status`↴](#jj-git-colocation-status) -* [`jj git colocation enable`↴](#jj-git-colocation-enable) * [`jj git colocation disable`↴](#jj-git-colocation-disable) +* [`jj git colocation enable`↴](#jj-git-colocation-enable) +* [`jj git colocation status`↴](#jj-git-colocation-status) * [`jj git export`↴](#jj-git-export) * [`jj git fetch`↴](#jj-git-fetch) * [`jj git import`↴](#jj-git-import) @@ -1351,17 +1351,19 @@ Manage Jujutsu repository colocation with Git ###### **Subcommands:** -* `status` — Show the current colocation status -* `enable` — Convert into a colocated Jujutsu/Git repository * `disable` — Convert into a non-colocated Jujutsu/Git repository +* `enable` — Convert into a colocated Jujutsu/Git repository +* `status` — Show the current colocation status -## `jj git colocation status` +## `jj git colocation disable` -Show the current colocation status +Convert into a non-colocated Jujutsu/Git repository -**Usage:** `jj git colocation status` +This moves the Git repository that is at the root of the Jujutsu workspace into the .jj directory. Once this is done you will no longer be able to use Git commands directly in the Jujutsu workspace. + +**Usage:** `jj git colocation disable` @@ -1375,13 +1377,11 @@ This moves the underlying Git repository that is found inside the .jj directory -## `jj git colocation disable` - -Convert into a non-colocated Jujutsu/Git repository +## `jj git colocation status` -This moves the Git repository that is at the root of the Jujutsu workspace into the .jj directory. Once this is done you will no longer be able to use Git commands directly in the Jujutsu workspace. +Show the current colocation status -**Usage:** `jj git colocation disable` +**Usage:** `jj git colocation status` diff --git a/cli/tests/test_git_colocation.rs b/cli/tests/test_git_colocation.rs index 8a53888744..b2d7a7bb38 100644 --- a/cli/tests/test_git_colocation.rs +++ b/cli/tests/test_git_colocation.rs @@ -253,3 +253,40 @@ fn test_git_colocation_status_colocated() { Hint: To disable colocation, run: `jj git colocation disable` [EOF]"); } + +#[test] +fn test_git_colocation_in_secondary_workspace() { + let test_env = TestEnvironment::default(); + test_env + .run_jj_in(".", ["git", "init", "--no-colocate", "main"]) + .success(); + let main_dir = test_env.work_dir("main"); + main_dir + .run_jj(["workspace", "add", "../secondary"]) + .success(); + let secondary_dir = test_env.work_dir("secondary"); + + let output = secondary_dir.run_jj(["git", "colocation", "status"]); + insta::assert_snapshot!(output, @r" + ------- stderr ------- + Error: This command cannot be used in a non-main Jujutsu workspace + [EOF] + [exit status: 1] + "); + + let output = secondary_dir.run_jj(["git", "colocation", "enable"]); + insta::assert_snapshot!(output, @r" + ------- stderr ------- + Error: This command cannot be used in a non-main Jujutsu workspace + [EOF] + [exit status: 1] + "); + + let output = secondary_dir.run_jj(["git", "colocation", "disable"]); + insta::assert_snapshot!(output, @r" + ------- stderr ------- + Error: This command cannot be used in a non-main Jujutsu workspace + [EOF] + [exit status: 1] + "); +}