changeset 49375:044e42ae45d9 stable

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.
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 25 May 2022 16:50:00 +0200
parents 455fce57e89e
children 6b04f702c501
files rust/rhg/src/commands/cat.rs
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rust/rhg/src/commands/cat.rs	Wed May 18 15:53:28 2022 +0100
+++ b/rust/rhg/src/commands/cat.rs	Wed May 25 16:50:00 2022 +0200
@@ -67,10 +67,19 @@
             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);