`atomic split` over CreateView (FromView) + SwitchView — the wrapper composes the same wire `view create --from` uses, and the CLI prints the SPLIT body's report lines from the created view's info.
(args: &super::split::Split)
| 6058 | /// composes the same wire `view create --from` uses, and the CLI prints |
| 6059 | /// the SPLIT body's report lines from the created view's info. |
| 6060 | pub fn split(args: &super::split::Split) -> CliResult<bool> { |
| 6061 | // The pure name validation stays client-side (the local body's first |
| 6062 | // check, with the same messages). |
| 6063 | super::split::validate_view_name(&args.name) |
| 6064 | .map_err(|message| CliError::InvalidArgument { message })?; |
| 6065 | let Some(session) = Service::open()? else { |
| 6066 | return Ok(false); |
| 6067 | }; |
| 6068 | // The source view default reads the working-copy marker (the same |
| 6069 | // client-side default the local body applies). |
| 6070 | let source = args |
| 6071 | .source |
| 6072 | .clone() |
| 6073 | .unwrap_or_else(|| current_view_name().unwrap_or_default()); |
| 6074 | let request = pb::CreateViewRequest { |
| 6075 | repository: Some(session.reference.clone()), |
| 6076 | meta: None, |
| 6077 | name: args.name.clone(), |
| 6078 | base: Some(pb::create_view_request::Base::FromView(source.clone())), |
| 6079 | scope: pb::ViewScope::Unspecified as i32, |
| 6080 | base_snapshot: None, |
| 6081 | }; |
| 6082 | let response = session.create_view(request)?; |
| 6083 | let view = response.view.expect("created view info"); |
| 6084 | let change_count = view.change_count; |
| 6085 | if change_count > 0 { |
| 6086 | print_success(&format!( |
| 6087 | "Created view: {} (split from {} with {} changes)", |
| 6088 | crate::output::view(&args.name), |
| 6089 | crate::output::view(&source), |
| 6090 | change_count |
| 6091 | )); |
| 6092 | } else { |
| 6093 | print_success(&format!( |
| 6094 | "Created view: {} (split from {} - empty)", |
| 6095 | crate::output::view(&args.name), |
| 6096 | crate::output::view(&source) |
| 6097 | )); |
| 6098 | } |
| 6099 | if args.switch { |
| 6100 | let switched = session.switch_view(pb::SwitchViewRequest { |
| 6101 | repository: Some(session.reference.clone()), |
| 6102 | meta: None, |
| 6103 | view: args.name.clone(), |
| 6104 | bypass_dirty_check: None, |
| 6105 | })?; |
| 6106 | print_success(&format!( |
| 6107 | "Switched to view: {} ({} files updated)", |
| 6108 | args.name, switched.files_written |
| 6109 | )); |
| 6110 | } else { |
| 6111 | print_hint(&format!( |
| 6112 | "Use 'atomic view switch {}' to switch to the new view", |
| 6113 | args.name |
| 6114 | )); |
| 6115 | } |
| 6116 | Ok(true) |
| 6117 | } |
no test coverage detected