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

Method run

atomic-cli/src/commands/split.rs:156–244  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

154
155impl Command for Split {
156 fn run(&self) -> CliResult<()> {
157 // Route every form through the service layer: the wrapper composes
158 // the same CreateView(FromView) wire `view create --from` uses (plus
159 // SwitchView when --switch), and this render prints the split
160 // body's report from the wire-carried counts.
161 if crate::commands::rpc::split(self)? {
162 return Ok(());
163 }
164
165 // Validate the new view name
166 validate_view_name(&self.name).map_err(|msg| CliError::InvalidArgument { message: msg })?;
167
168 // Find the repository
169 let repo_root = find_repository_root()?;
170 let mut repo = Repository::open(&repo_root).map_err(|e| match e {
171 atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound {
172 searched_path: path.into(),
173 },
174 other => CliError::Repository(other),
175 })?;
176 let working_copy = repo
177 .require_working_copy_id()
178 .map_err(CliError::Repository)?;
179 let desired_view = repo
180 .desired_view_name(working_copy)
181 .map_err(CliError::Repository)?;
182
183 // Determine source view (default to the working copy's desired view)
184 let source = self.source.clone().unwrap_or(desired_view);
185
186 // Verify source view exists
187 if !repo.view_exists(&source).map_err(CliError::Repository)? {
188 return Err(CliError::ViewNotFound {
189 name: source.clone(),
190 });
191 }
192
193 // Check if the new view already exists
194 if repo.view_exists(&self.name).map_err(CliError::Repository)? {
195 return Err(CliError::ViewAlreadyExists {
196 name: self.name.clone(),
197 });
198 }
199
200 // Get source view info for reporting
201 let source_info = repo.get_view_info(&source).map_err(CliError::Repository)?;
202 let change_count = source_info.change_count;
203
204 // Create the new view by copying change log from source.
205 // This does NOT re-insert changes into the graph - it just copies metadata.
206 // This avoids conflicts that would occur if we tried to re-insert changes
207 // that have already modified the shared graph.
208 repo.create_view_from(&self.name, &source)
209 .map_err(CliError::Repository)?;
210
211 if change_count > 0 {
212 print_success(&format!(
213 "Created view: {} (split from {} with {} changes)",

Callers

nothing calls this directly

Calls 14

splitFunction · 0.85
find_repository_rootFunction · 0.85
openFunction · 0.85
RepositoryClass · 0.85
print_successFunction · 0.85
print_hintFunction · 0.85
desired_view_nameMethod · 0.80
view_existsMethod · 0.80
get_view_infoMethod · 0.80
create_view_fromMethod · 0.80
validate_view_nameFunction · 0.70

Tested by

no test coverage detected