use super::*;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BashMutation {
pub path: String,
pub verb: &'static str,
pub cwd_at: CwdAt,
}
pub(crate) const GIT_MUTATING: &[&str] = &[
"add", "commit", "checkout", "reset", "rm", "mv", "restore", "stash", "merge", "rebase",
"apply", "clean",
];
#[must_use]
pub fn parse_bash_mutations(command: &str) -> Vec<BashMutation> {
let (command, bodies) = strip_heredoc_bodies_keeping(command);
let mask = shell_mask(&command);
let mut out = Vec::new();
let mut tracker = CwdTracker::new();
let mut body_cursor = 0usize;
for (segment, seg_mask) in split_segments(&command, &mask)
.into_iter()
.zip(split_segments(&mask, &mask))
{
let before = out.len();
let body_end = (body_cursor + heredoc_delims(segment).len()).min(bodies.len());
parse_segment(segment, seg_mask, &bodies[body_cursor..body_end], &mut out);
body_cursor = body_end;
let at = tracker.checkpoint();
for m in &mut out[before..] {
m.cwd_at = at.clone();
}
tracker.observe_segment(segment, seg_mask);
}
out
}
pub(crate) fn is_fully_masked(masked: &str) -> bool {
!masked.is_empty() && masked.chars().all(|c| c == MASK_CHAR)
}