(root: &Path, budget: ReconcileEffectBudget)
| 1841 | /// defers instead of replaying. |
| 1842 | #[tracing::instrument(name = "import_head", skip_all, fields(budget = ?budget))] |
| 1843 | fn import_git_to_atomic_budgeted(root: &Path, budget: ReconcileEffectBudget) -> CliResult<()> { |
| 1844 | let _span_preflight = |
| 1845 | Repository::try_lock_git_import_without_span(root, budget.is_metadata_only()) |
| 1846 | .map_err(|error| git_error(format!("Git shim import preflight refused: {error}")))?; |
| 1847 | let git = open_git(root)?; |
| 1848 | let head = observe_head(&git).map_err(observation_error)?; |
| 1849 | // §7.5: a detached HEAD imports behind its commit into the workspace |
| 1850 | // head-map/checkpoint view, or a fresh ephemeral `git/<oid>` Draft view. |
| 1851 | // An attached HEAD keeps the historical branch-name behavior. |
| 1852 | let (view, detached_tip) = match &head { |
| 1853 | HeadObservation::Attached { symref, .. } => ( |
| 1854 | symref |
| 1855 | .strip_prefix("refs/heads/") |
| 1856 | .map(str::to_string) |
| 1857 | .ok_or_else(|| { |
| 1858 | git_error(format!("Git HEAD symref '{symref}' is not a local branch")) |
| 1859 | })?, |
| 1860 | None, |
| 1861 | ), |
| 1862 | HeadObservation::Detached { oid } => { |
| 1863 | let oid_hex = oid.to_string(); |
| 1864 | let mut repo = Repository::open_with_budget(root, budget).map_err(CliError::from)?; |
| 1865 | let target = repo |
| 1866 | .detached_import_target(&oid_hex) |
| 1867 | .map_err(CliError::from)?; |
| 1868 | let (view, created) = match target { |
| 1869 | atomic_repository::DetachedImportTarget::Mapped { view } => (view, false), |
| 1870 | // CB-13D ::24 R1: an ephemeral view creation is a |
| 1871 | // metadata-changing import step — under the metadata-only |
| 1872 | // reactive budget the boundary defers with the unsafe-state |
| 1873 | // remediation instead of creating the view (the refused |
| 1874 | // head adoption must not fall through into a |
| 1875 | // metadata-changing import). |
| 1876 | atomic_repository::DetachedImportTarget::Ephemeral { view } |
| 1877 | if budget.is_metadata_only() => |
| 1878 | { |
| 1879 | return Err(CliError::Repository( |
| 1880 | atomic_repository::RepositoryError::ReactiveDeferred { |
| 1881 | detail: format!( |
| 1882 | "detached Git HEAD '{oid_hex}' would create ephemeral view '{view}'; that metadata-changing import step is deferred to an explicit 'atomic git shim reconcile'" |
| 1883 | ), |
| 1884 | }, |
| 1885 | )); |
| 1886 | } |
| 1887 | atomic_repository::DetachedImportTarget::Ephemeral { view } => { |
| 1888 | // A detached HEAD on a commit this repository already |
| 1889 | // interpreted (a checkout of an imported ancestor, `git |
| 1890 | // bisect`) is exactly that commit's closure: a parentless |
| 1891 | // Draft referencing the change. A Draft under the |
| 1892 | // checkpoint view would inherit every later member, so |
| 1893 | // its tip could never be an ancestor of the parent's tip |
| 1894 | // and the reconcile would strand the workspace. |
| 1895 | let interpreted = repo.checked_git_sha(&oid_hex).map_err(CliError::from)?; |
| 1896 | if let Some(hash) = interpreted { |
| 1897 | repo.create_view_with_identity( |
| 1898 | &view, |
| 1899 | atomic_core::pristine::ViewScope::Draft, |
| 1900 | None, |
no test coverage detected