From 20ff88461b6dc35b61057cf98e5fd121d388aeeb Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 2 Mar 2022 13:14:06 -0800 Subject: [PATCH] cli: error out if `-R` is not applicable Closes #101. --- src/commands.rs | 10 ++++++++++ tests/test_global_opts.rs | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index 9e0874720..d3b062826 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1719,6 +1719,11 @@ fn add_to_git_exclude(ui: &mut Ui, git_repo: &git2::Repository) -> Result<(), Co } fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &ArgMatches) -> Result<(), CommandError> { + if command.root_args.occurrences_of("repository") > 0 { + return Err(CommandError::UserError( + "'--repository' cannot be used with 'init'".to_string(), + )); + } let wc_path_str = args.value_of("destination").unwrap(); let wc_path = ui.cwd().join(wc_path_str); if wc_path.exists() { @@ -4219,6 +4224,11 @@ fn cmd_git_clone( command: &CommandHelper, args: &ArgMatches, ) -> Result<(), CommandError> { + if command.root_args.occurrences_of("repository") > 0 { + return Err(CommandError::UserError( + "'--repository' cannot be used with 'git clone'".to_string(), + )); + } let source = args.value_of("source").unwrap(); let wc_path_str = args .value_of("destination") diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index abb87cab9..afae08b6f 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -51,3 +51,23 @@ fn test_no_commit_working_copy() { let modified_commit_id_hex = get_stdout_string(&assert); assert_ne!(modified_commit_id_hex, initial_commit_id_hex); } + +#[test] +fn test_repo_arg_with_init() { + let test_env = TestEnvironment::default(); + let assert = test_env + .jj_cmd(test_env.env_root(), &["init", "-R=.", "repo"]) + .assert() + .failure(); + assert.stdout("Error: '--repository' cannot be used with 'init'\n"); +} + +#[test] +fn test_repo_arg_with_git_clone() { + let test_env = TestEnvironment::default(); + let assert = test_env + .jj_cmd(test_env.env_root(), &["git", "clone", "-R=.", "remote"]) + .assert() + .failure(); + assert.stdout("Error: '--repository' cannot be used with 'git clone'\n"); +}