cli: error out if -R is not applicable

Closes #101.
This commit is contained in:
Martin von Zweigbergk 2022-03-02 13:14:06 -08:00 committed by Martin von Zweigbergk
parent eed9d48bf7
commit 20ff88461b
2 changed files with 30 additions and 0 deletions

View file

@ -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")

View file

@ -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");
}