forked from mirrors/jj
cli: error out early if -R path is invalid
It should be better to handle invalid -R path globally. The error message is a bit worse, but I think it's still okay. This helps to load temporary config from the cwd-relative path. If the command processing continued with an invalid -R path, the temporary config would have to be explicitly discarded.
This commit is contained in:
parent
c82b2c78fd
commit
941e53802f
4 changed files with 6 additions and 10 deletions
|
@ -2975,8 +2975,10 @@ impl CliRunner {
|
|||
}
|
||||
|
||||
let maybe_workspace_loader = if let Some(path) = &args.global_args.repository {
|
||||
WorkspaceLoader::init(&cwd.join(path))
|
||||
.map_err(|err| map_workspace_load_error(err, Some(path)))
|
||||
// Invalid -R path is an error. No need to proceed.
|
||||
let loader = WorkspaceLoader::init(&cwd.join(path))
|
||||
.map_err(|err| map_workspace_load_error(err, Some(path)))?;
|
||||
Ok(loader)
|
||||
} else {
|
||||
WorkspaceLoader::init(find_workspace_dir(&cwd))
|
||||
.map_err(|err| map_workspace_load_error(err, None))
|
||||
|
|
|
@ -442,9 +442,6 @@ fn cmd_git_clone(
|
|||
command: &CommandHelper,
|
||||
args: &GitCloneArgs,
|
||||
) -> Result<(), CommandError> {
|
||||
if command.global_args().repository.is_some() {
|
||||
return Err(user_error("'--repository' cannot be used with 'git clone'"));
|
||||
}
|
||||
let remote_name = "origin";
|
||||
let source = absolute_git_source(command.cwd(), &args.source);
|
||||
let wc_path_str = args
|
||||
|
|
|
@ -53,9 +53,6 @@ pub(crate) fn cmd_init(
|
|||
command: &CommandHelper,
|
||||
args: &InitArgs,
|
||||
) -> Result<(), CommandError> {
|
||||
if command.global_args().repository.is_some() {
|
||||
return Err(user_error("'--repository' cannot be used with 'init'"));
|
||||
}
|
||||
let wc_path = command.cwd().join(&args.destination);
|
||||
match fs::create_dir(&wc_path) {
|
||||
Ok(()) => {}
|
||||
|
|
|
@ -133,7 +133,7 @@ fn test_repo_arg_with_init() {
|
|||
let test_env = TestEnvironment::default();
|
||||
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["init", "-R=.", "repo"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: '--repository' cannot be used with 'init'
|
||||
Error: There is no jj repo in "."
|
||||
"###);
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ fn test_repo_arg_with_git_clone() {
|
|||
let test_env = TestEnvironment::default();
|
||||
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["git", "clone", "-R=.", "remote"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: '--repository' cannot be used with 'git clone'
|
||||
Error: There is no jj repo in "."
|
||||
"###);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue