##// END OF EJS Templates
rhg: look for repository in ancestors also instead of cwd only...
Pulkit Goyal -
r48197:88119fff default
parent child Browse files
Show More
@@ -43,6 +43,22 b" pub struct Vfs<'a> {"
43 }
43 }
44
44
45 impl Repo {
45 impl Repo {
46 /// tries to find nearest repository root in current working directory or
47 /// its ancestors
48 pub fn find_repo_root() -> Result<PathBuf, RepoError> {
49 let current_directory = crate::utils::current_dir()?;
50 // ancestors() is inclusive: it first yields `current_directory`
51 // as-is.
52 for ancestor in current_directory.ancestors() {
53 if ancestor.join(".hg").is_dir() {
54 return Ok(ancestor.to_path_buf());
55 }
56 }
57 return Err(RepoError::NotFound {
58 at: current_directory,
59 });
60 }
61
46 /// Find a repository, either at the given path (which must contain a `.hg`
62 /// Find a repository, either at the given path (which must contain a `.hg`
47 /// sub-directory) or by searching the current directory and its
63 /// sub-directory) or by searching the current directory and its
48 /// ancestors.
64 /// ancestors.
@@ -66,17 +82,8 b' impl Repo {'
66 })
82 })
67 }
83 }
68 } else {
84 } else {
69 let current_directory = crate::utils::current_dir()?;
85 let root = Self::find_repo_root()?;
70 // ancestors() is inclusive: it first yields `current_directory`
86 Self::new_at_path(root, config)
71 // as-is.
72 for ancestor in current_directory.ancestors() {
73 if ancestor.join(".hg").is_dir() {
74 return Self::new_at_path(ancestor.to_owned(), config);
75 }
76 }
77 Err(RepoError::NotFound {
78 at: current_directory,
79 })
80 }
87 }
81 }
88 }
82
89
@@ -174,9 +174,8 b' fn main() {'
174 } else {
174 } else {
175 let local_config = {
175 let local_config = {
176 if std::env::var_os("HGRCSKIPREPO").is_none() {
176 if std::env::var_os("HGRCSKIPREPO").is_none() {
177 let current_dir = hg::utils::current_dir();
177 // TODO: handle errors from find_repo_root
178 // TODO: handle errors from current_dir
178 if let Ok(current_dir_path) = Repo::find_repo_root() {
179 if let Ok(current_dir_path) = current_dir {
180 let config_files = vec![
179 let config_files = vec![
181 ConfigSource::AbsPath(
180 ConfigSource::AbsPath(
182 current_dir_path.join(".hg/hgrc"),
181 current_dir_path.join(".hg/hgrc"),
General Comments 0
You need to be logged in to leave comments. Login now