(root: &Path, budget: ReconcileEffectBudget)
| 1797 | /// defers instead of replaying. |
| 1798 | #[tracing::instrument(name = "import_head", skip_all, fields(budget = ?budget))] |
| 1799 | fn import_git_to_atomic_budgeted(root: &Path, budget: ReconcileEffectBudget) -> CliResult<()> { |
| 1800 | let _span_preflight = |
| 1801 | Repository::try_lock_git_import_without_span(root, budget.is_metadata_only()) |
| 1802 | .map_err(|error| git_error(format!("Git shim import preflight refused: {error}")))?; |
| 1803 | let git = open_git(root)?; |
| 1804 | let head = observe_head(&git).map_err(observation_error)?; |
| 1805 | // §7.5: a detached HEAD imports behind its commit into the workspace |
| 1806 | // head-map/checkpoint view, or a fresh ephemeral `git/<oid>` Draft view. |
| 1807 | // An attached HEAD keeps the historical branch-name behavior. |
| 1808 | let (view, detached_tip) = match &head { |
| 1809 | HeadObservation::Attached { symref, .. } => ( |
| 1810 | symref |
| 1811 | .strip_prefix("refs/heads/") |
| 1812 | .map(str::to_string) |
| 1813 | .ok_or_else(|| { |
| 1814 | git_error(format!("Git HEAD symref '{symref}' is not a local branch")) |
| 1815 | })?, |
| 1816 | None, |
| 1817 | ), |
| 1818 | HeadObservation::Detached { oid } => { |
| 1819 | let oid_hex = oid.to_string(); |
| 1820 | let mut repo = Repository::open_with_budget(root, budget).map_err(CliError::from)?; |
| 1821 | let target = repo |
| 1822 | .detached_import_target(&oid_hex) |
| 1823 | .map_err(CliError::from)?; |
| 1824 | let (view, created) = match target { |
| 1825 | atomic_repository::DetachedImportTarget::Mapped { view } => (view, false), |
| 1826 | // CB-13D ::24 R1: an ephemeral view creation is a |
| 1827 | // metadata-changing import step — under the metadata-only |
| 1828 | // reactive budget the boundary defers with the unsafe-state |
| 1829 | // remediation instead of creating the view (the refused |
| 1830 | // head adoption must not fall through into a |
| 1831 | // metadata-changing import). |
| 1832 | atomic_repository::DetachedImportTarget::Ephemeral { view } |
| 1833 | if budget.is_metadata_only() => |
| 1834 | { |
| 1835 | return Err(CliError::Repository( |
| 1836 | atomic_repository::RepositoryError::ReactiveDeferred { |
| 1837 | detail: format!( |
| 1838 | "detached Git HEAD '{oid_hex}' would create ephemeral view '{view}'; that metadata-changing import step is deferred to an explicit 'atomic git shim reconcile'" |
| 1839 | ), |
| 1840 | }, |
| 1841 | )); |
| 1842 | } |
| 1843 | atomic_repository::DetachedImportTarget::Ephemeral { view } => { |
| 1844 | // A detached HEAD on a commit this repository already |
| 1845 | // interpreted (a checkout of an imported ancestor, `git |
| 1846 | // bisect`) is exactly that commit's closure: a parentless |
| 1847 | // Draft referencing the change. A Draft under the |
| 1848 | // checkpoint view would inherit every later member, so |
| 1849 | // its tip could never be an ancestor of the parent's tip |
| 1850 | // and the reconcile would strand the workspace. |
| 1851 | let interpreted = repo.checked_git_sha(&oid_hex).map_err(CliError::from)?; |
| 1852 | if let Some(hash) = interpreted { |
| 1853 | repo.create_view_with_identity( |
| 1854 | &view, |
| 1855 | atomic_core::pristine::ViewScope::Draft, |
| 1856 | None, |
no test coverage detected