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

Method validate_and_warn

atomic-cli/src/commands/view/delete.rs:177–235  ·  view source on GitHub ↗

Validations that must hold on every path, plus (optionally) the orphan warning and acknowledgement prompt.

(
        &self,
        repo: &Repository,
        name: &str,
        warn_orphans: bool,
        confirm: F,
    )

Source from the content-addressed store, hash-verified

175 /// Validations that must hold on every path, plus (optionally) the
176 /// orphan warning and acknowledgement prompt.
177 fn validate_and_warn<F>(
178 &self,
179 repo: &Repository,
180 name: &str,
181 warn_orphans: bool,
182 confirm: F,
183 ) -> CliResult<()>
184 where
185 F: FnOnce(&str) -> CliResult<bool>,
186 {
187 // Check if trying to delete the working copy's desired view
188 let working_copy = repo
189 .require_working_copy_id()
190 .map_err(CliError::Repository)?;
191 let desired_view = repo
192 .desired_view_name(working_copy)
193 .map_err(CliError::Repository)?;
194 if desired_view == name {
195 return Err(CliError::CannotDeleteCurrentView {
196 name: name.to_string(),
197 });
198 }
199
200 // Check if the view exists
201 if !repo.view_exists(name).map_err(CliError::Repository)? {
202 return Err(CliError::ViewNotFound {
203 name: name.to_string(),
204 });
205 }
206
207 if !warn_orphans {
208 return Ok(());
209 }
210
211 let orphans = repo
212 .view_deletion_orphans(name)
213 .map_err(CliError::Repository)?;
214 if !orphans.is_empty() {
215 print_warning(&format!(
216 "Deleting '{}' would orphan {} change(s): no remaining view references them.",
217 name,
218 orphans.len(),
219 ));
220 for hash in &orphans {
221 println!(" {}", style_hash(hash.to_base32()));
222 }
223 print_warning(
224 "Their data is not erased by view deletion, but they will disappear from all views and will not return to the source automatically.",
225 );
226 print_hint("Insert these changes into another view before deleting this one to keep them referenced.");
227 if !self.force
228 && !confirm("I understand these changes will be orphaned; delete the view")?
229 {
230 return Err(CliError::Cancelled);
231 }
232 }
233
234 Ok(())

Callers 2

runMethod · 0.80

Calls 7

print_warningFunction · 0.85
print_hintFunction · 0.85
desired_view_nameMethod · 0.80
view_existsMethod · 0.80
view_deletion_orphansMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected