Execute the diff command. This method: 1. Finds and opens the repository 2. Gets the status of the working copy 3. Computes diffs for modified files 4. Displays the diffs in the requested format
(&self)
| 217 | /// 3. Computes diffs for modified files |
| 218 | /// 4. Displays the diffs in the requested format |
| 219 | fn run(&self) -> CliResult<()> { |
| 220 | // Find the repository root |
| 221 | let repo_root = find_repository_root()?; |
| 222 | |
| 223 | // Open the repository |
| 224 | let repo = |
| 225 | Repository::open_readonly(&repo_root).map_err(|e| CliError::InvalidRepository { |
| 226 | reason: e.to_string(), |
| 227 | })?; |
| 228 | |
| 229 | // Parse algorithm |
| 230 | let algorithm = self.parse_algorithm()?; |
| 231 | |
| 232 | // Get output configuration |
| 233 | let config = self.get_output_config(); |
| 234 | |
| 235 | // If --change is specified, show the content of that specific change |
| 236 | if let Some(change_ref) = &self.change { |
| 237 | return self.show_change_diff(&repo, change_ref, &config); |
| 238 | } |
| 239 | |
| 240 | // Get status to find modified files |
| 241 | let status_options = StatusOptions::default(); |
| 242 | let status = repo |
| 243 | .status(status_options) |
| 244 | .map_err(|e| CliError::Internal(e.into()))?; |
| 245 | |
| 246 | // Collect files to diff |
| 247 | let files_to_diff: Vec<_> = if self.files.is_empty() { |
| 248 | // Diff all modified and added files |
| 249 | let mut entries: Vec<_> = status |
| 250 | .modified() |
| 251 | .chain(status.added()) |
| 252 | .chain(status.deleted()) |
| 253 | .map(|e| (e.path().to_path_buf(), e.status())) |
| 254 | .collect(); |
| 255 | |
| 256 | // Include untracked files if --untracked flag is set |
| 257 | if self.untracked { |
| 258 | entries.extend( |
| 259 | status |
| 260 | .untracked() |
| 261 | .map(|e| (e.path().to_path_buf(), e.status())), |
| 262 | ); |
| 263 | } |
| 264 | |
| 265 | entries |
| 266 | } else { |
| 267 | // Diff only specified files |
| 268 | self.files |
| 269 | .iter() |
| 270 | .filter_map(|path| { |
| 271 | let path_buf = PathBuf::from(path); |
| 272 | // Find the file in status |
| 273 | status |
| 274 | .entries() |
| 275 | .iter() |
| 276 | .find(|e| e.path() == path_buf) |