diff --git a/cli/src/commands/git/clone.rs b/cli/src/commands/git/clone.rs index 0d450e8af..469a5172d 100644 --- a/cli/src/commands/git/clone.rs +++ b/cli/src/commands/git/clone.rs @@ -22,7 +22,7 @@ use jj_lib::str_util::StringPattern; use jj_lib::workspace::Workspace; use crate::cli_util::{CommandHelper, WorkspaceCommandHelper}; -use crate::command_error::{user_error, user_error_with_message, CommandError}; +use crate::command_error::{cli_error, user_error, user_error_with_message, CommandError}; use crate::commands::git::{map_git_error, maybe_add_gitignore}; use crate::config::{write_config_value_to_file, ConfigNamePathBuf}; use crate::git_util::{get_git_repo, print_git_import_stats, with_remote_git_callbacks}; @@ -85,6 +85,9 @@ pub fn cmd_git_clone( command: &CommandHelper, args: &GitCloneArgs, ) -> Result<(), CommandError> { + if command.global_args().at_operation != "@" { + return Err(cli_error("--at-op is not respected")); + } let remote_name = "origin"; let source = absolute_git_source(command.cwd(), &args.source); let wc_path_str = args diff --git a/cli/src/commands/git/init.rs b/cli/src/commands/git/init.rs index 45c71ea06..f6d9a2e79 100644 --- a/cli/src/commands/git/init.rs +++ b/cli/src/commands/git/init.rs @@ -22,7 +22,9 @@ use jj_lib::workspace::Workspace; use jj_lib::{file_util, git}; use crate::cli_util::{print_trackable_remote_branches, start_repo_transaction, CommandHelper}; -use crate::command_error::{user_error_with_hint, user_error_with_message, CommandError}; +use crate::command_error::{ + cli_error, user_error_with_hint, user_error_with_message, CommandError, +}; use crate::commands::git::maybe_add_gitignore; use crate::config::{write_config_value_to_file, ConfigNamePathBuf}; use crate::git_util::{ @@ -71,6 +73,12 @@ pub fn cmd_git_init( command: &CommandHelper, args: &GitInitArgs, ) -> Result<(), CommandError> { + if command.global_args().ignore_working_copy { + return Err(cli_error("--ignore-working-copy is not respected")); + } + if command.global_args().at_operation != "@" { + return Err(cli_error("--at-op is not respected")); + } let cwd = command.cwd(); let wc_path = cwd.join(&args.destination); let wc_path = file_util::create_or_reuse_dir(&wc_path) diff --git a/cli/src/commands/init.rs b/cli/src/commands/init.rs index 1ec74ed47..71ff67357 100644 --- a/cli/src/commands/init.rs +++ b/cli/src/commands/init.rs @@ -21,7 +21,9 @@ use tracing::instrument; use super::git; use crate::cli_util::CommandHelper; -use crate::command_error::{user_error_with_hint, user_error_with_message, CommandError}; +use crate::command_error::{ + cli_error, user_error_with_hint, user_error_with_message, CommandError, +}; use crate::ui::Ui; /// Create a new repo in the given directory @@ -50,6 +52,12 @@ pub(crate) fn cmd_init( command: &CommandHelper, args: &InitArgs, ) -> Result<(), CommandError> { + if command.global_args().ignore_working_copy { + return Err(cli_error("--ignore-working-copy is not respected")); + } + if command.global_args().at_operation != "@" { + return Err(cli_error("--at-op is not respected")); + } let cwd = command.cwd(); let wc_path = cwd.join(&args.destination); let wc_path = file_util::create_or_reuse_dir(&wc_path) diff --git a/cli/tests/test_git_clone.rs b/cli/tests/test_git_clone.rs index 0d3d2dba4..fa54e223e 100644 --- a/cli/tests/test_git_clone.rs +++ b/cli/tests/test_git_clone.rs @@ -485,15 +485,12 @@ fn test_git_clone_at_operation() { let git_repo = git2::Repository::init(git_repo_path).unwrap(); set_up_non_empty_git_repo(&git_repo); - // TODO: just error out? no operation should exist - let (_stdout, stderr) = test_env.jj_cmd_ok( + let stderr = test_env.jj_cmd_cli_error( test_env.env_root(), &["git", "clone", "--at-op=@-", "source", "clone"], ); insta::assert_snapshot!(stderr, @r###" - Fetching into new repo in "$TEST_ENV/clone" - branch: main@origin [new] untracked - Setting the revset alias "trunk()" to "main@origin" + Error: --at-op is not respected "###); } diff --git a/cli/tests/test_git_init.rs b/cli/tests/test_git_init.rs index ea37f312b..25ec719a7 100644 --- a/cli/tests/test_git_init.rs +++ b/cli/tests/test_git_init.rs @@ -101,21 +101,11 @@ fn test_git_init_internal_ignore_working_copy() { std::fs::create_dir(&workspace_root).unwrap(); std::fs::write(workspace_root.join("file1"), "").unwrap(); - // No snapshot should be taken - let (_stdout, stderr) = - test_env.jj_cmd_ok(&workspace_root, &["git", "init", "--ignore-working-copy"]); + let stderr = + test_env.jj_cmd_cli_error(&workspace_root, &["git", "init", "--ignore-working-copy"]); insta::assert_snapshot!(stderr, @r###" - Initialized repo in "." + Error: --ignore-working-copy is not respected "###); - - let (stdout, stderr) = - test_env.jj_cmd_ok(&workspace_root, &["status", "--ignore-working-copy"]); - insta::assert_snapshot!(stdout, @r###" - The working copy is clean - Working copy : qpvuntsm 230dd059 (empty) (no description set) - Parent commit: zzzzzzzz 00000000 (empty) (no description set) - "###); - insta::assert_snapshot!(stderr, @""); } #[test] @@ -124,10 +114,9 @@ fn test_git_init_internal_at_operation() { let workspace_root = test_env.env_root().join("repo"); std::fs::create_dir(&workspace_root).unwrap(); - // TODO: just error out? no operation should exist - let (_stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "init", "--at-op=@-"]); + let stderr = test_env.jj_cmd_cli_error(&workspace_root, &["git", "init", "--at-op=@-"]); insta::assert_snapshot!(stderr, @r###" - Initialized repo in "." + Error: --at-op is not respected "###); } @@ -254,7 +243,7 @@ fn test_git_init_external_ignore_working_copy() { std::fs::write(workspace_root.join("file1"), "").unwrap(); // No snapshot should be taken - let (_stdout, stderr) = test_env.jj_cmd_ok( + let stderr = test_env.jj_cmd_cli_error( &workspace_root, &[ "git", @@ -265,25 +254,7 @@ fn test_git_init_external_ignore_working_copy() { ], ); insta::assert_snapshot!(stderr, @r###" - Done importing changes from the underlying Git repo. - Initialized repo in "." - "###); - - let (stdout, stderr) = - test_env.jj_cmd_ok(&workspace_root, &["status", "--ignore-working-copy"]); - insta::assert_snapshot!(stdout, @r###" - The working copy is clean - Working copy : sqpuoqvx f6950fc1 (empty) (no description set) - Parent commit: mwrttmos 8d698d4a my-branch | My commit message - "###); - insta::assert_snapshot!(stderr, @""); - - // TODO: Correct, but might be better to check out the root commit? - let stderr = test_env.jj_cmd_failure(&workspace_root, &["status"]); - insta::assert_snapshot!(stderr, @r###" - Error: The working copy is stale (not updated since operation b51416386f26). - Hint: Run `jj workspace update-stale` to update it. - See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-working-copy for more information. + Error: --ignore-working-copy is not respected "###); } @@ -295,8 +266,7 @@ fn test_git_init_external_at_operation() { let workspace_root = test_env.env_root().join("repo"); std::fs::create_dir(&workspace_root).unwrap(); - // TODO: just error out? no operation should exist - let (_stdout, stderr) = test_env.jj_cmd_ok( + let stderr = test_env.jj_cmd_cli_error( &workspace_root, &[ "git", @@ -307,8 +277,7 @@ fn test_git_init_external_at_operation() { ], ); insta::assert_snapshot!(stderr, @r###" - Done importing changes from the underlying Git repo. - Initialized repo in "." + Error: --at-op is not respected "###); } @@ -676,35 +645,13 @@ fn test_git_init_colocated_ignore_working_copy() { init_git_repo(&workspace_root, false); std::fs::write(workspace_root.join("file1"), "").unwrap(); - // No snapshot should be taken - let (_stdout, stderr) = test_env.jj_cmd_ok( + let stderr = test_env.jj_cmd_cli_error( &workspace_root, &["git", "init", "--ignore-working-copy", "--colocate"], ); insta::assert_snapshot!(stderr, @r###" - Done importing changes from the underlying Git repo. - Initialized repo in "." + Error: --ignore-working-copy is not respected "###); - - // FIXME: wrong HEAD, but fixing this would result in stale working copy - let (stdout, stderr) = - test_env.jj_cmd_ok(&workspace_root, &["status", "--ignore-working-copy"]); - insta::assert_snapshot!(stdout, @r###" - The working copy is clean - Working copy : qpvuntsm 230dd059 (empty) (no description set) - Parent commit: zzzzzzzz 00000000 (empty) (no description set) - "###); - insta::assert_snapshot!(stderr, @""); - - let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["status"]); - insta::assert_snapshot!(stdout, @r###" - Working copy changes: - A file1 - D some-file - Working copy : kkmpptxz 7864ea63 (no description set) - Parent commit: mwrttmos 8d698d4a my-branch | My commit message - "###); - insta::assert_snapshot!(stderr, @""); } #[test] @@ -713,14 +660,12 @@ fn test_git_init_colocated_at_operation() { let workspace_root = test_env.env_root().join("repo"); init_git_repo(&workspace_root, false); - // TODO: just error out? no operation should exist - let (_stdout, stderr) = test_env.jj_cmd_ok( + let stderr = test_env.jj_cmd_cli_error( &workspace_root, &["git", "init", "--at-op=@-", "--colocate"], ); insta::assert_snapshot!(stderr, @r###" - Done importing changes from the underlying Git repo. - Initialized repo in "." + Error: --at-op is not respected "###); } diff --git a/cli/tests/test_init_command.rs b/cli/tests/test_init_command.rs index 971238e36..1f2d044a2 100644 --- a/cli/tests/test_init_command.rs +++ b/cli/tests/test_init_command.rs @@ -546,4 +546,17 @@ fn test_init_local() { assert!(store_path.join("files").is_dir()); assert!(store_path.join("symlinks").is_dir()); assert!(store_path.join("conflicts").is_dir()); + + let stderr = test_env.jj_cmd_cli_error( + test_env.env_root(), + &["init", "--ignore-working-copy", "repo2"], + ); + insta::assert_snapshot!(stderr, @r###" + Error: --ignore-working-copy is not respected + "###); + + let stderr = test_env.jj_cmd_cli_error(test_env.env_root(), &["init", "--at-op=@-", "repo3"]); + insta::assert_snapshot!(stderr, @r###" + Error: --at-op is not respected + "###); }