Skip to content

Commit c9df362

Browse files
committed
refactor: move find_project_root to the hm crate, drop DirProvider re-export
Delete crates/hm-common/src/dirs.rs. Its sole remaining function, find_project_root, discovers the `.hm/` project root and is used only by the hm crate (context.rs and the config_layered test), so it moves to crates/hm/src/project.rs where it belongs. Also drop the `pub use dir_provider::DirProvider` crate-root re-export: every other hm-common type is module-qualified (hm_common::git::Git, hm_common::fs::write_atomic), so callers now use hm_common::dir_provider::DirProvider for consistency.
1 parent c9c6cf9 commit c9df362

8 files changed

Lines changed: 13 additions & 17 deletions

File tree

‎crates/hm-common/src/lib.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
#[cfg(feature = "sys-runtime")]
44
pub mod sys_runtime;
55
pub mod dir_provider;
6-
pub mod dirs;
76
pub mod format;
87
pub mod fs;
98
pub mod git;
109
pub mod process;
1110
pub mod python;
1211
pub mod string;
1312
pub mod time;
14-
15-
pub use dir_provider::DirProvider;

‎crates/hm-config/src/creds.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! File-backed credential store at `~/.config/hm/credentials.toml`.
22
//!
33
//! The file is written with [`Privacy::Private`] (0o600, parent dir 0o700)
4-
//! via [`hm_common::fs::blocking::write_atomic`], keyed by `(service, account)`.
4+
//! via [`hm_common::fs::write_atomic`], keyed by `(service, account)`.
55
66
use anyhow::{Context, Result};
77
use serde::{Deserialize, Serialize};
@@ -15,7 +15,7 @@ struct CredentialFile {
1515
}
1616

1717
fn path() -> Result<PathBuf> {
18-
let dirs = hm_common::DirProvider::new().context("could not determine config directory")?;
18+
let dirs = hm_common::dir_provider::DirProvider::new().context("could not determine config directory")?;
1919
Ok(dirs.config().join("hm").join("credentials.toml"))
2020
}
2121

‎crates/hm-config/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Config {
119119
///
120120
/// Returns an error if the platform config directory cannot be determined.
121121
pub fn user_config_path() -> Result<PathBuf> {
122-
let dirs = hm_common::DirProvider::new().context("could not determine config directory")?;
122+
let dirs = hm_common::dir_provider::DirProvider::new().context("could not determine config directory")?;
123123
Ok(dirs.config().join("hm").join("config.toml"))
124124
}
125125

‎crates/hm-exec/src/local/backend.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl LocalBackend {
5050
/// (VM backend + snapshot registry) and registering the [`VmRunner`] as
5151
/// the default runner.
5252
fn build_registry(&self) -> Result<RunnerRegistry> {
53-
let dirs = hm_common::DirProvider::new().ok_or_else(|| {
53+
let dirs = hm_common::dir_provider::DirProvider::new().ok_or_else(|| {
5454
BackendError::Local("cannot resolve the Harmont cache directory".into())
5555
})?;
5656
let registry =

‎crates/hm/src/context.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl RunContext {
2828
/// Returns an error if the config file is unreadable or malformed.
2929
pub fn from_cli(cli: &Cli) -> Result<Self> {
3030
let start_dir = std::env::current_dir().context("cannot determine current directory")?;
31-
let project_root = hm_common::dirs::find_project_root(&start_dir);
31+
let project_root = crate::project::find_project_root(&start_dir);
3232
let config = Config::load(project_root.as_deref())?;
3333

3434
let output = OutputMode::Human {

‎crates/hm/src/lib.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
reason = "transitive dependency version conflicts in rand/windows-sys/thiserror chains; not fixable without upstream updates"
44
)]
55
// The `dirs` crate must NOT be added as a direct dependency of this
6-
// crate. All directory resolution goes through `hm_common::dirs`, which
7-
// owns the `dirs` dependency and provides both platform primitives and
8-
// Harmont-specific discovery. Adding `dirs` here would bypass that
9-
// single source of truth.
6+
// crate. Platform-directory resolution goes through
7+
// `hm_common::DirProvider`, which owns the `dirs` dependency. Adding
8+
// `dirs` here would bypass that single source of truth.
109

1110
#[allow(
1211
clippy::print_stdout,
@@ -24,5 +23,6 @@ pub use hm_config as config;
2423
/// `harmont_cli::creds_store` path.
2524
pub use hm_config::creds as creds_store;
2625
pub mod context;
26+
pub mod project;
2727
pub mod error;
2828
pub(crate) mod signal;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
//! Project-directory discovery.
1+
//! The current Harmont project on disk.
22
//!
3-
//! The `hm`-namespaced directory *roots* (config, cache, …) live in
4-
//! [`crate::dir_provider`]. This module handles the orthogonal problem of
5-
//! locating the current project by walking up from a starting path.
3+
//! A project is any directory tree rooted at a directory that contains `.hm/`;
4+
//! this module locates that root.
65
76
#![allow(clippy::must_use_candidate)]
87

‎crates/hm/tests/config_layered.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn load_resolves_project_root() {
8585
)
8686
.unwrap();
8787

88-
let found = hm_common::dirs::find_project_root(project_dir.path());
88+
let found = harmont_cli::project::find_project_root(project_dir.path());
8989
assert_eq!(found, Some(project_dir.path().to_path_buf()));
9090

9191
let config_path = harmont_cli::config::Config::project_config_path(project_dir.path());

0 commit comments

Comments
 (0)