Normalize a path relative to the repository root.
(&self, repo_root: &Path, path: &str)
| 133 | |
| 134 | /// Normalize a path relative to the repository root. |
| 135 | fn normalize_path(&self, repo_root: &Path, path: &str) -> CliResult<String> { |
| 136 | let p = Path::new(path); |
| 137 | // On Windows, Path::is_absolute() returns false for Unix-style "/foo" |
| 138 | // paths (they're drive-relative). Treat a leading '/' as absolute on |
| 139 | // all platforms so cross-platform behaviour is consistent. |
| 140 | let looks_absolute = p.is_absolute() || path.starts_with('/'); |
| 141 | if looks_absolute { |
| 142 | match p.strip_prefix(repo_root) { |
| 143 | Ok(rel) => Ok(rel.to_string_lossy().to_string()), |
| 144 | Err(_) => Err(CliError::PathOutsideRepository { |
| 145 | path: PathBuf::from(path), |
| 146 | }), |
| 147 | } |
| 148 | } else { |
| 149 | Ok(path.to_string()) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /// Resolve the destination path. |
| 154 | /// |
no outgoing calls