`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)
| 6098 | /// composes the same wire `view create --from` uses, and the CLI prints |
| 6099 | /// the SPLIT body's report lines from the created view's info. |
| 6100 | pub fn split(args: &super::split::Split) -> CliResult<bool> { |
| 6101 | // The pure name validation stays client-side (the local body's first |
| 6102 | // check, with the same messages). |
| 6103 | super::split::validate_view_name(&args.name) |
| 6104 | .map_err(|message| CliError::InvalidArgument { message })?; |
| 6105 | let Some(session) = Service::open()? else { |
| 6106 | return Ok(false); |
| 6107 | }; |
| 6108 | // The source view default reads the working-copy marker (the same |
| 6109 | // client-side default the local body applies). |
| 6110 | let source = args |
| 6111 | .source |
| 6112 | .clone() |
| 6113 | .unwrap_or_else(|| current_view_name().unwrap_or_default()); |
| 6114 | let request = pb::CreateViewRequest { |
| 6115 | repository: Some(session.reference.clone()), |
| 6116 | meta: None, |
| 6117 | name: args.name.clone(), |
| 6118 | base: Some(pb::create_view_request::Base::FromView(source.clone())), |
| 6119 | scope: pb::ViewScope::Unspecified as i32, |
| 6120 | base_snapshot: None, |
| 6121 | }; |
| 6122 | let response = session.create_view(request)?; |
| 6123 | let view = response.view.expect("created view info"); |
| 6124 | let change_count = view.change_count; |
| 6125 | if change_count > 0 { |
| 6126 | print_success(&format!( |
| 6127 | "Created view: {} (split from {} with {} changes)", |
| 6128 | crate::output::view(&args.name), |
| 6129 | crate::output::view(&source), |
| 6130 | change_count |
| 6131 | )); |
| 6132 | } else { |
| 6133 | print_success(&format!( |
| 6134 | "Created view: {} (split from {} - empty)", |
| 6135 | crate::output::view(&args.name), |
| 6136 | crate::output::view(&source) |
| 6137 | )); |
| 6138 | } |
| 6139 | if args.switch { |
| 6140 | let switched = session.switch_view(pb::SwitchViewRequest { |
| 6141 | repository: Some(session.reference.clone()), |
| 6142 | meta: None, |
| 6143 | view: args.name.clone(), |
| 6144 | bypass_dirty_check: None, |
| 6145 | })?; |
| 6146 | print_success(&format!( |
| 6147 | "Switched to view: {} ({} files updated)", |
| 6148 | args.name, switched.files_written |
| 6149 | )); |
| 6150 | } else { |
| 6151 | print_hint(&format!( |
| 6152 | "Use 'atomic view switch {}' to switch to the new view", |
| 6153 | args.name |
| 6154 | )); |
| 6155 | } |
| 6156 | Ok(true) |
| 6157 | } |
no test coverage detected