(
&self,
request: Request<RemoveFilesRequest>,
)
| 1674 | } |
| 1675 | |
| 1676 | async fn remove_files( |
| 1677 | &self, |
| 1678 | request: Request<RemoveFilesRequest>, |
| 1679 | ) -> Result<Response<RemoveFilesResponse>, Status> { |
| 1680 | let request = request.into_inner(); |
| 1681 | let handle = self |
| 1682 | .state |
| 1683 | .resolve(request.repository.as_ref().unwrap_or(&default_ref()))?; |
| 1684 | self.state.log_rpc("RemoveFiles", Some(&handle)); |
| 1685 | // `keep_working_copy` guards the paths tracking untracks outright |
| 1686 | // (`--delete`); `untrack_only` is `--keep`, the `git rm --cached` shape |
| 1687 | // that stages a recorded path's untrack as pending intent with bytes |
| 1688 | // kept. The daemon mirrors the CLI's `git rm` matrix. |
| 1689 | let keep = request.keep_working_copy; |
| 1690 | let untrack_only = request.untrack_only; |
| 1691 | let gate_handle = handle.clone(); |
| 1692 | let _gate = gate_handle.exclusive().await; |
| 1693 | let result = tokio::task::spawn_blocking(move || -> Result<RemoveFilesResponse, Status> { |
| 1694 | let (repo, workspace) = handle.workspace_repository(if request.dry_run { |
| 1695 | atomic_repository::WorkspaceTxnMode::Observe |
| 1696 | } else { |
| 1697 | atomic_repository::WorkspaceTxnMode::Reconcile |
| 1698 | })?; |
| 1699 | let working_copy = workspace.working_copy(); |
| 1700 | let options = TrackingOptions { |
| 1701 | force: request.force, |
| 1702 | dry_run: request.dry_run, |
| 1703 | // `--keep` (`git rm --cached`): recorded paths stage their |
| 1704 | // untrack as per-view pending intent instead of deferring to a |
| 1705 | // working-copy deletion; the next record lands the delete with |
| 1706 | // the bytes kept. |
| 1707 | keep_recorded: untrack_only, |
| 1708 | ..TrackingOptions::default() |
| 1709 | }; |
| 1710 | // Validate every path before applying any of it, as `git rm` does: a |
| 1711 | // refusal must never leave the other paths half-untracked. The plan |
| 1712 | // is the same classification a mutation applies, so a preview reports |
| 1713 | // exactly what the command would do. |
| 1714 | let mut refusals: Vec<RemovalRefusal> = Vec::new(); |
| 1715 | let mut plan: Vec<( |
| 1716 | String, |
| 1717 | usize, |
| 1718 | Vec<std::path::PathBuf>, |
| 1719 | Vec<std::path::PathBuf>, |
| 1720 | )> = Vec::new(); |
| 1721 | for path in &request.paths { |
| 1722 | // Normalize exactly like the CLI: absolute paths must be |
| 1723 | // inside the repository root and are made relative. |
| 1724 | let normalized = if std::path::Path::new(path).is_absolute() { |
| 1725 | match std::path::Path::new(path).strip_prefix(&handle.root) { |
| 1726 | Ok(rel) => rel.display().to_string(), |
| 1727 | Err(_) => { |
| 1728 | return Err(domain_status( |
| 1729 | ErrorCode::InvalidArgument, |
| 1730 | format!("path outside repository: {path}"), |
| 1731 | )) |
| 1732 | } |
| 1733 | } |
nothing calls this directly
no test coverage detected