# HG changeset patch # User Raphaël Gomès # Date 2022-05-25 14:50:00 # Node ID 044e42ae45d969a0bcba44952a3fe7bbb58b372b # Parent 455fce57e89e2e519121bc752a99151943222b31 rhg: add error message for paths outside the repository when cwd != root This mirrors the Python implementation. The relative path handling should probably be refactored into a util, but it it out of scope for this change. diff --git a/rust/rhg/src/commands/cat.rs b/rust/rhg/src/commands/cat.rs --- a/rust/rhg/src/commands/cat.rs +++ b/rust/rhg/src/commands/cat.rs @@ -67,10 +67,19 @@ pub fn run(invocation: &crate::CliInvoca let message = "`..` or `.` path segment"; return Err(CommandError::unsupported(message)); } + let relative_path = working_directory + .strip_prefix(&cwd) + .unwrap_or(&working_directory); let stripped = normalized .strip_prefix(&working_directory) - // TODO: error message for path arguments outside of the repo - .map_err(|_| CommandError::abort(""))?; + .map_err(|_| { + CommandError::abort(format!( + "abort: {} not under root '{}'\n(consider using '--cwd {}')", + file, + working_directory.display(), + relative_path.display(), + )) + })?; let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) .map_err(|e| CommandError::abort(e.to_string()))?; files.push(hg_file);