Move or rename a tracked file. This updates the tracking to reflect a file move/rename. The file's history is preserved because the inode stays the same. Note: This does NOT move the actual file on disk. You should move the file first, then call this method. # Arguments `from` - Current path of the file `to` - New path for the file # Example ```rust,ignore // First move the actual file std::
(
&self,
from: P,
to: Q,
)
| 422 | /// repo.move_file("old_name.rs", "new_name.rs")?; |
| 423 | /// ``` |
| 424 | pub fn move_file<P: AsRef<Path>, Q: AsRef<Path>>( |
| 425 | &self, |
| 426 | from: P, |
| 427 | to: Q, |
| 428 | ) -> Result<Inode, RepositoryError> { |
| 429 | let from_normalized = normalize_path(from.as_ref()); |
| 430 | let to_normalized = normalize_path(to.as_ref()); |
| 431 | |
| 432 | let mut txn = self |
| 433 | .pristine |
| 434 | .write_txn() |
| 435 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 436 | |
| 437 | let inode = |
| 438 | move_tracked(&mut txn, &from_normalized, &to_normalized).map_err(|e| match e { |
| 439 | TrackingError::NotTracked { path } => RepositoryError::FileNotTracked { |
| 440 | path: PathBuf::from(path), |
| 441 | }, |
| 442 | TrackingError::DestinationExists { path } => RepositoryError::FileAlreadyTracked { |
| 443 | path: PathBuf::from(path), |
| 444 | }, |
| 445 | other => RepositoryError::Database(other.to_string()), |
| 446 | })?; |
| 447 | |
| 448 | txn.commit() |
| 449 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 450 | |
| 451 | Ok(inode) |
| 452 | } |
| 453 | |
| 454 | /// Check if a file is tracked. |
| 455 | /// |