Repository: google/comprehensive-rust
File: xtask/src/main.rs (Rust)

Code before:
    // Collect the files relevant for evaluation.
    // - CI environment variable is set: all modified markdown files in the src/
    //   directory
    // - all html files in the provided directory otherwise
    let candidate_slides: Vec<PathBuf> = if env::var("CI").is_ok() {
        println!("CI environment detected, checking only modified slides.");
        // GITHUB_BASE_REF is available in PRs. Default to 'main' for other CI
        // contexts.
        let base_ref = env::var("GITHUB_BASE_REF").unwrap_or("main".to_string());
        let mut cmd = Command::new("git");
        cmd.arg("diff")
            .arg("--name-only")
            .arg(format!("{}...", base_ref))
            .arg("--")
            // Retrieve all modified files in the src directory.
            // Pathspec syntax: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-pathspec
            // * can match path separators, thus matches also files in subdirectories
            .arg("src/*.md");
        println!("> {cmd:?}");
        let output = cmd.output().context("Failed to run git diff")?;
        String::from_utf8(output.stdout)?
            .lines()
            .map(|line| {
                let path = Path::new(line);
                // We know the path starts with "src/" because of the pathspec in the
                // git diff command. and we need it relative to the html base
                // directory
                let stripped_path = path.strip_prefix("src").unwrap();
                let mut html_path = stripped_path.to_path_buf();
                // replace the .md extension with .html
                html_path.set_extension("html");
                html_path
            })
            .collect()
    } else {
        println!("Local environment, checking all slides.");
        WalkDir::new(&html_directory)
            .into_iter()
            .filter_map(|e| e.ok())
            // only files with .html extension
            .filter(|e| e.path().extension().is_some_and(|ext| ext == "html"))
            // relative path inside the html directory
            .map(|e| e.path().strip_prefix(&html_directory).unwrap().to_path_buf())
            .collect()
    };
    // Filter the candidate slides
    let mut slides = Vec::new();
    for slide in candidate_slides {
        // Skip excluded files
        if exclude_paths.iter().any(|exclude_path| slide.ends_with(exclude_path)) {
            continue;

Review comment (suggestion):
```suggestion
                // `git diff` command, and we need it relative to the html base
```

Code after:
    // Collect the files relevant for evaluation.
    // - CI environment variable is set: all modified markdown files in the src/
    //   directory
    // - all html files in the provided directory otherwise
    let candidate_slides: Vec<PathBuf> = if env::var("CI").is_ok() {
        println!("CI environment detected, checking only modified slides.");
        // GITHUB_BASE_REF is available in PRs. Default to 'main' for other CI
        // contexts.
        let base_ref = env::var("GITHUB_BASE_REF").unwrap_or("main".to_string());
        let mut cmd = Command::new("git");
        cmd.arg("diff")
            .arg("--name-only")
            .arg(format!("{}...", base_ref))
            .arg("--")
            // Retrieve all modified files in the src directory.
            // Pathspec syntax: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-pathspec
            // `*` can match path separators, thus matches also files in
            // subdirectories
            .arg("src/*.md");
        println!("> {cmd:?}");
        let output = cmd.output().context("Failed to run git diff")?;
        String::from_utf8(output.stdout)?
            .lines()
            .map(|line| {
                let path = Path::new(line);
                // We know the path starts with "src/" because of the pathspec in the
                // `git diff` command, and we need it relative to the html base
                // directory
                let stripped_path = path.strip_prefix("src").unwrap();
                let mut html_path = stripped_path.to_path_buf();
                // replace the .md extension with .html
                html_path.set_extension("html");
                html_path
            })
            .collect()
    } else {
        println!("Local environment, checking all slides.");
        WalkDir::new(&html_directory)
            .into_iter()
            .filter_map(|e| e.ok())
            // only files with .html extension
            .filter(|e| e.path().extension().is_some_and(|ext| ext == "html"))
            // relative path inside the html directory
            .map(|e| e.path().strip_prefix(&html_directory).unwrap().to_path_buf())
            .collect()
    };
    // Filter the candidate slides
    let mut slides = Vec::new();
    for slide in candidate_slides {
        // Skip excluded files
        if exclude_paths.iter().any(|exclude_path| slide.ends_with(exclude_path)) {