Commit f970baf3 authored by Pulkit Goyal's avatar Pulkit Goyal
Browse files

rhg: look for repository in ancestors also instead of cwd only

Last patch introduced config reading at startup to parse value of `--repository`
flag. However, that patch only tried to check for current repository at current
working directory and not it's ancestors. This patch fixes that.

Differential Revision: https://phab.mercurial-scm.org/D10767
parent e16aaf976c44
Pipeline #22883 failed with stages
in 40 minutes and 7 seconds
......@@ -43,6 +43,22 @@ pub struct Vfs<'a> {
}
impl Repo {
/// tries to find nearest repository root in current working directory or
/// its ancestors
pub fn find_repo_root() -> Result<PathBuf, RepoError> {
let current_directory = crate::utils::current_dir()?;
// ancestors() is inclusive: it first yields `current_directory`
// as-is.
for ancestor in current_directory.ancestors() {
if ancestor.join(".hg").is_dir() {
return Ok(ancestor.to_path_buf());
}
}
return Err(RepoError::NotFound {
at: current_directory,
});
}
/// Find a repository, either at the given path (which must contain a `.hg`
/// sub-directory) or by searching the current directory and its
/// ancestors.
......@@ -66,17 +82,8 @@ impl Repo {
})
}
} else {
let current_directory = crate::utils::current_dir()?;
// ancestors() is inclusive: it first yields `current_directory`
// as-is.
for ancestor in current_directory.ancestors() {
if ancestor.join(".hg").is_dir() {
return Self::new_at_path(ancestor.to_owned(), config);
}
}
Err(RepoError::NotFound {
at: current_directory,
})
let root = Self::find_repo_root()?;
Self::new_at_path(root, config)
}
}
......
......@@ -174,9 +174,8 @@ fn main() {
} else {
let local_config = {
if std::env::var_os("HGRCSKIPREPO").is_none() {
let current_dir = hg::utils::current_dir();
// TODO: handle errors from current_dir
if let Ok(current_dir_path) = current_dir {
// TODO: handle errors from find_repo_root
if let Ok(current_dir_path) = Repo::find_repo_root() {
let config_files = vec![
ConfigSource::AbsPath(
current_dir_path.join(".hg/hgrc"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment