view rust/rhg/src/commands/debugignorerhg.rs @ 49894:678588b01af1

rhg: implement checkexec to support weird filesystems In particular, some of our repos are stored on a fileserver that simulates POSIX permissions poorly, in such a way that prevents the removal of execute permission. This causes rhg show a spurious unclean status, even though python hg reports the repo as clean. We fix this by making rhg implement the ~same checkexec logic that python hg does.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 05 Jan 2023 17:15:03 +0000
parents 37bc3edef76f
children 58074252db3c
line wrap: on
line source

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(())
}