view rust/rhg/src/commands/debugignorerhg.rs @ 49550:363923bd51cd stable

dirstate-v2: hash the source of the ignore patterns as well Fixes the test introduced in the last changeset. This caused the hash to change, which means that the check in the test had to be adapted. Since this hash is only done as a caching mechanism, invalidation does not pose any backwards compatibility issues.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 02 Nov 2022 12:05:34 +0100
parents 6d4daf51283c
children 37bc3edef76f
line wrap: on
line source

use crate::error::CommandError;
use clap::SubCommand;
use hg;
use hg::matchers::get_ignore_matcher;
use hg::StatusError;
use log::warn;

pub const HELP_TEXT: &str = "
Show effective hgignore patterns used by rhg.

This is a pure Rust version of `hg debugignore`.

Some options might be missing, check the list below.
";

pub fn args() -> clap::App<'static, 'static> {
    SubCommand::with_name("debugignorerhg").about(HELP_TEXT)
}

pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
    let repo = invocation.repo?;

    let ignore_file = repo.working_directory_vfs().join(".hgignore"); // TODO hardcoded

    let (ignore_matcher, warnings) = get_ignore_matcher(
        vec![ignore_file],
        &repo.working_directory_path().to_owned(),
        &mut |_source, _pattern_bytes| (),
    )
    .map_err(|e| StatusError::from(e))?;

    if !warnings.is_empty() {
        warn!("Pattern warnings: {:?}", &warnings);
    }

    let patterns = ignore_matcher.debug_get_patterns();
    invocation.ui.write_stdout(patterns)?;
    invocation.ui.write_stdout(b"\n")?;
    Ok(())
}