rust/rhg/src/commands/root.rs
changeset 46740 97ac588b6d9e
parent 46593 5ce2aa7c2ad5
child 49639 37bc3edef76f
equal deleted inserted replaced
46739:c184b490da37 46740:97ac588b6d9e
     1 use crate::error::CommandError;
     1 use crate::error::CommandError;
     2 use format_bytes::format_bytes;
     2 use format_bytes::format_bytes;
       
     3 use hg::errors::{IoErrorContext, IoResultExt};
     3 use hg::utils::files::get_bytes_from_path;
     4 use hg::utils::files::get_bytes_from_path;
     4 
     5 
     5 pub const HELP_TEXT: &str = "
     6 pub const HELP_TEXT: &str = "
     6 Print the root directory of the current repository.
     7 Print the root directory of the current repository.
     7 
     8 
    12     clap::SubCommand::with_name("root").about(HELP_TEXT)
    13     clap::SubCommand::with_name("root").about(HELP_TEXT)
    13 }
    14 }
    14 
    15 
    15 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
    16 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
    16     let repo = invocation.repo?;
    17     let repo = invocation.repo?;
    17     let bytes = get_bytes_from_path(repo.working_directory_path());
    18     let working_directory = repo.working_directory_path();
       
    19     let working_directory = std::fs::canonicalize(working_directory)
       
    20         .with_context(|| {
       
    21             IoErrorContext::CanonicalizingPath(working_directory.to_owned())
       
    22         })?;
       
    23     let bytes = get_bytes_from_path(&working_directory);
    18     invocation
    24     invocation
    19         .ui
    25         .ui
    20         .write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?;
    26         .write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?;
    21     Ok(())
    27     Ok(())
    22 }
    28 }