Initialize a new repository whose default view has the given name. Behaves like [`Repository::init`], but the initial shared root view — and the config's `[view] default` — is `view_name` instead of [`DEFAULT_VIEW`]. This is used by `atomic git import` so the imported repository's default view matches the Git default branch rather than leaving an unused `dev` view behind. # Arguments `path` - T
(
path: P,
view_name: &str,
)
| 458 | /// - The directory cannot be created |
| 459 | /// - The database cannot be initialized |
| 460 | pub fn init_with_view<P: AsRef<Path>>( |
| 461 | path: P, |
| 462 | view_name: &str, |
| 463 | ) -> Result<Self, RepositoryError> { |
| 464 | let root = path.as_ref().to_path_buf(); |
| 465 | let dot_dir = root.join(DOT_DIR); |
| 466 | |
| 467 | // Check if repository already exists |
| 468 | if dot_dir.exists() { |
| 469 | return Err(RepositoryError::AlreadyExists { |
| 470 | path: root.display().to_string(), |
| 471 | }); |
| 472 | } |
| 473 | |
| 474 | // Create directory structure |
| 475 | std::fs::create_dir_all(&dot_dir)?; |
| 476 | std::fs::create_dir_all(dot_dir.join("changes"))?; |
| 477 | std::fs::create_dir_all(dot_dir.join(WORKSPACES_DIR))?; |
| 478 | |
| 479 | // Create initial config |
| 480 | let config_path = dot_dir.join("config.toml"); |
| 481 | let initial_config = format!( |
| 482 | r#"# Atomic repository configuration |
| 483 | |
| 484 | [view] |
| 485 | default = "{}" |
| 486 | "#, |
| 487 | view_name |
| 488 | ); |
| 489 | std::fs::write(&config_path, initial_config)?; |
| 490 | |
| 491 | // Initialize the repository database (redb creates the file) |
| 492 | let pristine = |
| 493 | Arc::new(Pristine::open(dot_dir.join(DATABASE_FILE)).map_err(RepositoryError::from)?); |
| 494 | |
| 495 | // Create the default view and its workspace directory |
| 496 | { |
| 497 | let mut txn = pristine |
| 498 | .write_txn() |
| 499 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 500 | txn.open_or_create_view(view_name) |
| 501 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 502 | txn.commit() |
| 503 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 504 | } |
| 505 | ensure_workspace_dir(&dot_dir, view_name)?; |
| 506 | |
| 507 | // Persist the working-copy record before publishing compatibility files. |
| 508 | let layout = working_copy::discover_layout(&root)?; |
| 509 | let (_working_copy_id, current_view) = |
| 510 | working_copy::migrate_identity(&pristine, &layout, view_name)?; |
| 511 | |
| 512 | // Align the stored root with `open`: the layout discovery canonicalizes |
| 513 | // the working root (e.g. macOS `/var` → `/private/var`), and a |
| 514 | // repository initialized through a symlinked path must report the same |
| 515 | // root as one opened from disk. |
| 516 | let root = layout.working_root.clone(); |
| 517 | let dot_dir = root.join(DOT_DIR); |
nothing calls this directly
no test coverage detected