rust/rhg/src/commands/debugignorerhg.rs
author Raphaël Gomès <rgomes@octobus.net>
Tue, 15 Nov 2022 00:02:43 +0100
changeset 49639 37bc3edef76f
parent 49558 363923bd51cd
child 49914 58074252db3c
permissions -rw-r--r--
rhg: upgrade `clap` dependency This one is the worst one to upgrade since v2 -> v4 broke a ton of API, which thankfully seems saner now. Contrary to what was done in the `hg-core/src/examples/nodemap` rewrite, we're not switching from the "builder" pattern to the "derive" pattern, since that would imply a much larger diff. It can be done incrementally.

use crate::error::CommandError;
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::Command {
    clap::command!("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(())
}