MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run

Method run

atomic-cli/src/commands/view/new.rs:321–423  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

319
320impl Command for New {
321 fn run(&self) -> CliResult<()> {
322 // Get the view name
323 let name = self
324 .name
325 .as_ref()
326 .ok_or_else(|| CliError::InvalidArgument {
327 message: "View name is required".to_string(),
328 })?;
329
330 // Validate the view name
331 validate_view_name(name).map_err(|msg| CliError::InvalidArgument { message: msg })?;
332
333 // Find the repository
334 let repo_root = find_repository_root()?;
335 let mut repo = Repository::open(&repo_root).map_err(|e| match e {
336 atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound {
337 searched_path: path.into(),
338 },
339 other => CliError::Repository(other),
340 })?;
341
342 // Check if the view already exists
343 if repo.view_exists(name).map_err(CliError::Repository)? {
344 return Err(CliError::ViewAlreadyExists {
345 name: name.to_string(),
346 });
347 }
348
349 // If --draft or --parent is specified, use the two-tier create path
350 if self.draft || self.parent.is_some() {
351 return self.run_two_tier(name, &mut repo);
352 }
353
354 // Determine how to create the new view:
355 //
356 // --from X → create Draft parented on X, insert X's changes
357 // default → create Draft parented on nearest Shared ancestor,
358 // with an EMPTY change log (no files until `insert`)
359 //
360 // The new view is a Draft workspace whose edges go to
361 // GRAPH (filtered by this view's change set). The parent link
362 // gives the overlay chain read-access to the shared graph for
363 // record-time diff computation.
364 //
365 // When --from is specified, the source's changes are inserted
366 // immediately so the new view starts with the source's files.
367 // Without --from, the change log starts empty — the user brings
368 // in changes explicitly via `insert from-view`. This is the
369 // normal workflow:
370 //
371 // atomic view create feature # empty workspace
372 // atomic insert from-view dev # inherit dev's files
373 // # ... make changes, record ...
374 // atomic insert from-view feature --to-view dev # promote
375 if let Some(ref source) = self.from {
376 // Explicit --from: fork from the specified view.
377 if !repo.view_exists(source).map_err(CliError::Repository)? {
378 return Err(CliError::ViewNotFound {

Calls 11

find_repository_rootFunction · 0.85
RepositoryClass · 0.85
print_successFunction · 0.85
as_refMethod · 0.80
view_existsMethod · 0.80
run_two_tierMethod · 0.80
get_view_infoMethod · 0.80
create_view_fromMethod · 0.80
validate_view_nameFunction · 0.70
create_viewMethod · 0.45
maybe_switchMethod · 0.45